/** * Create a new counter listener. * * @param num The number of sub callbacks. * @param ignorefailures Flag whether to ignore failures. * @param countReachedListener Functional listener called when the count is * reached. */ public CounterResultListener(int num, boolean ignorefailures, IFunctionalResultListener<Void> countReachedListener) { this(num, ignorefailures, SResultListener.createResultListener(countReachedListener)); }
/** * Creates an {@link IResultListener} that delegates results and exceptions to a given Future. * * @param delegate The future used for success delegation. * @param customResultListener Custom result listener that overwrites the delegation behaviour. * @return {@link IResultListener} */ public static <E> IResultListener<E> delegate(final Future<E> delegate, IFunctionalResultListener<E> customResultListener) { return delegate(delegate, false, customResultListener); }
/** * Creates an {@link IResultListener} that delegates exceptions to a given Future * and results to a given SuccessListener. * * @param delegate The future used for exception delegation. * @param customResultListener The SuccessListener. * @return {@link IResultListener} */ public static <E,T> IResultListener<E> delegateExceptions(final Future<T> delegate, final IFunctionalResultListener<E> customResultListener) { return delegateExceptions(delegate, false, customResultListener); }
/** * Creates an {@link IResultListener} that delegates results to the given * SuccessListener. * * @param sucListener The SuccessListener. * @param defaultExceptionHandling Specifies whether to use a default * handling for exceptions or not. * @return {@link IResultListener} */ public static <E> IResultListener<E> createResultListener(final IFunctionalResultListener<E> sucListener, final boolean defaultExceptionHandling) { if (defaultExceptionHandling) { return createResultListener(sucListener, printExceptions()); } else { return createResultListener(sucListener, ignoreExceptions()); } }
/** * Creates an {@link IResultListener} that delegates results to the given * SuccessListener and Exceptions to the given ExceptionListener. * * @param sucListener The SuccessListener. * @param exceptionListener The ExceptionListener. If <code>null</code>, exceptions are logged. * @return {@link IResultListener} */ public static <E> IResultListener<E> createResultListener(final IFunctionalResultListener<E> sucListener, final IFunctionalExceptionListener exceptionListener) { final IFunctionalExceptionListener innerExceptionListener = (exceptionListener == null) ? printExceptions() : exceptionListener; return new IResultListener<E>() { public void resultAvailable(E result) { sucListener.resultAvailable(result); } public void exceptionOccurred(Exception exception) { innerExceptionListener.exceptionOccurred(exception); } }; } }
public IFuture<Void> acceptEither(IFuture<E> other, final Consumer<E> action, Class<?> futuretype) final CounterResultListener<Void> exceptionCounter = new CounterResultListener<Void>(2, SResultListener.<Void>ignoreResults()); final Future<Void> resultIndicator = new Future<Void>(); final Future<Void> ret = getFuture(futuretype);
/** * Called after a successful search. */ public void resultAvailable(Object result) { searchfut = null; delegate = (IService)result; if(fut!=null) { try { IFuture resfut = (IFuture)invoke(proxy, method, args); SResultListener.delegateFromTo(resfut, fut); } catch(Throwable t) { fut.setException(new RuntimeException(t)); } } }
final IFunctionalExceptionListener innerExceptionListener = (exceptionListener == null) ? SResultListener.printExceptions() : exceptionListener; addResultListener(new DefaultTuple2ResultListener<E, F>()
public <U> IFuture<U> applyToEither(IFuture<E> other, final Function<E, U> fn, Class<?> futuretype) final CounterResultListener<Void> exceptionCounter = new CounterResultListener<Void>(2, SResultListener.<Void>ignoreResults()); final Future<Void> resultIndicator = new Future<Void>(); final Future<U> ret = getFuture(futuretype);
/** * Creates an {@link IResultListener} that delegates results to the given * SuccessListener and uses default exception handling. * * @param sucListener The SuccessListener. * @return {@link IResultListener} */ public static <E> IResultListener<E> createResultListener(final IFunctionalResultListener<E> sucListener) { return createResultListener(sucListener, true); }
/** * Creates an {@link IIntermediateResultListener} that delegates results and exceptions to a given IntermediateFuture. * * @param delegate The future used for intermediate and final result delegation. * @return {@link IntermediateDelegationResultListener} */ public static <E> IIntermediateResultListener<E> delegate(final IntermediateFuture<E> delegate) { return delegate(delegate, false, null, null); }
IFunctionalExceptionListener exceptionListener) final IFunctionalExceptionListener innerExceptionListener = (exceptionListener == null) ? SResultListener.printExceptions(): exceptionListener; addResultListener(new IntermediateDefaultResultListener<E>()
/** * Create a new collection listener. * * @param num The expected number of results. * @param ignorefailures When set to true failures will be tolerated and * just not be added to the result collection. * @param resultDelegate The functional delegate result listener. * @param exceptionDelegate The functional delegate exception listener. * Passing <code>null</code> enables default exception logging. */ public CollectionResultListener(int num, boolean ignorefailes, IFunctionalResultListener<Collection<E>> resultDelegate, IFunctionalExceptionListener exceptionDelegate) { this(num, ignorefailes, SResultListener.createResultListener(resultDelegate, exceptionDelegate)); }
/** * Creates an {@link IResultListener} that delegates results and exceptions to a given Future. * Supports creating delegations for Future, IntermediateFuture and Tuple2Future. * * @param delegate The future used for success delegation. * @return {@link IResultListener} */ public static <E> IResultListener<E> delegate(final Future<E> delegate) { return delegate(delegate, false); }
/** * Create a new collection listener. * * @param num The expected number of results. * @param ignorefailures When set to true failures will be tolerated and * just not be added to the result collection. * @param resultDelegate The functional delegate result listener. * @param exceptionDelegate The functional delegate exception listener. * Passing <code>null</code> enables default exception logging. */ public CollectionResultListener(boolean ignorefailes, IFunctionalResultListener<Collection<E>> resultDelegate, IFunctionalExceptionListener exceptionDelegate) { this(-1, ignorefailes, SResultListener.createResultListener(resultDelegate, exceptionDelegate)); }
/** * Creates an {@link IResultListener} that delegates results and exceptions to a given Future. * * @param delegate The future used for success delegation. * @param undone Flag if undone methods should be used. * @return {@link IResultListener} */ public static <E> IResultListener<E> delegate(final Future<E> delegate, boolean undone) { return delegate(delegate, undone, null); }
/** * Create a new counter listener. * * @param num The number of sub callbacks. * @param ignorefailures Flag whether to ignore failures. * @param countReachedListener Functional listener called when the count is * reached. * @param exListener The listener that is called on exceptions. Passing * <code>null</code> enables default exception logging. */ public CounterResultListener(int num, boolean ignorefailures, IFunctionalResultListener<Void> countReachedListener, IFunctionalExceptionListener exListener) { this(num, ignorefailures, SResultListener.createResultListener(countReachedListener, exListener)); }
/** * Creates an {@link IIntermediateResultListener} that delegates results and exceptions to a given IntermediateFuture. * * @param delegate The future used for intermediate and final result delegation. * @param undone Flag if undone methods should be used. * @return {@link IntermediateDelegationResultListener} */ public static <E> IIntermediateResultListener<E> delegate(final IntermediateFuture<E> delegate, boolean undone) { return delegate(delegate, undone, null, null); }
/** * Create a new counter listener. * * @param num The number of sub callbacks. * @param ignorefailures Flag whether to ignore failures. * @param countReachedListener Functional listener called when the count is * reached. * @param intermediateResultListener Functional listener called on * intermediate results, can be <code>null</code>. * @param exListener The listener that is called on exceptions. Passing * <code>null</code> enables default exception logging. */ public CounterResultListener(int num, boolean ignorefailures, IFunctionalResultListener<Void> countReachedListener, IFunctionalResultListener<E> intermediateResultListener, IFunctionalExceptionListener exListener) { this(num, ignorefailures, SResultListener.createResultListener(countReachedListener, exListener)); this.intermediateResultListener = intermediateResultListener; }
/** * Creates a delegation from source to target, respecting future types. * @param source Delegation source. * @param target Delegation target. */ public static <E> void delegateFromTo(IFuture<E> source, Future<E> target) { // if (source instanceof ITuple2Future && target instanceof Tuple2Future) // { // // need special case for tuple? // ((ITuple2Future) source).addResultListener(delegate((Tuple2Future)target)); // } if (source instanceof IIntermediateFuture && target instanceof IntermediateFuture) { ((IIntermediateFuture) source).addIntermediateResultListener(delegate((IntermediateFuture)target)); } else { source.addResultListener(delegate(target)); } // TODO: needed for other *DelegationResultListeners ? }