public interface

RequestContext

implements RequestInfoProvider
com.atlassian.stash.request.RequestContext

Class Overview

Provides information about a request, such as the requestId, sessionId, remoteAddress and more. RequestContext is currently used as an abstraction for HTTP and SSH requests, but can easily be used for other protocols as well.

See Also

Summary

Public Methods
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.
@Nullable StashAuthenticationContext getAuthenticationContext()
Convenience method to access the authentication context for the current request.
@Nonnull String getId()
Returns a highly unique (though not guaranteeably unique) request ID.
boolean isActive()
[Expand]
Inherited Methods
From interface com.atlassian.stash.request.RequestInfoProvider
From interface com.atlassian.stash.request.RequestMetadata

Public Methods

public void addCleanupCallback (Runnable callback)

Registers a cleanup task that is executed when the current request ends. Note that the callback will only be called for the current request.

Parameters
callback callback that should be called when the request ends

public void addLabel (String label)

Adds a label to the request context that will be included in the access logs. Use this purely for diagnostic / analysis purposes.

Parameters
label the label to add

@Nullable public StashAuthenticationContext getAuthenticationContext ()

Convenience method to access the authentication context for the current request.

Returns
  • the StashAuthenticationContext for the current request, or null if there is no authenticated user.

@Nonnull public String getId ()

Returns a highly unique (though not guaranteeably unique) request ID.

The request ID contains:

  1. The minute of the current day
  2. The number of requests, including the current one, which have been serviced by the application since it was started
  3. The number of requests which were being processed concurrently at the time the ID was generated
These fields are separated by an "x". The hour of the day portion resets each night, and the concurrency count rises and falls with the load on the server. The request count is monotonically increasing until the 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.

Returns
  • the generated request ID

public boolean isActive ()

Returns
  • true if the request is in progress. false if there is no current request or the request has finished