org.jboss.mx.interceptor
Class AbstractSharedInterceptor

java.lang.Object
  extended by org.jboss.mx.interceptor.AbstractInterceptor
      extended by org.jboss.mx.interceptor.AbstractSharedInterceptor
All Implemented Interfaces:
MBeanRegistration, Interceptor, SharedInterceptor

public abstract class AbstractSharedInterceptor
extends AbstractInterceptor
implements SharedInterceptor

Base class for shared interceptors. This class provides some default method implementations for shared interceptors.

Version:
$Revision: 57200 $
Author:
Juha Lindfors.
See Also:
SharedInterceptor, MBeanInvoker

Field Summary
protected  ObjectName objectName
          Object name of this interceptor.
protected  MBeanServer server
          MBean server reference for shared interceptors.
 
Fields inherited from class org.jboss.mx.interceptor.AbstractInterceptor
isShared, log, name
 
Constructor Summary
AbstractSharedInterceptor()
          Constructs a new shared interceptor instance.
AbstractSharedInterceptor(String name)
          Constructs a new shared interceptor instance with a given name.
 
Method Summary
protected  ObjectName createObjectName()
          Creates an object name for this interceptor.
 void destroy()
          This method is part of the interceptor MBean's registration lifecycle.
 MBeanServer getMBeanServer()
          Returns the interceptor's view to the MBean server it has been registered to.
 ObjectName getObjectName()
          Returns the object name of this shared interceptor.
 void init()
          This method is part of the interceptor MBean's registration lifecycle.
 void postDeregister()
          This method is called by the MBeanServer after deregistration takes place.
 void postRegister(Boolean registrationSuccesful)
          This method is called by the MBeanServer after registration takes place or when registration fails.
 void preDeregister()
          This method is called by the MBeanServer before deregistration takes place.
 ObjectName preRegister(MBeanServer server, ObjectName oname)
          This method is called by the MBeanServer before registration takes place.
 ObjectName register(MBeanServer server)
          Registers the interceptor to the MBean server.
 void setName(String name)
          Shared interceptors allows their name to be set only before they have been registered to the MBean server.
 void start()
          This method is part of the interceptor MBean's registration lifecycle.
 void stop()
          This method is part of the interceptor MBean's registration lifecycle.
 String toString()
          Returns a string representation of this interceptor instance.
 
Methods inherited from class org.jboss.mx.interceptor.AbstractInterceptor
getName, invoke, isShared, setLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jboss.mx.interceptor.Interceptor
getName, invoke, isShared, setLogger
 

Field Detail

server

protected MBeanServer server
MBean server reference for shared interceptors.


objectName

protected ObjectName objectName
Object name of this interceptor. Shared interceptors must always contain a valid object name.

Constructor Detail

AbstractSharedInterceptor

public AbstractSharedInterceptor()
Constructs a new shared interceptor instance. The interceptor is not automatically registered to the MBean server. Notice that the interceptor name must be set before the call to register(javax.management.MBeanServer) method. Shared interceptor names must be unique within the MBean server.


AbstractSharedInterceptor

public AbstractSharedInterceptor(String name)
Constructs a new shared interceptor instance with a given name. The interceptor is not automatically registered to the MBean server. Notice that the shared interceptor name must be unique name among all shared interceptors within the MBean server.

Parameters:
name - name of this interceptor
Throws:
IllegalArgumentException - if name contains null reference
Method Detail

getObjectName

public ObjectName getObjectName()
Description copied from interface: SharedInterceptor
Returns the object name of this shared interceptor.

Specified by:
getObjectName in interface SharedInterceptor
Returns:
interceptor's object name

getMBeanServer

public MBeanServer getMBeanServer()
Description copied from interface: SharedInterceptor
Returns the interceptor's view to the MBean server it has been registered to.

Specified by:
getMBeanServer in interface SharedInterceptor
Returns:
interceptor's view to its MBean server

register

public ObjectName register(MBeanServer server)
                    throws InterceptorNameConflictException
Registers the interceptor to the MBean server.

The interceptor is registered under the JBOSSMX_DOMAIN name. An interceptor's object name contains a type property and a name property. Property type always contains string 'Interceptor' as its value. Interceptor's name is used as a value for the name property. Therefore, an interceptor created with name 'Bart' can be found from the MBean server under object name:


    JBOSSMX_DOMAIN:type=Interceptor,name=Bart,*

 
If the log reference has not been set for this interceptor when it is registered, this implementation will register a log MBean via the system log manager under JBOSSMX domain (see SystemLogManager for details). The log instance's name will match the pattern:

    "JBossMX.Interceptor.<interceptor name>"

 

