public interface WindowFuture<K,R,P>
WindowFuture is either uncompleted or completed.
When an operation begins, a new future object is created. The new future
is uncompleted initially - it is neither succeeded, failed, nor cancelled
because the operation is not finished yet. If the operation is
finished either successfully, with failure, or by cancellation, the future is
marked as completed with more specific information, such as the cause of the
failure. Please note that even failure and cancellation belong to the
completed state.
+---------------------------+
| Completed successfully |
+---------------------------+
+----> isDone() = true |
+--------------------------+ | | isSuccess() = true |
| Uncompleted | | +===========================+
+--------------------------+ | | Completed with failure |
| isDone() = false | | +---------------------------+
| isSuccess() = false |----+----> isDone() = true |
| isCancelled() = false | | | getCause() = non-null |
| getCause() = null | | +===========================+
+--------------------------+ | | Completed by cancellation |
| +---------------------------+
+----> isDone() = true |
| isCancelled() = true |
+---------------------------+
| Modifier and Type | Field and Description |
|---|---|
static int |
CALLER_NOT_WAITING
The caller is not waiting on this entry
|
static int |
CALLER_WAITING
The caller is waiting on this entry
|
static int |
CALLER_WAITING_TIMEOUT
The caller was waiting, but gave up (timeout)
|
| 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. |
static final int CALLER_NOT_WAITING
static final int CALLER_WAITING
static final int CALLER_WAITING_TIMEOUT
K getKey()
R getRequest()
P getResponse()
boolean isDone()
true if and only if this future is
complete, regardless of whether the operation was successful, failed,
or cancelled.boolean isSuccess()
true if and only if the operation was completed
successfully.Throwable getCause()
null if succeeded or this future is not
completed yet.boolean isCancelled()
true if and only if this future was cancelled by a
cancel() method.int getCallerStateHint()
boolean isCallerWaiting()
true 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.int getWindowSize()
boolean hasExpireTimestamp()
long getExpireTimestamp()
hasExpireTimestamp()long getOfferTimestamp()
long getAcceptTimestamp()
long getOfferToAcceptTime()
boolean hasDoneTimestamp()
long getDoneTimestamp()
long getOfferToDoneTime()
long getAcceptToDoneTime()
void complete(P response)
response - The response for the associated requestvoid complete(P response, long doneTimestamp)
response - The response for the associated requestdoneTimestamp - The timestamp when the request completedvoid fail(Throwable t)
t - The throwable as the cause of failurevoid fail(Throwable t, long doneTimestamp)
t - The throwable as the cause of failuredoneTimestamp - The timestamp when the request failedvoid cancel()
void cancel(long doneTimestamp)
doneTimestamp - The timestamp when the request was cancelledboolean await()
throws InterruptedException
InterruptedException - Thrown if the current thread was interruptedboolean await(long timeoutMillis)
throws InterruptedException
timeoutMillis - The amount of milliseconds to waitInterruptedException - Thrown if the current thread was interruptedCopyright © 2012-2015 Cloudhopper by Twitter. All Rights Reserved.