public class ThreadLocalRequestCorrelator extends java.lang.Object implements RequestCorrelator
RequestCorrelator that fetches ContextsContainer and request Identifer from
ThreadLocal variables. EventLoopGroup used by all RxClients in use for
the propagation of these contexts, uses ContextAwareEventLoopGroup. | Modifier and Type | Class and Description |
|---|---|
static class |
ThreadLocalRequestCorrelator.ThreadStateHolder |
| Modifier and Type | Field and Description |
|---|---|
protected static java.lang.ThreadLocal<ThreadLocalRequestCorrelator.ThreadStateHolder> |
state |
| Constructor and Description |
|---|
ThreadLocalRequestCorrelator() |
| Modifier and Type | Method and Description |
|---|---|
void |
beforeNewClientRequest(java.lang.String requestId,
ContextsContainer contextsContainer)
A callback before a client request is made.
|
void |
dumpThreadState() |
void |
dumpThreadState(java.io.PrintStream outputStream) |
ContextsContainer |
getContextForClientRequest(java.lang.String requestId)
This method does the correlation between the inbound
ContextsContainer to a fresh client request. |
static ContextsContainer |
getCurrentContextContainer() |
static java.lang.String |
getCurrentRequestId() |
java.lang.String |
getRequestIdForClientRequest()
This does the correlation between an inbound request and all outbound requests that are made during the
processing of the same request.
|
<V> java.util.concurrent.Callable<V> |
makeClosure(java.util.concurrent.Callable<V> original)
Encloses the passed
Callable into a closure so that it can capture the contexts as it exists when this
Callable is created and use it during the context's execution, which happens in a different thread. |
java.lang.Runnable |
makeClosure(java.lang.Runnable original)
Encloses the passed
Runnable into a closure so that it can capture the contexts as it exists when this
Runnable is created and use it during the context's execution, which happens in a different thread. |
void |
onClientProcessingEnd(java.lang.String requestId)
A callback when a client is done with the processing of the passed
requestId. |
void |
onNewServerRequest(java.lang.String requestId,
ContextsContainer contextsContainer)
A callback for a fresh request on the underlying channel.
|
void |
onServerProcessingEnd(java.lang.String requestId)
A callback when the entire request processing is over for the passed
requestId |
protected static final java.lang.ThreadLocal<ThreadLocalRequestCorrelator.ThreadStateHolder> state
public java.lang.String getRequestIdForClientRequest()
RequestCorrelatorgetRequestIdForClientRequest in interface RequestCorrelatornull otherwise.public ContextsContainer getContextForClientRequest(java.lang.String requestId)
RequestCorrelatorContextsContainer to a fresh client request.getContextForClientRequest in interface RequestCorrelatorrequestId - Request Id for this request. Can be nullContextsContainer for this request, if any. null if none exists.public void onNewServerRequest(java.lang.String requestId,
ContextsContainer contextsContainer)
RequestCorrelatoronNewServerRequest in interface RequestCorrelatorrequestId - Request Id for this request.contextsContainer - Container for this request.public void beforeNewClientRequest(java.lang.String requestId,
ContextsContainer contextsContainer)
RequestCorrelatorRequestCorrelator.onNewServerRequest(String, ContextsContainer). This method is provided to be explicit on when these
callbacks are made. RequestCorrelator.getRequestIdForClientRequest() and
RequestCorrelator.getContextForClientRequest(String) which is the reason why this context setting is
required.beforeNewClientRequest in interface RequestCorrelatorrequestId - Request Id for this request.contextsContainer - Container for this request.public void onClientProcessingEnd(java.lang.String requestId)
RequestCorrelatorrequestId. onClientProcessingEnd in interface RequestCorrelatorrequestId - Request id for which the processing is over.public void onServerProcessingEnd(java.lang.String requestId)
RequestCorrelatorrequestIdonServerProcessingEnd in interface RequestCorrelatorrequestId - Request id for which the processing is over.public static ContextsContainer getCurrentContextContainer()
public static java.lang.String getCurrentRequestId()
public <V> java.util.concurrent.Callable<V> makeClosure(java.util.concurrent.Callable<V> original)
ContextCapturerCallable into a closure so that it can capture the contexts as it exists when this
Callable is created and use it during the context's execution, which happens in a different thread.makeClosure in interface ContextCapturerV - Return type of the Callableoriginal - Original Callable to be invoked from the closure.Callablepublic java.lang.Runnable makeClosure(java.lang.Runnable original)
ContextCapturerRunnable into a closure so that it can capture the contexts as it exists when this
Runnable is created and use it during the context's execution, which happens in a different thread.makeClosure in interface ContextCaptureroriginal - Original Runnable to be invoked from the closure.Runnablepublic void dumpThreadState()
public void dumpThreadState(java.io.PrintStream outputStream)