Tuscany phase-based interceptor ordering
As of today, we can add multiple interceptors to the invocation chain, but
we cannot control their ordering. When more policies are supported, I see a
need to provide some simple ordering mechnisim for interceptors. There are a few examples:
1) binding/implementation invokers have to be the last one in the invocation chain.
2) for a service wire, service-level policy handlers (such as propategate/suspend transaction) must be called before implementation-level
handlers (such as managed/noManagedTransaction, security run-as).
3) if I add a encryption/decryption policy handler, it needs to be invoked after the data transformation interceptor on the client side, and before the
data transformation interceptor on the service side.
4) pass-by-value interceptor (if required) should be invoked before the implementation-invoker.
SCA invocation may have three stages: reference, service and implementation.
For example, a typical invocation chain for the reference side can be:
- reference: (SourceComponent) --> DataTransformation --> Suspend/PropagateTransaction --> ReferenceBindingInvoker --> ...
- service: (ServiceBindingListener) --> DataTransformation --> PropagateTransaction
- implementation: ManagedTransaction --> ImplementationInvoker --> (TargetComponent)
We introduce a phase concept which groups a collection of interceptors to a
relative position in the invocation chain for each stage. There are a list
of system defined phases (such as reference.invoker or
implementation.invoker) and it can be extended by Tuscany extensions.
Each phase is uniquely identied by the name. Each phase can define its
relative ordering using the 'before' and/or 'after' attributes. When an
interceptor is added to the InvocationChain, we can specify a phase name.
The Tuscany runtime will sort the phases by the partial order. SCA
invocations will be dispatched in the order of phases. There is no ordering
between interceptors in the same phase.
To define a phase, we use the following simple syntax in the service provider file named as "META-INF/services/org.apache.tuscany.sca.invocation.Phase".
name=PhaseName, stage=stageName, before=PhaseName4 PhaseName5, after=PhaseName3
- name: The name of the phase
- stage: The stage of the phase, it can be one of the values: reference, service, or implemention
- before: A list of phase names separated by spaces to denote this phase should be placed before
- after: A list of phase names separated by spaces to denote this phase should be placed after
A special phase name '*' can be used for 'before' and 'after' attribute to represent all phases.