/** * Obtains an ensured of the specified {@link Deferred} * (configured using default {@link Ensured} timeouts) * * @param deferred the {@link Deferred} to ensure * * @return an {@link Ensured} of the {@link Deferred} */ public static <T> Deferred<T> ensured(Deferred<T> deferred) { return deferred instanceof Ensured ? deferred : new Ensured<T>(deferred, getDefaultEnsuredRetryDurationsMS(), getDefaultEnsuredTimeoutMS()); }
/** * {@inheritDoc} */ @Override public Class<T> getDeferredClass() { return m_deferred.getDeferredClass(); }
/** * Obtains an {@link Cached} of the specified {@link Deferred}. * * @param deferred the {@link Deferred} to cache * * @return a {@link Cached} of the {@link Deferred} */ public static <T> Cached<T> cached(Deferred<T> deferred) { return deferred instanceof Cached ? (Cached<T>) deferred : new Cached<T>(deferred); }
/** * Obtains the value of a {@link Deferred}. * <p> * This is functionally equivalent to calling {@link Deferred#get()} on * {@link #ensured(Deferred)}. * * @param deferred the {@link Deferred} to ensure * * @return the value of the {@link Deferred} */ public static <T> T ensure(Deferred<T> deferred) { return ensured(deferred).get(); }
/** * {@inheritDoc} */ @Override public T get() throws UnresolvableInstanceException, InstanceUnavailableException { throw new UnresolvableInstanceException(this); }
/** * {@inheritDoc} */ @Override public T get() throws UnresolvableInstanceException, InstanceUnavailableException { throw new InstanceUnavailableException(this); }
/** * Asserts that a value will eventually satisfy the specified {@link Matcher}. * <p> * Should the value be the result of a call to {@link DeferredHelper#invoking(Deferred)} * the result is unwrapped into a {@link Deferred} that is then used for the assert. * * @param <T> the type of value produced by the {@link Deferred} * * @param message the message for the AssertionError (<code>null</code> ok) * @param value the value * @param matcher the {@link Matcher} * * @throws AssertionError if the assertion fails */ public static <T> void assertThat(String message, T value, Matcher<?> matcher) throws AssertionError { assertThat(message, eventually(value), matcher); }
/** * Obtains an {@link Ensured} of the specified {@link Deferred}. * * @param deferred the {@link Deferred} to ensure * @param totalRetryDurationMS the maximum duration (in milliseconds) to retry * * @return an {@link Ensured} of the {@link Deferred} */ public static <T> Deferred<T> ensured(Deferred<T> deferred, long totalRetryDurationMS) { return deferred instanceof Ensured ? (Ensured<T>) deferred : new Ensured<T>(deferred, getDefaultEnsuredRetryDurationsMS(), totalRetryDurationMS); }
/** * Asserts that the specified {@link Callable} submitted to the {@link JavaApplication} * will eventually match the specified matcher. * * @param application * @param callable * @param matcher * @param <T> * * @throws AssertionError */ public static <T> void assertThat(JavaApplication<?> application, Callable<T> callable, Matcher<?> matcher) throws AssertionError { assertThat(new DeferredRemoteExecution<T>(application, callable), matcher); } }
/** * 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)); }
/** * 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); }
/** * Obtains a {@link Deferred} representation of a Java Future. * * @param clzOfResult the {@link Class} of result from the * {@link java.util.concurrent.Future} * @param future the {@link java.util.concurrent.Future} * * @return a {@link Deferred} */ public static <T> Deferred<T> future(Class<T> clzOfResult, java.util.concurrent.Future<T> future) { return new Future<T>(clzOfResult, future); }
/** * Obtains the value of a {@link Deferred}. * <p> * This is functionally equivalent to calling {@link Deferred#get()} on * {@link #ensure(Deferred, long)}. * * @param deferred the {@link Deferred} to ensure * @param totalRetryDurationMS the maximum duration (in milliseconds) to retry * * @return an {@link Ensured} of the {@link Deferred} */ public static <T> T ensure(Deferred<T> deferred, long totalRetryDurationMS) { return ensured(deferred, totalRetryDurationMS).get(); }
/** * Asserts that a value will eventually satisfy the specified {@link Matcher}. * <p> * Should the value be the result of a call to {@link DeferredHelper#invoking(Deferred)} * the result is unwrapped into a {@link Deferred} that is then used for the assert. * * @param <T> the type of value produced by the {@link Deferred} * * @param value the value * @param matcher the {@link Matcher} * * @throws AssertionError if the assertion fails */ public static <T> void assertThat(T value, Matcher<?> matcher) throws AssertionError { assertThat(null, eventually(value), matcher); }
/** * {@inheritDoc} */ @Override public Class<T> getDeferredClass() { return m_deferred.getDeferredClass(); }
/** * Obtains the value of a {@link Deferred}. * <p> * This is functionally equivalent to calling {@link Deferred#get()} on * {@link #ensure(Deferred, long, TimeUnit)}. * * @param deferred the {@link Deferred} to ensure * @param totalRetryDuration the maximum duration for retrying * @param totalRetryDurationUnits the {@link TimeUnit}s for the duration * * @return the value of the {@link Deferred} */ public static <T> T ensure(Deferred<T> deferred, long totalRetryDuration, TimeUnit totalRetryDurationUnits) { return ensured(deferred, totalRetryDuration, totalRetryDurationUnits).get(); }
/** * {@inheritDoc} */ @Override public Class<T> getDeferredClass() { return m_deferred.getDeferredClass(); }