Interceptors in OpenESB v2.1 will be slightly different from interceptors in Fuji, primarily because Fuji benefits from the modularity and features provided by OSGi.
To provide support for interceptors in OpenESB, there are two main gaps to be filled :
A registry for interceptors, this in memory cache of interceptors will be maintained by the JBI Runtime. This will function similar to the OSGi Service Registry , the services scope being limited to Interceptors.
To provide the JBI runtime with the ability to load service assembly classes
Maintain an in-memory cache of interceptors registered by the JBI Runtime
Provide an API to register/unregister and query interceptor in the cache
This is a transient in-memory cache and is not to be persisted
It should be easy to access the cache from within any module in the runtime.
The com.sun.jbi.EnvironmentContext could have the following two methods :
* Add an interceptor to the interceptor cache
* @param interceptor - the interceptor instance
* @param properties - the interceptor priorities
InterceptorRegistration registerInterceptor(Object interceptor,java.util.Dictionary properties);
* @return an array of InterceptorReference's one for each interceptor in the cache
The EnviromentContext will delegate to a low level InterceptorCache implementation.
The InterceptorRegistration and InterceptorReference are defined along the lines of the OSGi ServiceRegistration and ServiceReference interfaces :
* Handle to a single interceptor instance in the cache.
public interface InterceptorReference
/** @return the interceptor instance */
/** @return the value of the named interceptor property */
Object getProperty(String name);
/** @return a String array of all the property keys defined for the interceptor */
* Interceptor Registration
public interface InterceptorRegistration
/** @return the reference to the registered interceptor */
* Update the interceptor properties.
* @param properties - properties to be updated
void setProperties(java.util.Dictionary properties);
* Unregister the interceptor from the cache
Service Assembly Classloader
When a service assembly is started, the JBI runtime needs to introspect each and every class in the Service Assembly to determine if it has any interceptor methods. If it does, then an instance of the class needs to be registered in the Interceptor Cache along with the interception properties obtained from the @Intercept elements. To be able to introspect the class the runtime would need to load the class first, since the Classloader for the JBI runtime does not have the service assembly in it's class path, a new Service Assembly Classloader is required.
From my preliminary study of how classes are loaded in Open ESB, it appears that I need to do the following :
In the framework code, add new methods to create/get/remove a ServiceAssembly Classloader as follows :
When a Service Assembly is Started the instance DeploymentService will use the Service Assembly Classloader to load the service assembly classes and register the interceptors in the InterceptorCache using the Environment Context.
When a Service Assembly is Shutdown, the instance DeploymentService will unregister all the interceptors pertinent to the service assembly from the interceptor cache.
When the Service Assembly is undeployed the classloader for the service assembly will be destroyed.
Service Assembly Classloader
A new interface ServiceAssemblyClassLoaderFactory will be defined which has the three methods mentioned above for managing the Service Assembly Classloader. An instance of the ServiceAssemblyClassLoaderFactory can be obtained from the runtime Environment context i.e. com.sun.jbi.EnvironmentContext.getServiceAssemblyClassLoaderFactory(). The Deployment Service will use this class loader factory to create the Service Assembly Class Loader on demand.
The attached image shows the class loader hierarchy in the Open ESB runtime.
Interceptors in Open ESB v2.1 do not need to implement the Interceptor interface since :
We do not have interceptors from external bundles
There is no generic Service Registry, but a specific InterceptorCache
There is no requirement for the Interceptor wrapper either.