public class VCacheRequestContextManager extends Object implements VCacheRequestContextOperations
VCacheRequestContextOperations
, this class provides a single VCacheRequestContextOperations.doInRequestContext(Supplier, Action)
method which handles the thread-local init/clear semantics internally.
Additionally, calls to the VCacheRequestContextOperations.doInRequestContext(Supplier, Action)
method can be nested, allowing different levels of
client code to ensure that the request context is initialized without worrying about whether or not it's already been
done further up the call stack.
If getCurrentRequestContext()
is invoked outside of the context of VCacheRequestContextOperations.doInRequestContext(Supplier, Action)
this class
will return a RequestContext
which stubs out method calls, and which remembers no data. The RequestContext.partitionIdentifier()
of this
object will be the same "fallback" identifier passed as an argument to this class's constructor, and represents the
"unknown tenant" state of code that hasn't initialised the context properly.
VCacheRequestContextOperations.Action<T,X extends Throwable>
Constructor and Description |
---|
VCacheRequestContextManager(VCachePartitionIdentifierProvider partitionIdentifierProvider) |
Modifier and Type | Method and Description |
---|---|
<T,X extends Throwable> |
doInRequestContext(Supplier<String> partitionIdentiferSupplier,
VCacheRequestContextOperations.Action<T,X> action)
Executes the supplied action callback within a VCache
RequestContext . |
<T,X extends Throwable> |
doInRequestContext(VCacheRequestContextOperations.Action<T,X> action)
Executes the supplied action callback within a VCache
RequestContext , using the system default
partition identifier. |
com.atlassian.vcache.internal.RequestContext |
getCurrentRequestContext()
Returns a
RequestContext for the current thread. |
Runnable |
initRequestContext() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
doInRequestContext, withRequestContext, withRequestContext
public VCacheRequestContextManager(VCachePartitionIdentifierProvider partitionIdentifierProvider)
@Nonnull public com.atlassian.vcache.internal.RequestContext getCurrentRequestContext()
RequestContext
for the current thread. If the thread is within a VCacheRequestContextOperations.doInRequestContext(Action)
block, then a "real" context will be returned (i.e. one that memoizes context information). Otherwise, a "fake"
context will be returned (i.e. one that does not memoize anything).public <T,X extends Throwable> T doInRequestContext(VCacheRequestContextOperations.Action<T,X> action) throws X extends Throwable
RequestContext
, using the system default
partition identifier.doInRequestContext
in interface VCacheRequestContextOperations
T
- the return type of the callbackX
- the exception type thrown by the callbackaction
- the callback to be executed within the request contextX
- the exception thrown by the callbackX extends Throwable
public <T,X extends Throwable> T doInRequestContext(Supplier<String> partitionIdentiferSupplier, VCacheRequestContextOperations.Action<T,X> action) throws X extends Throwable
RequestContext
. If no request context is bound to
the current thread, then one will be set up with the supplied partition identifier. Calls to this method may be
nested. Nested calls will re-use the existing context bound by the first call. Nested calls must supply the
same partition identifier as the first call.doInRequestContext
in interface VCacheRequestContextOperations
T
- the return type of the callbackX
- the exception type thrown by the callbackpartitionIdentiferSupplier
- the supplier for paritiotn identifier that will be used to create new request context, if necessaryaction
- the callback to be executed within the request contextX
- the exception thrown by the callbackX extends Throwable
public Runnable initRequestContext()
Copyright © 2003–2017 Atlassian. All rights reserved.