org.jboss.system
abstract public class: InterceptorServiceMBeanSupport [javadoc |
source]
java.lang.Object
org.jboss.mx.util.JBossNotificationBroadcasterSupport
org.jboss.system.ServiceMBeanSupport
org.jboss.system.InterceptorServiceMBeanSupport
All Implemented Interfaces:
InterceptorServiceMBean, org.jboss.kernel.spi.dependency.KernelControllerContextAware, ServiceMBean, MBeanRegistration, NotificationEmitter
Direct Known Subclasses:
SubDeployerInterceptorSupport
Helper class that can be used for writing MBean Services
that dynamically hook-up an Interceptor to other (X)MBeans
that have been configured as Interceptable.
In a nutshell, call attach()/detach() from your
createService()/destroyService() or startService()/stopService()
pair methods to attach/detach an interceptor to the target mbean(s),
then override invoke() to do something with the invocations.
You may also provide your own Interceptor, in which case
you should call attach(Interceptor).
- author:
< - a href="mailto:dimitris@jboss.org">Dimitris Andreadis
- version:
$ - Revision: 57108 $
| Methods from org.jboss.system.ServiceMBeanSupport: |
|---|
|
create, createService, destroy, destroyService, getDeploymentInfo, getLog, getName, getNextNotificationSequenceNumber, getObjectName, getServer, getServiceName, getState, getStateString, jbossInternalCreate, jbossInternalDescription, jbossInternalDestroy, jbossInternalLifecycle, jbossInternalStart, jbossInternalStop, pojoChange, pojoCreate, pojoDestroy, pojoStart, pojoStop, postDeregister, postRegister, preDeregister, preRegister, setKernelControllerContext, start, startService, stop, stopService, unsetKernelControllerContext |
| Method from org.jboss.system.InterceptorServiceMBeanSupport Detail: |
protected void attach() throws Exception {
if (interceptor == null)
{
attach(new XMBeanInterceptor());
}
}
Add our interceptor to the target Interceptables.
Override invoke(Invocation) to handle the calls. |
protected void attach(Interceptor interceptor) throws Exception {
if (interceptor == null)
{
throw new IllegalArgumentException("Null interceptor");
}
// check we haven't attached already
if (this.interceptor != null)
{
throw new IllegalStateException("Interceptor already attached");
}
log.debug("Attaching interceptor: " + interceptor.getName());
// remember the interceptor
this.interceptor = interceptor;
// add the interceptor to the Interceptables; an exception
// will be thrown if any of them is not Interceptable,
// in which case detach() should be called.
if (interceptables != null)
{
Object[] params = new Object[] { interceptor };
String[] signature = new String[] { Interceptor.class.getName() };
for (Iterator i = interceptables.iterator(); i.hasNext(); )
{
ObjectName target = (ObjectName)i.next();
super.server.invoke(target,
DynamicInterceptor.ADD_INTERCEPTOR,
params,
signature);
log.debug("Interceptor attached to: '" + target + "'");
}
}
}
Add the provided interceptor to the target Interceptables. |
protected void detach() {
if (interceptor != null)
{
log.debug("Detaching interceptor: " + interceptor.getName());
if (interceptables != null)
{
Object[] params = new Object[] { interceptor };
String[] signature = new String[] { Interceptor.class.getName() };
for (Iterator i = interceptables.iterator(); i.hasNext(); )
{
ObjectName target = (ObjectName)i.next();
try
{
super.server.invoke(target,
DynamicInterceptor.REMOVE_INTERCEPTOR,
params,
signature);
log.debug("Interceptor detached from: '" + target + "'");
}
catch (Exception e)
{
log.debug("Caught exception while removing interceptor from '" +
target + "'", e);
}
}
}
interceptor = null;
}
}
Remove the interceptor from the target Interceptables |
public List getInterceptables() {
// return a copy
if (interceptables != null)
{
return new ArrayList(interceptables);
}
return null;
}
|
protected Object invoke(Invocation invocation) throws Throwable {
return invokeNext(invocation);
}
|
protected Object invokeNext(Invocation invocation) throws Throwable {
// call the next in the interceptor chain,
// if nobody follows dispatch the call
Interceptor next = invocation.nextInterceptor();
if (next != null)
{
return next.invoke(invocation);
}
else
{
return invocation.dispatch();
}
}
Use this to forward the call |
public void setInterceptables(List interceptables) {
// copy
if (interceptables != null)
{
this.interceptables = new ArrayList(interceptables);
}
}
|