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.
- Author:
- Kohsuke Kawaguchi
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceAbstraction of the execution that happens inside the interceptor. -
Method Summary
Modifier and TypeMethodDescription<R,P> R execute(Fiber f, P p, FiberContextSwitchInterceptor.Work<R, P> work) Allows the interception of the fiber execution.
-
Method Details
-
execute
Allows the interception of the fiber execution.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.- Parameters:
f-Fiberto be executed.p- The opaque parameter value forFiberContextSwitchInterceptor.Work. Simply pass this value toFiberContextSwitchInterceptor.Work.execute(Object).- Returns:
- The opaque return value from the the
FiberContextSwitchInterceptor.Work. Simply return the value fromFiberContextSwitchInterceptor.Work.execute(Object).
-