org.apache.camel.spi
Interface Policy

All Known Subinterfaces:
AuthorizationPolicy, TransactedPolicy

public interface Policy

A strategy capable of applying interceptors to a processor

Its strongly adviced to use an AsyncProcessor as the returned wrapped Processor which ensures the policy works well with the asynchronous routing engine. You can use the DelegateAsyncProcessor to easily return an AsyncProcessor and override the AsyncProcessor.process(org.apache.camel.Exchange, org.apache.camel.AsyncCallback) to implement your interceptor logic. And just invoke the super method to continue routing.

Mind that not all frameworks supports asynchronous routing, for example some transaction managers, such as Spring Transaction uses the current thread to store state of the transaction, and thus can't transfer this state to other threads when routing continues asynchronously.

Version:

Method Summary
 void beforeWrap(RouteContext routeContext, ProcessorDefinition<?> definition)
          Hook invoked before the wrap.
 Processor wrap(RouteContext routeContext, Processor processor)
          Wraps any applicable interceptors around the given processor.
 

Method Detail

beforeWrap

void beforeWrap(RouteContext routeContext,
                ProcessorDefinition<?> definition)
Hook invoked before the wrap.

This allows you to do any custom logic before the processor is wrapped. For example to manipulate the definiton

Parameters:
routeContext - the route context
definition - the processor definition

wrap

Processor wrap(RouteContext routeContext,
               Processor processor)
Wraps any applicable interceptors around the given processor.

Parameters:
routeContext - the route context
processor - the processor to be intercepted
Returns:
either the original processor or a processor wrapped in one or more processors


Apache Camel