|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.glassfish.jersey.process.internal.RequestScope
public class RequestScope
Scopes a single request/response processing execution.
This implementation is derived from Guice Wiki article on Custom Scopes: Apply this scope with atry…finally block:
scope.enter();
try {
// explicitly seed some seed objects...
scope.seed(Key.get(SomeObject.class), someObject);
// create and access scoped objects
} finally {
scope.exit();
}
The scope can be initialized with one or more seed instances by calling
seed(key, instance) before the injector will be called upon to
provide for this key. A typical use is for a Servlet filter to enter/exit the
scope, representing a Request Scope, and seed HttpServletRequest and
HttpServletResponse. For each key inserted with seed(), it's good practice
(since you have to provide some binding anyhow) to include a
corresponding binding that will throw an exception if Guice is asked to
provide for that key if it was not yet seeded:
bind(key)
.toProvider(RequestScope.unseededKeyProvider())
.in(ScopeAnnotation.class);
| Nested Class Summary | |
|---|---|
static class |
RequestScope.Module
|
static class |
RequestScope.Snapshot
An opaque RequestScope state holder. |
| Constructor Summary | |
|---|---|
RequestScope()
|
|
| Method Summary | |
|---|---|
org.glassfish.hk2.ScopeInstance |
current()
|
void |
enter()
Enters the new RequestScope scope block in the current thread. |
void |
enter(RequestScope.Snapshot snapshot)
Resumes/continues an existing RequestScope scope block in the
current thread. |
void |
exit()
Exits the active scope block in the current thread. |
boolean |
isActive()
Provides information whether the current code is executed in a context of an active request scope. |
RequestScope.Snapshot |
takeSnapshot()
Takes snapshot of the state of the active RequestScope scope block
in the current thread. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public RequestScope()
| Method Detail |
|---|
public org.glassfish.hk2.ScopeInstance current()
current in interface org.glassfish.hk2.Scope
public RequestScope.Snapshot takeSnapshot()
throws IllegalStateException
RequestScope scope block
in the current thread.
RequestScope scope block state snapshot
IllegalStateException - in case there is no active RequestScope
scope block in the current thread.public boolean isActive()
true if the current code runs in a context of an active
request scope, false otherwise.
public void enter()
throws IllegalStateException
RequestScope scope block in the current thread.
NOTE: This method must not be called from within an active RequestScope
scope block in the same thread.
IllegalStateException - in case the method is called from an already
active RequestScope scope block in the same thread.
public void enter(RequestScope.Snapshot snapshot)
throws IllegalStateException
RequestScope scope block in the
current thread. All scope data are initialized from the provided
scope snapshot.
NOTE: This method must not be called from within an active RequestScope
scope block in the same thread otherwise an exception will be thrown.
snapshot - snapshot of the scope block that should be resumed
in the current thread
IllegalStateException - in case the method is called from an already
active RequestScope scope block in the same thread.
public void exit()
throws IllegalStateException
RequestScope
scope block in the current thread.
IllegalStateException - in case there is no active RequestScope scope
block to exit in the current thread.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||