Specified by:
register in interface SharedInterceptor
Parameters:
server - MBean server where this shared interceptor is registered
Returns:
the object name of the registered interceptor
Throws:
InterceptorNameConflictException - if an interceptor was already registered to the given server

init

public void init()
          throws Exception
This method is part of the interceptor MBean's registration lifecycle. It is called before the MBean is registered to the server. Concrete interceptor implementations can override this method to provide initialization code that should be executed before the interceptor is registered.

Any exception that is propagated from this method to its caller will cancel the interceptor registration.

Specified by:
init in interface Interceptor
Overrides:
init in class AbstractInterceptor
Throws:
Exception - if you want to cancel the interceptor registration

start

public void start()
This method is part of the interceptor MBean's registration lifecycle. It is called after the MBean is registered to the server. Concrete interceptor implementations can override this method to provide initialization code that should be executed once the MBean server and object name references for this interceptor have been resolved.

Specified by:
start in interface Interceptor
Overrides:
start in class AbstractInterceptor

stop

public void stop()
          throws Exception
This method is part of the interceptor MBean's registration lifecycle. It is called before the MBean is unregistered from the server. Concrete interceptor implementations can override this method to provide cleanup code that should be executed before the interceptor is unregistered.

Any exception that is propagated from this method to its caller will cancel the interceptor unregistration.

Specified by:
stop in interface Interceptor
Overrides:
stop in class AbstractInterceptor
Throws:
Exception - if you want to cancel the interceptor unregistration

destroy

public void destroy()
This method is part of the interceptor MBean's registration lifecycle. It is called after the MBean has been unregistered from the server. Concrete interceptor implementations can override this method to provide cleanup code that should be executed once the interceptor is no longer registered to the MBean server.

Specified by:
destroy in interface Interceptor
Overrides:
destroy in class AbstractInterceptor

preRegister

public ObjectName preRegister(MBeanServer server,
                              ObjectName oname)
                       throws Exception
Description copied from interface: MBeanRegistration
This method is called by the MBeanServer before registration takes place. The MBean is passed a reference of the MBeanServer it is about to be registered with. The MBean must return the ObjectName it will be registered with. The MBeanServer can pass a suggested object depending upon how the MBean is registered.

The MBean can stop the registration by throwing an exception.The exception is forwarded to the invoker wrapped in an MBeanRegistrationException.

Specified by:
preRegister in interface MBeanRegistration
Returns:
the actual ObjectName to register this MBean with.
Throws:
Exception - for any error, the MBean is not registered.

postRegister

public void postRegister(Boolean registrationSuccesful)
Description copied from interface: MBeanRegistration
This method is called by the MBeanServer after registration takes place or when registration fails.

Specified by:
postRegister in interface MBeanRegistration
Parameters:
registrationSuccesful - the MBeanServer passes true when the MBean was registered, false otherwise.

preDeregister

public void preDeregister()
                   throws Exception
Description copied from interface: MBeanRegistration
This method is called by the MBeanServer before deregistration takes place.

The MBean can throw an exception, this will stop the deregistration. The exception is forwarded to the invoker wrapped in an MBeanRegistrationException.

Specified by:
preDeregister in interface MBeanRegistration
Throws:
Exception

postDeregister

public void postDeregister()
Description copied from interface: MBeanRegistration
This method is called by the MBeanServer after deregistration takes place.

Specified by:
postDeregister in interface MBeanRegistration

setName

public void setName(String name)
Shared interceptors allows their name to be set only before they have been registered to the MBean server. After that the name is fixed and any attempt to invoke this method to change the name will yield a IllegalArgumentException.

Overrides:
setName in class AbstractInterceptor
Parameters:
name - name of this shared interceptor
Throws:
IllegalArgumentException - if there was an attempt to change the name after the interceptor had been registered to the server

toString

public String toString()
Returns a string representation of this interceptor instance.

Overrides:
toString in class AbstractInterceptor
Returns:
string representation

createObjectName

protected ObjectName createObjectName()
                               throws MalformedObjectNameException
Creates an object name for this interceptor. The object name contains a type property and a name property. Property type always contains string 'Interceptor' as its value. Interceptor's name is used as a value for the name property. Therefore, an interceptor created with name 'Bart' will generate an object name matching to pattern:

    JBOSSMX_DOMAIN:type=Interceptor,name=Bart,*

 

Returns:
generated object name for this interceptor
Throws:
MalformedObjectNameException - if the object name could not be created


Copyright © 2002 JBoss Group, LLC. All Rights Reserved.