@Beta public final class FakeTimeLimiter extends Object implements TimeLimiter
|Constructor and Description|
|Modifier and Type||Method and Description|
Invokes a specified Callable, timing out after the specified time limit.
Returns an instance of
public <T> T newProxy(T target, Class<T> interfaceType, long timeoutDuration, TimeUnit timeoutUnit)
interfaceTypethat delegates all method calls to the
targetobject, enforcing the specified time limit on each call. This time-limited delegation is also performed for calls to
If the target method call finishes before the limit is reached, the return
value or exception is propagated to the caller exactly as-is. If, on the
other hand, the time limit is reached, the proxy will attempt to abort the
call to the target, and will throw an
It is important to note that the primary purpose of the proxy object is to return control to the caller when the timeout elapses; aborting the target method call is of secondary concern. The particular nature and strength of the guarantees made by the proxy is implementation-dependent. However, it is important that each of the methods on the target object behaves appropriately when its thread is interrupted.
target- the object to proxy
interfaceType- the interface you wish the returned proxy to implement
timeoutDuration- with timeoutUnit, the maximum length of time that callers are willing to wait on each method call to the proxy
timeoutUnit- with timeoutDuration, the maximum length of time that callers are willing to wait on each method call to the proxy
public <T> T callWithTimeout(Callable<T> callable, long timeoutDuration, TimeUnit timeoutUnit, boolean amInterruptible) throws Exception
UncheckedTimeoutExceptionto the caller.
Warning: The future of this method is in doubt. It may be nuked, or changed significantly.
callable- the Callable to execute
timeoutDuration- with timeoutUnit, the maximum length of time to wait
timeoutUnit- with timeoutDuration, the maximum length of time to wait
amInterruptible- whether to respond to thread interruption by aborting the operation and throwing InterruptedException; if false, the operation is allowed to complete or time out, and the current thread's interrupt status is re-asserted.
interruptibleis true and our thread is interrupted during execution
UncheckedTimeoutException- if the time limit is reached
Copyright © 2010-2013. All Rights Reserved.