public interface FiberContextSwitchInterceptor
Fiber
context switch.
Even though pipeline runs asynchronously, sometimes it's desirable
to bind some state to the current thread running a fiber. Such state
may include security subject (in terms of AccessController.doPrivileged(java.security.PrivilegedAction<T>)
),
or a transaction.
This mechanism makes it possible to do such things, by allowing some code to be executed before and after a thread executes a fiber.
The design also encapsulates the entire fiber execution in a single
opaque method invocation FiberContextSwitchInterceptor.Work.execute(P)
, allowing the use of
finally block.
Modifier and Type | Interface and Description |
---|---|
static interface |
FiberContextSwitchInterceptor.Work<R,P>
Abstraction of the execution that happens inside the interceptor.
|
Modifier and Type | Method and Description |
---|---|
<R,P> R |
execute(Fiber f,
P p,
FiberContextSwitchInterceptor.Work<R,P> work)
Allows the interception of the fiber execution.
|
<R,P> R execute(Fiber f, P p, FiberContextSwitchInterceptor.Work<R,P> work)
This method needs to be implemented like this:
<R,P> R execute( Fiber f, P p, Work<R,P> work ) { // do some preparation work ... try { // invoke return work.execute(p); } finally { // do some clean up work ... } }
While somewhat unintuitive,
this interception mechanism enables the interceptor to wrap
the whole fiber execution into a AccessController.doPrivileged(PrivilegedAction)
,
for example.
f
- Fiber
to be executed.p
- The opaque parameter value for FiberContextSwitchInterceptor.Work
. Simply pass this value to
FiberContextSwitchInterceptor.Work.execute(Object)
.FiberContextSwitchInterceptor.Work
. Simply return
the value from FiberContextSwitchInterceptor.Work.execute(Object)
.Copyright © 2015 Oracle Corporation. All rights reserved.