Registers the {@code listener} to be called when an execution is complete for all of the configured policies are
exceeded.
332306
public FailsafeExecutor<R> onComplete(CheckedConsumer<? extends ExecutionCompletedEvent<R>> listener) {
    completeListener = EventListener.of(Assert.notNull(listener, "listener"));
    return this;
  }
387233
public <T> void registerRefListener(T oldObject, final Listener<T> listener) {
    checkNotNull(oldObject);
    checkNotNull(listener);
    Object oldMapping = mappings.get(oldObject);
    if (oldMapping == null) {
      // store the listener so it will be run when the old object mapping is registered
      mappings.put(oldObject, listener);
    } else if (oldMapping instanceof Listener) {
      // chain the listeners
      @SuppressWarnings("unchecked") // Listener<T> can only be registered with a T
      final Listener<T> oldListener = (Listener) oldMapping;
      mappings.put(oldObject, chainListeners(listener, oldListener));
    } else {
      // if there was a value mapped to the old object it must have been a T
      @SuppressWarnings("unchecked")
      T typedValue = (T) oldMapping;
      listener.newVersion(typedValue);
    }
  }
1283217
public void initialize(Context context, ResponseListener listener) {
        this.context = context;
        this.listener = (listener != null) ? listener : new ResponseListener() {
            final String message = "ResponseListener is not specified. Defaulting to empty listener.";

            @Override
            public void onSuccess(Response response) {
                logger.debug(message);
            }

            @Override
            public void onFailure(Response response, Throwable t, JSONObject extendedInfo) {
                logger.debug(message);
            }
        };

        logger.debug("AuthorizationRequestAgent is initialized.");
    }
878554
@RestrictTo(LIBRARY)
	public void notifyFinishedUseCase(UseCaseListener listener) {
		try {
			LOGGER.debug("Notifying " + getClass().getSimpleName() + " finish to listener " + listener.getClass().getSimpleName());
			listener.onFinishUseCase();
		} catch (Exception e) {
			AbstractException abstractException = wrapException(e);
			logHandledException(abstractException);
		}
	}
1119046
public void addListener(PreInvalidationListener listener) {
    	if (preInvalidationListenerCount == 1 && tc.isDebugEnabled())
    		Tr.debug(tc, "Over-writing current PreInvalidationListener with new one");
        currentPreInvalidationListener = listener;
        preInvalidationListenerCount = 1;
    }
1119719
public static void registerLifeCycleObserver(@NonNull Application application, @NonNull LifecycleListener listener) {
        application.registerActivityLifecycleCallbacks(new LifeCycleController(listener).createLifecycleCallback());
    }
138400
private void executeListeners() {
    if (!monitor.isOccupiedByCurrentThread()) {
      // iterate by index to avoid concurrent modification exceptions
      for (int i = 0; i < listeners.size(); i++) {
        listeners.get(i).execute();
      }
    }
  }
749140
private void registerListeners() {
    protocol.registerExecuteHandler(this::execute);
    protocol.registerBackupHandler(this::backup);
    protocol.registerRestoreHandler(this::restore);
    protocol.registerCloseHandler(this::close);
    protocol.registerMetadataHandler(this::metadata);
  }
1326211
public final void listenInline(AsyncWorkListener<T,TError> listener) {
		synchronized (this) {
			if (!unblocked || listenersInline != null) {
				if (listenersInline == null) listenersInline = new ArrayList<>(5);
				listenersInline.add(listener);
				return;
			}
		}
		if (error != null) listener.error(error);
		else if (cancel != null) listener.cancelled(cancel);
		else listener.ready(result);
	}
