public class RequestContext
extends java.lang.Object
Constructor and Description |
---|
RequestContext()
Build a new
RequestContext with a default 30s timeout. |
RequestContext(RequestContext src)
Copy constructor.
|
Modifier and Type | Method and Description |
---|---|
RequestContext |
computeDeadline()
Compute a deadline from the
timeout() . |
int |
deadline()
Get the deadline for this request.
|
int |
elapsed()
Tell the time elapsed since this request has started.
|
RequestContext |
ensureRequestId()
Ensure this request has an ID and it is at least 8 characters.
|
boolean |
hasDeadline()
Tell whether this request has a deadline or not.
|
boolean |
hasStarted()
Tell if this request has started.
|
boolean |
hasTimeout()
Tell whether this request has a timeout or not.
|
java.lang.String |
requestId()
Get the request ID.
|
RequestContext |
resetDeadline()
Reset the deadline set on this request.
|
RequestContext |
startTiming()
Start timing this request.
|
int |
timeout()
Get the timeout for the request.
|
RequestContext |
withDeadline(int deadline)
Set a deadline on the whole request.
|
RequestContext |
withRequestId(java.lang.String requestId)
Set a request ID.
|
RequestContext |
withTimeout(int timeout)
Set a timeout for each unique sub-request resulting from an API call.
|
public RequestContext()
RequestContext
with a default 30s timeout.public RequestContext(RequestContext src)
RequestContext
from another one.
This will keep the request ID, the timeout and the deadline (if there is one).src
- The RequestContext
to copy.public RequestContext ensureRequestId()
public java.lang.String requestId()
public RequestContext withRequestId(java.lang.String requestId)
requestId
- a request ID string. If is null, it will be auto-generated. If
it is less than 8 characters, it will be suffixed.public RequestContext computeDeadline()
timeout()
. This also means that the
timeout will be recomputed for each unique sub-request resulting from an
API call. If this request has started, compute the timeout from the start,
otherwise compute it from now.this
public int deadline()
withTimeout(int)
) but no
deadline, computeDeadline()
will be called.public int elapsed()
public boolean hasDeadline()
true
after computeDeadline()
or deadline()
has been
called.true
if this request has a deadline.public boolean hasStarted()
true
if this request has started.public boolean hasTimeout()
true
if this request has timeout.public RequestContext resetDeadline()
this
public RequestContext startTiming()
public int timeout()
hasDeadline()
returns true
, successive calls to this
method will return decreasing values, and negative values when the
deadline has been exceeded.public RequestContext withDeadline(int deadline)
withTimeout(int)
to the duration
from now to the deadline.deadline
- the deadline in millisecondspublic RequestContext withTimeout(int timeout)
withDeadline(int)
.
The timeout will be used to compute the deadline when
startTiming()
or deadline()
is called.timeout
- a timeout in milliseconds