use of com.ms.silverking.cloud.dht.client.AsyncOperationListener in project SilverKing by Morgan-Stanley.
the class AsyncOperationImpl method addListeners.
/**
* Adds multiple completion listeners. For any listener that is already complete, the callback will be
* immediately executed, possibly in the calling thread.
* @param listeners update listeners
* @param listenStates states to generate updates for
*/
public void addListeners(Iterable<AsyncOperationListener> _listeners, OperationState... listenStates) {
EnumSet<OperationState> _listenStates;
OperationState opState;
_listenStates = CollectionUtil.arrayToEnumSet(listenStates);
opState = getState();
lock.lock();
try {
// Trigger immediate updates for completion, but only for completion
if (opState != OperationState.INCOMPLETE && _listenStates.contains(opState)) {
for (AsyncOperationListener listener : _listeners) {
listener.asyncOperationUpdated(this);
}
} else {
if (listeners == null) {
listeners = new HashSet<>();
}
for (AsyncOperationListener listener : _listeners) {
listeners.add(new Pair<>(listener, _listenStates));
}
}
} finally {
lock.unlock();
}
}
Aggregations