Class OperationContext<T extends java.lang.annotation.Annotation>
- java.lang.Object
-
- org.glassfish.hk2.extras.operation.OperationContext<T>
-
- All Implemented Interfaces:
Context<T>
@Contract public abstract class OperationContext<T extends java.lang.annotation.Annotation> extends java.lang.Object implements Context<T>
The implementation ofContext
for an Operation.An operation is defined as a unit of work that can be associated with one or more java threads, but where two operations of the same type may not be associated with the same thread at the same time. Examples of such an operation might be a RequestScope or a TenantRequesteOperation. An operation is a more general concept than the normal Java EE request scope, since it does not require a Java EE container
Users of this API generally create a
Scope
annotation and extend this class, implementing theContext.getScope()
and making sure the parameterized type is the Scope annotation. TheScope
annotation for an Operation is usuallyProxiable
but does not have to be. As with all implementations ofContext
the subclass of this class must be in theSingletonInjectsPerRequest
scope. The user code then uses theOperationManager
andOperationHandle
to start and stop Operations and to associate and dis-associate threads with OperationsClasses extending this class may also choose to override the method
Context.supportsNullCreation()
which returns false by default
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.HashMap<java.lang.Long,java.util.LinkedList<OperationHandleImpl<T>>>
closingOperations
private java.util.HashSet<ActiveDescriptor<?>>
creating
private SingleOperationManager<T>
manager
private java.util.HashMap<OperationHandleImpl<T>,java.util.LinkedHashMap<ActiveDescriptor<?>,java.lang.Object>>
operationMap
private boolean
shuttingDown
-
Constructor Summary
Constructors Constructor Description OperationContext()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
closeOperation(OperationHandleImpl<T> operation)
boolean
containsKey(ActiveDescriptor<?> descriptor)
Determines if this context has a value for the given keyvoid
destroyOne(ActiveDescriptor<?> descriptor)
This method is called whenServiceHandle.destroy()
method is called.<U> U
findOrCreate(ActiveDescriptor<U> activeDescriptor, ServiceHandle<?> root)
Creates a contextual instance of this ActiveDescriptor by calling its create method if there is no other matching contextual instance.boolean
isActive()
True if this context is active, false otherwisevoid
setOperationManager(SingleOperationManager<T> manager)
void
shutdown()
Shut down this context.boolean
supportsNullCreation()
Returns true if the findOrCreate method can return nulljava.lang.String
toString()
-
-
-
Field Detail
-
manager
private SingleOperationManager<T extends java.lang.annotation.Annotation> manager
-
operationMap
private final java.util.HashMap<OperationHandleImpl<T extends java.lang.annotation.Annotation>,java.util.LinkedHashMap<ActiveDescriptor<?>,java.lang.Object>> operationMap
-
creating
private final java.util.HashSet<ActiveDescriptor<?>> creating
-
closingOperations
private final java.util.HashMap<java.lang.Long,java.util.LinkedList<OperationHandleImpl<T extends java.lang.annotation.Annotation>>> closingOperations
-
shuttingDown
private boolean shuttingDown
-
-
Method Detail
-
findOrCreate
public <U> U findOrCreate(ActiveDescriptor<U> activeDescriptor, ServiceHandle<?> root)
Description copied from interface:Context
Creates a contextual instance of this ActiveDescriptor by calling its create method if there is no other matching contextual instance. If there is already a contextual instance it is returned. If parent is null then this must work like the find call- Specified by:
findOrCreate
in interfaceContext<T extends java.lang.annotation.Annotation>
- Parameters:
activeDescriptor
- The descriptor to use when creating instancesroot
- The extended provider for the outermost parent being created- Returns:
- A context instance. This value may NOT be null
-
containsKey
public boolean containsKey(ActiveDescriptor<?> descriptor)
Description copied from interface:Context
Determines if this context has a value for the given key- Specified by:
containsKey
in interfaceContext<T extends java.lang.annotation.Annotation>
- Parameters:
descriptor
- The descriptor to look for in this context- Returns:
- true if this context has a value associated with this descriptor
-
destroyOne
public void destroyOne(ActiveDescriptor<?> descriptor)
Description copied from interface:Context
This method is called whenServiceHandle.destroy()
method is called. It is up to the context implementation whether or not to honor this destruction request based on the lifecycle requirements of the context- Specified by:
destroyOne
in interfaceContext<T extends java.lang.annotation.Annotation>
- Parameters:
descriptor
- A non-null descriptor upon whichServiceHandle.destroy()
has been called
-
closeOperation
public void closeOperation(OperationHandleImpl<T> operation)
-
shutdown
public void shutdown()
Description copied from interface:Context
Shut down this context.
-
supportsNullCreation
public boolean supportsNullCreation()
Description copied from interface:Context
Returns true if the findOrCreate method can return null- Specified by:
supportsNullCreation
in interfaceContext<T extends java.lang.annotation.Annotation>
- Returns:
- true if null is a legal value from the findOrCreate method
-
isActive
public boolean isActive()
Description copied from interface:Context
True if this context is active, false otherwise
-
setOperationManager
public void setOperationManager(SingleOperationManager<T> manager)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-