Class VCacheRequestContextManager
java.lang.Object
com.atlassian.confluence.impl.vcache.VCacheRequestContextManager
- All Implemented Interfaces:
VCacheRequestContextOperations
An implementation of
VCacheRequestContextOperations
which provides a simple interface to client code.
This class provides a single doInRequestContext(Action)
method which handles the thread-local
init/clear semantics internally.
Additionally, calls to the doInRequestContext(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 doInRequestContext(Action)
, then 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.
- Since:
- 5.10
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.atlassian.confluence.vcache.VCacheRequestContextOperations
VCacheRequestContextOperations.Action<T,
X extends Throwable> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T,
X extends Throwable>
TdoInRequestContext
(VCacheRequestContextOperations.Action<T, X> action) Executes the supplied action callback within a VCacheRequestContext
, using the system default partition identifier.<T,
X extends Throwable>
TdoInRequestContext
(String partitionIdentifer, VCacheRequestContextOperations.Action<T, X> action) Deprecated.since 6.0.@NonNull Runnable
Initialises the request context for the current thread, re-using any exist context if one is present.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.atlassian.confluence.vcache.VCacheRequestContextOperations
doInRequestContext, withRequestContext, withRequestContext
-
Constructor Details
-
VCacheRequestContextManager
-
-
Method Details
-
doInRequestContext
public <T,X extends Throwable> T doInRequestContext(VCacheRequestContextOperations.Action<T, X> action) throws XExecutes the supplied action callback within a VCacheRequestContext
, using the system default partition identifier.- Specified by:
doInRequestContext
in interfaceVCacheRequestContextOperations
- Type Parameters:
T
- the return type of the callbackX
- the exception type thrown by the callback- Parameters:
action
- the callback to be executed within the request context- Returns:
- the value returned by the callback
- Throws:
X
- the exception thrown by the callback
-
doInRequestContext
@Deprecated public <T,X extends Throwable> T doInRequestContext(String partitionIdentifer, VCacheRequestContextOperations.Action<T, X> action) throws XDeprecated.since 6.0. Partitions are not supported in Confluence ServerExecutes the supplied action callback within a VCacheRequestContext
. 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.- Specified by:
doInRequestContext
in interfaceVCacheRequestContextOperations
- Type Parameters:
T
- the return type of the callbackX
- the exception type thrown by the callback- Parameters:
partitionIdentifer
- the partition identifier that will be used to create new request context, if necessaryaction
- the callback to be executed within the request context- Returns:
- the value returned by the callback
- Throws:
X
- the exception thrown by the callback
-
initRequestContext
Initialises the request context for the current thread, re-using any exist context if one is present.- Returns:
- A
Runnable
that should be invoked to clear up the context. It is the callers job to ensure this is invoked at the appropriate time. Most callers should instead use the more foolproofVCacheRequestContextOperations.doInRequestContext(Runnable)
-