com.sun.xml.ws.api.pipe
Interface FiberContextSwitchInterceptor


public interface FiberContextSwitchInterceptor

Interception for 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)), 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.


Nested Class Summary
static interface FiberContextSwitchInterceptor.Work<R,P>
          Abstraction of the execution that happens inside the interceptor.
 
Method Summary
<R,P> R
execute(Fiber f, P p, FiberContextSwitchInterceptor.Work<R,P> work)
          Allows the interception of the fiber execution.
 

Method Detail

execute

<R,P> R execute(Fiber f,
                P p,
                FiberContextSwitchInterceptor.Work<R,P> work)
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 - Fiber to be executed.
p - The opaque parameter value for FiberContextSwitchInterceptor.Work. Simply pass this value to FiberContextSwitchInterceptor.Work.execute(Object).
Returns:
The opaque return value from the the FiberContextSwitchInterceptor.Work. Simply return the value from FiberContextSwitchInterceptor.Work.execute(Object).