public class DefaultWindowFuture<K,R,P> extends Object implements WindowFuture<K,R,P>
CALLER_NOT_WAITING, CALLER_WAITING, CALLER_WAITING_TIMEOUT| Modifier | Constructor and Description |
|---|---|
protected |
DefaultWindowFuture(Window window,
ReentrantLock windowLock,
Condition completedCondition,
K key,
R request,
int callerStateHint,
long originalOfferTimeoutMillis,
int windowSize,
long offerTimestamp,
long acceptTimestamp,
long expireTimestamp)
Creates a new DefaultWindowFuture.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
await()
Waits for this future to be completed within the amount of time remaining
from the original offerTimeoutMillis minus the amount of time it took
for the Window to accept the offer.
|
boolean |
await(long timeoutMillis)
Waits for this future to be completed within the specified time limit.
|
void |
cancel()
Completes (as a cancel) a request.
|
void |
cancel(long doneTimestamp)
Completes (as a cancel) a request.
|
void |
complete(P response)
Completes (as a success) a request by setting the response.
|
void |
complete(P response,
long doneTimestamp)
Completes (as a success) a request by setting the response.
|
void |
fail(Throwable t)
Completes (as a failure) a request by setting a throwable as the cause
of failure.
|
void |
fail(Throwable t,
long doneTimestamp)
Completes (as a failure) a request by setting a throwable as the cause
of failure.
|
long |
getAcceptTimestamp()
Gets the accept timestamp in milliseconds.
|
long |
getAcceptToDoneTime()
Gets the amount of time (in ms) from accept to done or -1 if a done
timestamp does not yet exist.
|
int |
getCallerStateHint()
Gets a hint of the caller state such as whether the caller is waiting, not
waiting, or timed out while waiting for completion.
|
Throwable |
getCause()
Returns the cause of the failed operation if the operation has
failed.
|
long |
getDoneTimestamp()
Gets the done timestamp in milliseconds.
|
long |
getExpireTimestamp()
Gets the expire timestamp in milliseconds.
|
K |
getKey()
Gets the key of the window entry.
|
long |
getOfferTimestamp()
Gets the offer timestamp in milliseconds.
|
long |
getOfferToAcceptTime()
Gets the amount of time (in ms) from offer to accept.
|
long |
getOfferToDoneTime()
Gets the amount of time (in ms) from offer to done or -1 if a done
timestamp does not yet exist.
|
R |
getRequest()
Gets the request contained in the window entry.
|
P |
getResponse()
Gets the response associated with the window entry.
|
int |
getWindowSize()
Returns the size of the window (number of requests in it) after this
request was added.
|
boolean |
hasDoneTimestamp()
Returns true if a done timestamp value exists (> 0).
|
boolean |
hasExpireTimestamp()
Returns true if an expire timestamp value exists (> 0).
|
boolean |
isCallerWaiting()
Returns
true if and only if the caller hinted at "WAITING" for
completion. |
boolean |
isCancelled()
Returns
true if and only if this future was cancelled by a
cancel() method. |
boolean |
isDone()
Returns
true if and only if this future is
complete, regardless of whether the operation was successful, failed,
or cancelled. |
boolean |
isSuccess()
Returns
true if and only if the operation was completed
successfully. |
void |
setCallerStateHint(int callerState) |
protected DefaultWindowFuture(Window window, ReentrantLock windowLock, Condition completedCondition, K key, R request, int callerStateHint, long originalOfferTimeoutMillis, int windowSize, long offerTimestamp, long acceptTimestamp, long expireTimestamp)
window - The window that created this future. Saved as a weak
reference to prevent circular references.windowLock - The shared lock from the windowcompletedCondition - The shared condition to wait onkey - The key of the futurerequest - The request of the futurecallerStateHint - The initial state of the caller hintoriginalOfferTimeoutMillis - windowSize - Size of the window after this request was added. Useful
for calculating an estimated response time for this request rather
than all requests ahead of it in the window.offerTimestamp - The timestamp when the request was offeredacceptTimestamp - The timestamp when the request was acceptedexpireTimestamp - The timestamp when the request will expire or -1
if no expiration is setpublic K getKey()
WindowFuturegetKey in interface WindowFuture<K,R,P>public R getRequest()
WindowFuturegetRequest in interface WindowFuture<K,R,P>public P getResponse()
WindowFuturegetResponse in interface WindowFuture<K,R,P>public Throwable getCause()
WindowFuturegetCause in interface WindowFuture<K,R,P>null if succeeded or this future is not
completed yet.public int getCallerStateHint()
WindowFuturegetCallerStateHint in interface WindowFuture<K,R,P>public void setCallerStateHint(int callerState)
public boolean isCallerWaiting()
WindowFuturetrue if and only if the caller hinted at "WAITING" for
completion. Returns false if the caller either did not hint
at planning on "WAITING" or did wait but timed out and gave up. Please
note that even if this returns true, it does not mean the caller is
actively waiting since this merely represents a hint.isCallerWaiting in interface WindowFuture<K,R,P>public int getWindowSize()
WindowFuturegetWindowSize in interface WindowFuture<K,R,P>public boolean hasExpireTimestamp()
WindowFuturehasExpireTimestamp in interface WindowFuture<K,R,P>public long getExpireTimestamp()
WindowFuturegetExpireTimestamp in interface WindowFuture<K,R,P>WindowFuture.hasExpireTimestamp()public long getOfferTimestamp()
WindowFuturegetOfferTimestamp in interface WindowFuture<K,R,P>public long getAcceptTimestamp()
WindowFuturegetAcceptTimestamp in interface WindowFuture<K,R,P>public boolean hasDoneTimestamp()
WindowFuturehasDoneTimestamp in interface WindowFuture<K,R,P>public long getDoneTimestamp()
WindowFuturegetDoneTimestamp in interface WindowFuture<K,R,P>public long getOfferToAcceptTime()
WindowFuturegetOfferToAcceptTime in interface WindowFuture<K,R,P>public long getOfferToDoneTime()
WindowFuturegetOfferToDoneTime in interface WindowFuture<K,R,P>public long getAcceptToDoneTime()
WindowFuturegetAcceptToDoneTime in interface WindowFuture<K,R,P>public boolean isDone()
WindowFuturetrue if and only if this future is
complete, regardless of whether the operation was successful, failed,
or cancelled.isDone in interface WindowFuture<K,R,P>public boolean isSuccess()
WindowFuturetrue if and only if the operation was completed
successfully.isSuccess in interface WindowFuture<K,R,P>public void complete(P response)
WindowFuturecomplete in interface WindowFuture<K,R,P>response - The response for the associated requestpublic void complete(P response, long doneTimestamp)
WindowFuturecomplete in interface WindowFuture<K,R,P>response - The response for the associated requestdoneTimestamp - The timestamp when the request completedpublic void fail(Throwable t)
WindowFuturefail in interface WindowFuture<K,R,P>t - The throwable as the cause of failurepublic void fail(Throwable t, long doneTimestamp)
WindowFuturefail in interface WindowFuture<K,R,P>t - The throwable as the cause of failuredoneTimestamp - The timestamp when the request failedpublic boolean isCancelled()
WindowFuturetrue if and only if this future was cancelled by a
cancel() method.isCancelled in interface WindowFuture<K,R,P>public void cancel()
WindowFuturecancel in interface WindowFuture<K,R,P>public void cancel(long doneTimestamp)
WindowFuturecancel in interface WindowFuture<K,R,P>doneTimestamp - The timestamp when the request was cancelledpublic boolean await()
throws InterruptedException
WindowFutureawait in interface WindowFuture<K,R,P>InterruptedException - Thrown if the current thread was interruptedpublic boolean await(long timeoutMillis)
throws InterruptedException
WindowFutureawait in interface WindowFuture<K,R,P>timeoutMillis - The amount of milliseconds to waitInterruptedException - Thrown if the current thread was interruptedCopyright © 2012-2015 Cloudhopper by Twitter. All Rights Reserved.