@Contract public abstract class OperationContext<T extends Annotation> extends Object implements Context<T>
Context
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 the Context.getScope()
and making sure the parameterized type is the Scope annotation.
The Scope
annotation for an Operation is usually
Proxiable
but does not have to be. As with all implementations
of Context
the subclass of this class must be in the SingletonInjectsPerRequest
scope. The user code then uses the OperationManager
and OperationHandle
to start and stop Operations and to associate and dis-associate
threads with Operations
Classes extending this class may also choose to override the method
Context.supportsNullCreation()
which returns false by default
Constructor and Description |
---|
OperationContext() |
Modifier and Type | Method and Description |
---|---|
void |
closeOperation(OperationHandleImpl<T> operation) |
boolean |
containsKey(ActiveDescriptor<?> descriptor)
Determines if this context has a value for the given key
|
void |
destroyOne(ActiveDescriptor<?> descriptor)
This method is called when
ServiceHandle.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 otherwise
|
void |
setOperationManager(SingleOperationManager<T> manager) |
void |
shutdown()
Shut down this context.
|
boolean |
supportsNullCreation()
Returns true if the findOrCreate method can return null
|
String |
toString() |
public <U> U findOrCreate(ActiveDescriptor<U> activeDescriptor, ServiceHandle<?> root)
Context
findOrCreate
in interface Context<T extends Annotation>
activeDescriptor
- The descriptor to use when creating instancesroot
- The extended provider for the outermost parent being createdpublic boolean containsKey(ActiveDescriptor<?> descriptor)
Context
containsKey
in interface Context<T extends Annotation>
descriptor
- The descriptor to look for in this contextpublic void destroyOne(ActiveDescriptor<?> descriptor)
Context
ServiceHandle.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 contextdestroyOne
in interface Context<T extends Annotation>
descriptor
- A non-null descriptor upon which ServiceHandle.destroy()
has been calledpublic void closeOperation(OperationHandleImpl<T> operation)
public void shutdown()
Context
shutdown
in interface Context<T extends Annotation>
public boolean supportsNullCreation()
Context
supportsNullCreation
in interface Context<T extends Annotation>
public boolean isActive()
Context
isActive
in interface Context<T extends Annotation>
public void setOperationManager(SingleOperationManager<T> manager)
Copyright © 2009-2017, Oracle and/or its affiliates. All Rights Reserved.