public interface RequestContext extends RequestInfoProvider
RequestContext
is currently used as an abstraction for HTTP and SSH requests, but can easily be used for other protocols as well.RequestManager
Modifier and Type | Method and Description |
---|---|
void |
addCleanupCallback(Runnable callback)
Registers a cleanup task that is executed when the current request ends.
|
void |
addLabel(String label)
Adds a label to the request context that will be included in the access logs.
|
long |
getBytesRead() |
long |
getBytesWritten() |
Optional<Duration> |
getDuration() |
String |
getId()
Returns a highly unique (though not guaranteeably unique) request ID.
|
boolean |
isActive() |
void |
setBytesRead(long bytesRead)
Report on the number of bytes read for this request.
|
void |
setBytesWritten(long bytesWritten)
Report on the number of bytes written for this request.
|
void |
setResponseCode(int responseCode)
The response code of the request.
|
getRawRequest, getRawResponse
getAction, getDetails, getProtocol, getRemoteAddress, getSessionId, hasSessionId, isSecure
void addCleanupCallback(@Nonnull Runnable callback)
callback
- callback that should be called when the request endsIllegalStateException
- if no request is active
void addLabel(@Nonnull String label)
label
- the label to addIllegalStateException
- if no request is active
@Nonnull String getId()
The request ID contains:
long
for the counter wraps (which at 1,000 requests per second will take 252 million years).
It is worth noting that the uniqueness period required for request IDs is 1 day, which is the period at which log files are rotated. The goal of this ID is not to be universally unique so much as it is to allow support to easily trace the logging related to a single request, within the log files.
IllegalStateException
- if no request is active
boolean isActive()
true
if the request is in progress. false
if there is no current request or the request
has finishedlong getBytesRead()
void setBytesRead(long bytesRead)
bytesRead
- the number of bytes readIllegalStateException
- if no request is active
long getBytesWritten()
void setBytesWritten(long bytesWritten)
bytesWritten
- the number of bytes writtenIllegalStateException
- if no request is active
@Nonnull Optional<Duration> getDuration()
Duration
representing the amount of wall time taken to process this request or
Optional.EMPTY
if the duration has not been setvoid setResponseCode(int responseCode)
responseCode
- the request response codeIllegalStateException
- if no request is active
Copyright © 2019 Atlassian. All rights reserved.