Interceptors
Being able to intercept the server invocations is a key requirement for 24x7 service accessibility. Intercepting, queuing, or redirecting invocations becomes useful when a service is being restarted or reconfigured as part of its maintenance lifecycle. Sharing generic functionality such as access control, logging, or concurrency control as an interceptor for MBeans lessens the work required to develop individual service implementations.
JBossMX registers each MBean with an invoker and a stack of interceptors that the invocation is passed through (see Figure 2). The invoker object is responsible for managing the interceptors and sending the invocations down the chain of interceptors toward the managed resource. A logging interceptor can therefore be inserted to implement logging for management attribute and operation invocations. A security interceptor can be put in place to check that the originator of the invocation has sufficient access rights for the MBean or one of its attributes or operations. The invoker itself can support the MBean lifecycle services by controlling the entrance to the interceptor stack. When a service is being restarted, an invoker can block and queue incoming invocations until the service is once again available (or the received invocations time out), or redirect the incoming invocations to another MBean instance that's able to service the same requests.
Figure 2 Overview of interceptor architecture in JBossMX.
Readers familiar with JMX model MBeans may recognize the resemblance to how model MBeans separate the management code from the managed resource object. In fact, the model MBean implementation provided by JBossMX is such an invoker, as shown in Figure 2. The JBossMX model MBean implementation implements both the ModelMBean interface and the invoker functionality, fitting itself directly into the design shown in the figure.
Readers familiar with the JBoss application server may be aware that the EJB container contract in JBoss is implemented by setting a stack of interceptors in front of the EJB object. The invocation is passed through the interceptors that enforce the EJB specification functionality. This is a specific instance of the more generic design outlined in this article. The JBoss server, with its JMX-based microkernel architecture, interceptors, and connectors, provides a generic framework for any server-side component, whether it's implementing an existing specification such as the J2EE or goes beyond J2EE, using customized service interceptors. The JMX agent level provides a dynamic and loosely coupled infrastructure that's required for a 24x7 service. In addition, the registered services are accessible to all JMX-compliant management applications.