<p>Adds a listener that will be notified on the given executor when
peers are disconnected from.</p>
172736
public void addDisconnectedEventListener(Executor executor, PeerDisconnectedEventListener listener) {
        peerDisconnectedEventListeners.add(new ListenerRegistration<>(checkNotNull(listener), executor));
        for (Peer peer : getConnectedPeers())
            peer.addDisconnectedEventListener(executor, listener);
        for (Peer peer : getPendingPeers())
            peer.addDisconnectedEventListener(executor, listener);
    }
776874
public void addSpiderListener(SpiderListener listener) {
		if (spider != null) {
			this.spider.addSpiderListener(listener);
		} else {
			this.pendingSpiderListeners.add(listener);
		}
	}
240297
public void onStartWithServer(ExecutionContext<I> context, ExecutionInfo info) {
        for (ExecutionListener<I, O> listener: listeners) {
            try {
                if (!isListenerDisabled(listener)) {
                    listener.onStartWithServer(context.getChildContext(listener), info);
                }
            } catch (Throwable e) {
                if (e instanceof AbortExecutionException) {
                    throw (AbortExecutionException) e;
                }
                logger.error("Error invoking listener " + listener, e);
            }
        }
    }
417065
@Override
    public void addConnectionListener(SICoreConnectionListener listener)
                    throws SIConnectionUnavailableException, SIConnectionDroppedException
    {
        if (TraceComponent.isAnyTracingEnabled() && CoreSPIConnection.tc.isEntryEnabled())
            SibTr.entry(CoreSPIConnection.tc, "addConnectionListener",
                        new Object[] { this, listener });

        checkNotClosed();

        // Synchronize on the close object, we don't want the connection closing
        // while we try to add the listener.
        synchronized (_connectionListeners)
        {
            //store a reference to the listener
            _connectionListeners.add(listener);
        }

        if (TraceComponent.isAnyTracingEnabled() && CoreSPIConnection.tc.isEntryEnabled())
            SibTr.exit(CoreSPIConnection.tc, "addConnectionListener");
    }
1105275
public synchronized void listenOn(Cache<CounterKey, CounterValue> cache) throws InterruptedException {
      if (!topologyListener.registered) {
         this.cache = cache;
         topologyListener.register(cache);
      }
      if (!listenersRegistered) {
         this.cache.addListener(valueListener, CounterKeyFilter.getInstance());
         listenersRegistered = true;
      }
   }
1203684
public S onFailure(CheckedConsumer<? extends ExecutionCompletedEvent<R>> listener) {
    failureListener = EventListener.of(Assert.notNull(listener, "listener"));
    return (S) this;
  }
958526
void notifyWhenStateChanged(Runnable callback, Executor executor, ConnectivityState source) {
    checkNotNull(callback, "callback");
    checkNotNull(executor, "executor");
    checkNotNull(source, "source");

    Listener stateChangeListener = new Listener(callback, executor);
    if (state != source) {
      stateChangeListener.runInExecutor();
    } else {
      listeners.add(stateChangeListener);
    }
  }
214294
function(listener) {
    EventHandlers.syncRoamingMessage.push(listener);
    if (device.platform === "Android") {
      exec(null, null, PLUGIN_NAME, "addSyncRoamingMessageListener", []);
    }
  }
127077
public void addListener(ForwardingClientListener listener) {
		if (listener != null) {
			clientlisteners.addElement(listener);

			SocketListener s;
			Enumeration<SocketListener> en = socketlisteners.elements();
			while (en.hasMoreElements()) {
				s = (SocketListener) en.nextElement();
				if (s.isListening()) {
					listener.forwardingStarted(
							ForwardingClientListener.LOCAL_FORWARDING,
							generateKey(s.addressToBind, s.portToBind),
							s.hostToConnect, s.portToConnect);

				}
			}
			if (Log.isDebugEnabled()) {
				Log.debug(this, "enumerated socketlisteners");
			}

			Enumeration<String> en2 = incomingtunnels.keys();
			String key;
			String destination;
			String hostToConnect;
			int portToConnect;
			while (en2.hasMoreElements()) {
				key = en2.nextElement();
				if (key.equals(X11_KEY)
						|| ssh.getContext().getX11Display() != null
						&& ssh.getContext().getX11Display().equals(key))
					continue;
				destination = (String) remoteforwardings.get(key);
				hostToConnect = destination.substring(0,
						destination.indexOf(':'));
				portToConnect = Integer.parseInt(destination
						.substring(destination.indexOf(':') + 1));

				listener.forwardingStarted(
						ForwardingClientListener.REMOTE_FORWARDING, key,
						hostToConnect, portToConnect);

			}
			if (Log.isDebugEnabled()) {
				Log.debug(this, "enumerated incomingtunnels");
			}

			String display = ssh.getContext().getX11Display();

			if (Log.isDebugEnabled()) {
				Log.debug(this, "display is " + display);
			}

			if (display != null && isXForwarding) {
				String hostname = "localhost";
				int screen;
				int idx = display.indexOf(':');
				if (idx != -1) {
					hostname = display.substring(0, idx);
					screen = Integer.parseInt(display.substring(idx + 1));
				} else {
					screen = Integer.parseInt(display);
				}

				listener.forwardingStarted(
						ForwardingClientListener.X11_FORWARDING, X11_KEY,
						hostname, screen);
			}
		}
	}