657765
private void registerListener(final ChangesLogWrapper logWrapper, TransactionableResourceManager txResourceManager)
      throws RepositoryException
   {
      try
      {
         // Why calling the listeners non tx aware has been done like this:
         // 1. If we call them in the commit phase and we use Arjuna with ISPN, we get:
         //       ActionStatus.COMMITTING > is not in a valid state to be invoking cache operations on.
         //       at org.infinispan.interceptors.TxInterceptor.enlist(TxInterceptor.java:195)
         //       at org.infinispan.interceptors.TxInterceptor.enlistReadAndInvokeNext(TxInterceptor.java:167)
         //       at org.infinispan.interceptors.TxInterceptor.visitGetKeyValueCommand(TxInterceptor.java:162)
         //       at org.infinispan.commands.read.GetKeyValueCommand.acceptVisitor(GetKeyValueCommand.java:64)
         //    This is due to the fact that ISPN enlist the cache even for a read access and enlistments are not 
         //    allowed in the commit phase
         // 2. If we call them in the commit phase, we use Arjuna with ISPN and we suspend the current tx,
         //    we get deadlocks because we try to acquire locks on cache entries that have been locked by the main tx.
         // 3. If we call them in the afterComplete, we use JOTM with ISPN and we suspend and resume the current tx, we get:
         //       jotm: resume: Invalid Transaction Status:STATUS_COMMITTED (Current.java, line 743) 
         //       javax.transaction.InvalidTransactionException: Invalid resume org.objectweb.jotm.TransactionImpl
         //       at org.objectweb.jotm.Current.resume(Current.java:744)
         //    This is due to the fact that it is not allowed to resume a tx when its status is STATUS_COMMITED

         txResourceManager.addListener(new TransactionableResourceManagerListener()
         {
            public void onCommit(boolean onePhase) throws Exception
            {
            }

            public void onAfterCompletion(int status) throws Exception
            {
               if (status == Status.STATUS_COMMITTED)
               {
                  // Since the tx is successfully committed we can call components non tx aware

                  // The listeners will need to be executed outside the current tx so we suspend
                  // the current tx we can face enlistment issues on product like ISPN
                  transactionManager.suspend();

                  SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
                  {
                     public Void run()
                     {
                        notifySaveItems(logWrapper.getChangesLog(), false);
                        return null;
                     }
                  });
                  // Since the resume method could cause issue with some TM at this stage, we don't resume the tx
               }
            }

            public void onAbort() throws Exception
            {
            }
         });
      }
      catch (Exception e)
      {
         throw new RepositoryException("The listener for the components not tx aware could not be added", e);
      }
   }
798105
public static void fireCompleted(Run r, @Nonnull TaskListener listener) {
        for (RunListener l : all()) {
            if(l.targetType.isInstance(r))
                try {
                    l.onCompleted(r,listener);
                } catch (Throwable e) {
                    report(e);
                }
        }
    }
472586
function registerListener(context, listener, ...arg) {
    if (context.set) {
        for (let i = 0; i < arg.length; i++) {
            if (isFunction(arg[i])) {
                listener.push(arg[i]);
            }
        }
    }
    return context;
}
244082
public static <T> void exceptionListener(CompletableFuture<T> completableFuture, Consumer<Throwable> exceptionListener) {
        completableFuture.whenComplete((r, ex) -> {
            if (ex != null) {
                Callbacks.invokeSafely(exceptionListener, ex, null);
            }
        });
    }
639590
public void addListener(final WebAppListener listener) {
		NullArgumentException.validateNotNull(listener, "Listener");
		NullArgumentException.validateNotNull(listener.getListenerClass(),
				"Listener class");
		if (!listeners.contains(listener)) {
			listeners.add(listener);
		}
	}
1233176
public ListenerRegistration<RuleLifecycleListener> addLifecycleListener(final RuleLifecycleListener listener)
    {
        this.listeners.add(listener);
        return new ListenerRegistration<RuleLifecycleListener>()
        {
            @Override
            public RuleLifecycleListener removeListener()
            {
                listeners.remove(listener);
                return listener;
            }
        };

    }
941163
public void addListener(TransactionableResourceManagerListener listener)
   {
      TransactionContext ctx = contexts.get();
      if (ctx == null)
      {
         throw new IllegalStateException("There is no active transaction context");
      }
      XidContext xidCtx = ctx.getXidContext();
      if (xidCtx == null)
      {
         throw new IllegalStateException("There is no active xid context");
      }
      xidCtx.addListener(listener);
   }
1019724
public void registerExecutionListener(final ExecutionListener executionListener) {

		final Integer priority = Integer.valueOf(executionListener.getPriority());

		if (priority.intValue() < 0) {
			LOG.error("Priority for execution listener " + executionListener.getClass() + " must be non-negative.");
			return;
		}

		final ExecutionListener previousValue = this.executionListeners.putIfAbsent(priority, executionListener);

		if (previousValue != null) {
			LOG.error("Cannot register " + executionListener.getClass() + " as an execution listener. Priority "
				+ priority.intValue() + " is already taken.");
		}
	}