Package com.hybris.cockpitng.core.spring
Class RequestOperationContextHolder
- java.lang.Object
-
- com.hybris.cockpitng.core.spring.RequestOperationContextHolder
-
public class RequestOperationContextHolder extends java.lang.ObjectSingleton object which holds scope contexts specific to thread tree
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classRequestOperationContextHolder.ContextRequestAn object representing a request for scope context.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidattachToContext(RequestOperationContextHolder.ContextRequest contextRequest)Joins operation performed by current thread to scope context prepared earlier by callingprepareForOperation().protected RequestOperationContextcreateContext()protected RequestOperationContextHolder.ContextRequestcreateContextRequest()voiddetachFromContext()Disjoints operation performed by current thread from scope context prepared earlier by callingprepareForOperation().protected voiddetachRequestThreadFromContext(java.lang.Object requestId)protected voiddetachThreadFromContext(java.lang.Thread thread)RequestOperationContextgetContext()Obtains a context for current thread if available, otherwise throwsIllegalStateExceptionbooleanhasContext()Checks if context for current thread is availablevoidinitializeContext()Initializes new request operation context and binds it to current thread.static RequestOperationContextHolderinstance()Retrieve the instance of the singletonRequestOperationContextHolder.ContextRequestprepareForOperation()Prepares a context for current thread (if not yet created).
-
-
-
Method Detail
-
instance
public static RequestOperationContextHolder instance()
Retrieve the instance of the singleton- Returns:
- The
RequestOperationContextHoldersingleton instance
-
initializeContext
public void initializeContext()
Initializes new request operation context and binds it to current thread. If any other context is already bound with current thread, thread detaches from it (seedetachFromContext()).
-
prepareForOperation
public RequestOperationContextHolder.ContextRequest prepareForOperation()
Prepares a context for current thread (if not yet created). Method should be called in the thread that has a context already attached or is a root thread. It reserves resources for new operation context. It is required that an operation is actually started and attaches itself by callingattachToContext(ContextRequest).- Returns:
- a handle to prepared context
- See Also:
attachToContext(ContextRequest)
-
createContextRequest
protected RequestOperationContextHolder.ContextRequest createContextRequest()
-
createContext
protected RequestOperationContext createContext()
-
attachToContext
public void attachToContext(RequestOperationContextHolder.ContextRequest contextRequest)
Joins operation performed by current thread to scope context prepared earlier by callingprepareForOperation(). Method should be called in the operation's thread.- Parameters:
contextRequest- scope context request enquired byprepareForOperation()call
-
detachFromContext
public void detachFromContext()
Disjoints operation performed by current thread from scope context prepared earlier by callingprepareForOperation(). Method should be called in the operation's thread. If context is no longer used, then it is cleared and removed.
-
detachRequestThreadFromContext
protected void detachRequestThreadFromContext(java.lang.Object requestId)
-
detachThreadFromContext
protected void detachThreadFromContext(java.lang.Thread thread)
-
hasContext
public boolean hasContext()
Checks if context for current thread is available- Returns:
trueif there is a context correlated with this thread- See Also:
initializeContext()
-
getContext
public RequestOperationContext getContext()
Obtains a context for current thread if available, otherwise throwsIllegalStateException- Returns:
- context correlated with this thread
- See Also:
initializeContext()
-
-