/** * Constructor for a {@link DeferredInvoke}. * * @param object the object on which to invoke the specified {@link Method} * @param method the {@link Method} to invoke * @param arguments the arguments for the invocation */ public DeferredInvoke(Object object, Method method, Object... arguments) { this(new Existing<Object>(object), method, arguments); }
/** * Constructs a {@link DeferredPredicate} for value with the * specified {@link Predicate}. * * @param value the value to use supplied to the {@link Predicate} * @param predicate the {@link Predicate} */ public DeferredPredicate(T value, Predicate<T> predicate) { if (value instanceof Deferred) { this.deferred = (Deferred) value; } else { this.deferred = new Existing<T>(value); } this.predicate = predicate; this.lastMatchedValue = null; }
/** * Creates a dynamic proxy of an {@link Object}. The returned proxy will * record interactions (method calls) against the proxy for the * purposes of representing the calls as {@link Deferred}s. * <p> * The results of interactions on the returned proxy are always non-sense * and/or other dynamic proxies. To determine the actual result (as * a {@link Deferred}), one must call {@link #eventually(Object)}. * * @param <T> the type of {@link Object} * @param object the {@link Object} to proxy * * @return a recording dynamic proxy of the {@link Object} */ public static <T> T invoking(T object) { return invoking(new Existing<T>(object)); }
/** * Obtains a {@link Deferred} representation of the last call to a * dynamic proxy created with either {@link #invoking(Object)} or * {@link #invoking(Deferred)}. * * @param t the value returned from an call to 'invoking' * * @return a {@link Deferred} representation of a previous call * {@link #invoking(Object)} */ @SuppressWarnings("unchecked") public static <T> Deferred<T> eventually(T t) { // get the last deferred value from invoking Deferred<T> deferred = (Deferred<T>) m_deferred.get(); if (deferred == null) { deferred = t instanceof Deferred ? (Deferred<T>) t : new Existing<T>(t); } else { // clear the last invoking call m_deferred.set(null); } return ensured(deferred); }
/** * Obtains a {@link Deferred} representation of the last call to a * dynamic proxy created with either {@link #invoking(Object)} or * {@link #invoking(Deferred)}. * * @param t the value returned from an call to 'invoking' * @param totalRetryDuration the maximum duration for retrying * @param totalRetryDurationUnits the {@link TimeUnit}s for the duration * * @return a {@link Deferred} representation of a previous call * {@link #invoking(Object)} */ @SuppressWarnings("unchecked") public static <T> Deferred<T> eventually(T t, long totalRetryDuration, TimeUnit totalRetryDurationUnits) { // get the last deferred value from invoking Deferred<T> deferred = (Deferred<T>) m_deferred.get(); if (deferred == null) { deferred = t instanceof Deferred ? (Deferred<T>) t : new Existing<T>(t); } else { // clear the last invoking call m_deferred.set(null); } return ensured(deferred, totalRetryDuration, totalRetryDurationUnits); }