Package org.glassfish.jersey.inject.hk2
Class Hk2RequestScope.Instance
- java.lang.Object
-
- org.glassfish.jersey.inject.hk2.Hk2RequestScope.Instance
-
- All Implemented Interfaces:
RequestContext
- Enclosing class:
- Hk2RequestScope
public static final class Hk2RequestScope.Instance extends java.lang.Object implements RequestContext
Implementation of the request scope instance.
-
-
Field Summary
Fields Modifier and Type Field Description private LazyUid
id
private ExtendedLogger
logger
private java.util.concurrent.atomic.AtomicInteger
referenceCounter
Holds the number of snapshots of this scope.private java.util.Map<ForeignDescriptor,java.lang.Object>
store
A map of injectable instances in this scope.
-
Constructor Summary
Constructors Modifier Constructor Description private
Instance()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
contains(ForeignDescriptor provider)
<T> T
get(ForeignDescriptor descriptor)
Get an inhabitant stored in the scope instance that matches the active descriptor .Hk2RequestScope.Instance
getReference()
Get a "new" reference of the scope instance.<T> T
put(ForeignDescriptor descriptor, T value)
Store a new inhabitant for the given descriptor.void
release()
Release a single reference to the current request scope instance.<T> void
remove(ForeignDescriptor descriptor)
Remove a value for the descriptor if present in the scope instance store.java.lang.String
toString()
-
-
-
Field Detail
-
logger
private final ExtendedLogger logger
-
id
private final LazyUid id
-
store
private final java.util.Map<ForeignDescriptor,java.lang.Object> store
A map of injectable instances in this scope.
-
referenceCounter
private final java.util.concurrent.atomic.AtomicInteger referenceCounter
Holds the number of snapshots of this scope.
-
-
Method Detail
-
getReference
public Hk2RequestScope.Instance getReference()
Get a "new" reference of the scope instance. This will increase the internal reference counter which prevents the scope instance to be destroyed until arelease()
method is explicitly called (once per eachgetReference()
method call).- Specified by:
getReference
in interfaceRequestContext
- Returns:
- referenced scope instance.
-
get
public <T> T get(ForeignDescriptor descriptor)
Get an inhabitant stored in the scope instance that matches the active descriptor .- Type Parameters:
T
- inhabitant type.- Parameters:
descriptor
- inhabitant descriptor.- Returns:
- matched inhabitant stored in the scope instance or
null
if not matched.
-
put
public <T> T put(ForeignDescriptor descriptor, T value)
Store a new inhabitant for the given descriptor.- Type Parameters:
T
- inhabitant type.- Parameters:
descriptor
- inhabitant descriptor.value
- inhabitant value.- Returns:
- old inhabitant previously stored for the given descriptor or
null
if none stored.
-
remove
public <T> void remove(ForeignDescriptor descriptor)
Remove a value for the descriptor if present in the scope instance store.- Parameters:
descriptor
- key for the value to be removed.
-
contains
public boolean contains(ForeignDescriptor provider)
-
release
public void release()
Release a single reference to the current request scope instance.Once all instance references are released, the instance will be recycled.
- Specified by:
release
in interfaceRequestContext
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-