867035
public void addPreMessageReceivedEventListener(Executor executor, PreMessageReceivedEventListener listener) {
        peersPreMessageReceivedEventListeners.add(new ListenerRegistration<>(checkNotNull(listener), executor));
        for (Peer peer : getConnectedPeers())
            peer.addPreMessageReceivedEventListener(executor, listener);
        for (Peer peer : getPendingPeers())
            peer.addPreMessageReceivedEventListener(executor, listener);
    }
217211
private void notifyConnected(Peer peer) {
		for(Listener listener : new HashSet<>(listeners)) {
			listener.onConnected(peer);
		}
	}
899395
private static void removeDataEventListenerFromPeer(Peer peer, PeerDataEventListener listener) {
        peer.removeBlocksDownloadedEventListener(listener);
        peer.removeChainDownloadStartedEventListener(listener);
        peer.removeGetDataEventListener(listener);
        peer.removePreMessageReceivedEventListener(listener);
    }
291136
private void notifyListeners(LifecycleState oldState, LifecycleState newState)
  {
    notifyWait();
    
    // initial must be outside synchronized to avoid any blocking
    // for fail-safe shutdown
    if (_listeners == null) {
      return;
    }
    
    ArrayList<LifecycleListener> listeners = null;
    
    synchronized (this) {
      notifyAll();

      if (_listeners != null) {
        for (int i = 0; i < _listeners.size(); i++) {
          LifecycleListener listener = _listeners.get(i).get();

          if (listener != null) {
            if (listeners == null) {
              listeners = new ArrayList<LifecycleListener>();
            }
            
            listeners.add(listener);
          }
          else {
            _listeners.remove(i);
            i--;
          }
        }
      }
    }

    if (listeners != null) {
      for (LifecycleListener listener : listeners) {
        listener.lifecycleEvent(oldState, newState);
      }
    }
  }
799465
@Override
    final public void addConnectionEventListener(
                                                 final ConnectionEventListener listener) {

        if (TraceComponent.isAnyTracingEnabled() && TRACE.isEntryEnabled()) {
            SibTr.entry(this, TRACE, "addConnectionEventListener", listener);
        }

        synchronized (_connectionListeners) {
            _connectionListeners.add(listener);
        }

        if (TraceComponent.isAnyTracingEnabled() && TRACE.isEntryEnabled()) {
            SibTr.exit(this, TRACE, "addConnectionEventListener");
        }

    }
272053
public void addListener(IsSimplePromiseResponseHandler<T> listener) {
    if (handlers == null) {
      handlers = new LinkedList<>();
    }

    handlers.add(listener);

    if (response != null || exception != null) {
      listener.onResponse(this);
    }
  }
824276
public void removeConnectionEventListener(ConnectionEventListener listener) {
        final boolean isTraceOn = TraceComponent.isAnyTracingEnabled();

        if (isTraceOn && tc.isEntryEnabled()) 
            Tr.entry(this, tc, "removeConnectionEventListener", listener);

        if (listener == null) {
            NullPointerException nullX = new NullPointerException(
                            "Cannot remove null ConnectionEventListener.");

            if (isTraceOn && tc.isEntryEnabled())
                Tr.exit(this, tc, "removeConnectionEventListener", nullX); 
            throw nullX; 
        }

        // setting the metrics to null here causes a NPE the metrics cannot be set to null
        // until the end of the destroy method.

        // Not synchronized because of the contract that add/remove event listeners will only
        // be used on ManagedConnection create/destroy, when the ManagedConnection is not
        // used by any other threads. 

        // Find matching listener in the array -- then remove it, adjust entries as
        // necessary, and adjust the counter

        // loop through the listeners
        for (int i = 0; i < numListeners; i++)
            // look for matching listener
            if (listener == ivEventListeners[i]) {
                // remove the matching listener, but don't leave a gap in the array -- the order of
                // the listeners in the array doesn't matter, so move the last listener to fill the
                // gap left by the remove, if necessary
                ivEventListeners[i] = ivEventListeners[--numListeners];
                ivEventListeners[numListeners] = null;

                if (isTraceOn && tc.isEntryEnabled())
                    Tr.exit(this, tc, "removeConnectionEventListener"); 
                return;
            }

        if (isTraceOn && tc.isEntryEnabled()) 
            Tr.exit(this, tc, "removeConnectionEventListener", "Listener not found for remove.");
    }
110025
public S onSuccess(CheckedConsumer<? extends ExecutionCompletedEvent<R>> listener) {
    successListener = EventListener.of(Assert.notNull(listener, "listener"));
    return (S) this;
  }