Top Description Methods
org.glassfish.hk2.api

public Interface Context<T>

Known Direct Implementers
org.glassfish.hk2.internal.InheritableThreadContext, org.glassfish.hk2.internal.PerThreadContext, org.glassfish.hk2.utilities.ImmediateContext
Annotations
@Contract
Type Parameters
<T>
This must be the type for which this is a context. For example, if your scope is SecureScope, then your context must implement Context<SecureScope>
Imports
java.lang.annotation.Annotation, org.jvnet.hk2.annotations.Contract

An implementation of this must be put into the system in order to create contextual instances of services. If there is more than one active implementation available for the same scope on the same thread a runtime exception will be thrown when the scope is accessed.

An implementation of Context must be in the Singleton scope

Author
jwells

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if this context has a value associated with this descriptor
containsKey
(ActiveDescriptor<?>
The descriptor to look for in this context
descriptor
)

Determines if this context has a value for the given key

public void
destroyOne(ActiveDescriptor<?>
A non-null descriptor upon which ServiceHandle#destroy() has been called
descriptor
)

This method is called when ServiceHandle#destroy() method is called.

public <U> U

Returns:

A context instance. This value may NOT be null
findOrCreate
(ActiveDescriptor<U>
The descriptor to use when creating instances
activeDescriptor
,
ServiceHandle<?>
The extended provider for the outermost parent being created
root
)

Creates a contextual instance of this ActiveDescriptor by calling its create method if there is no other matching contextual instance.

public Class<? extends Annotation>

Returns:

may not return null, must return the scope for which this is a context
getScope
()

The scope for which this is the context

public boolean

Returns:

true if this context is active, false otherwise
isActive
()

True if this context is active, false otherwise

public void
shutdown()

Shut down this context.

public boolean

Returns:

true if null is a legal value from the findOrCreate method
supportsNullCreation
()

Returns true if the findOrCreate method can return null

Method Detail

containsKeyback to summary
public boolean containsKey(ActiveDescriptor<?> descriptor)

Determines if this context has a value for the given key

Parameters
descriptor:ActiveDescriptor<?>

The descriptor to look for in this context

Returns:boolean

true if this context has a value associated with this descriptor

destroyOneback to summary
public void destroyOne(ActiveDescriptor<?> descriptor)

This method is called when 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 context

Parameters
descriptor:ActiveDescriptor<?>

A non-null descriptor upon which ServiceHandle#destroy() has been called

findOrCreateback to summary
public <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. If there is already a contextual instance it is returned. If parent is null then this must work like the find call

Parameters
activeDescriptor:ActiveDescriptor<U>

The descriptor to use when creating instances

root:ServiceHandle<?>

The extended provider for the outermost parent being created

Returns:U

A context instance. This value may NOT be null

getScopeback to summary
public Class<? extends Annotation> getScope()

The scope for which this is the context

Returns:Class<? extends Annotation>

may not return null, must return the scope for which this is a context

isActiveback to summary
public boolean isActive()

True if this context is active, false otherwise

Returns:boolean

true if this context is active, false otherwise

shutdownback to summary
public void shutdown()

Shut down this context.

supportsNullCreationback to summary
public boolean supportsNullCreation()

Returns true if the findOrCreate method can return null

Returns:boolean

true if null is a legal value from the findOrCreate method