org.sape.carbon.services.management.interceptor
Class DefaultManagementInterceptorImpl

java.lang.Object
  |
  +--javax.management.NotificationBroadcasterSupport
        |
        +--org.sape.carbon.services.management.interceptor.DefaultManagementInterceptorImpl
All Implemented Interfaces:
Decorator, javax.management.DynamicMBean, EventManager, Interceptor, ManagementInterceptor, javax.management.NotificationBroadcaster

public class DefaultManagementInterceptorImpl
extends javax.management.NotificationBroadcasterSupport
implements ManagementInterceptor, Interceptor, EventManager

This is an interceptor implementation that provides JMX integration for Carbon Components. It handles the DynamicMBean interface's methods and provides an XML based storage mechanism for MBeanInfo configurations.

To configure this interceptor add the following to a component template configuration:
  <!-- The JMX Assistant -->
  <DecoratorConfiguration>
     <Factory>
         org.sape.carbon.services.management.interceptor.ManagementInterceptorFactory
     </Factory>
     <CustomConfiguration
          ConfigurationInterface="org.sape.carbon.services.management.interceptor.ManagementInterceptorConfiguration">

         <MBeanServerServiceLocation>/manage/DefaultMBeanServer</MBeanServerServiceLocation>
         <SendNotifications>true</SendNotifications>
     </CustomConfiguration>
  </DecoratorConfiguration>
 
Copyright 2002 Sapient

Since:
carbon 1.0
Version:
$Revision: 1.13 $($Author: dvoet $ / $Date: 2003/05/05 21:21:33 $)
Author:
Greg Hinkle, March 2002

Nested Class Summary
static class DefaultManagementInterceptorImpl.MBeanFeatureInfoComparator
          This comporator may be used to order all types of MBeanFeatureInfo objects by name.
 
Field Summary
protected  Component component
          A reference to the component that is being monitored by this interceptor.
private  Class componentFunctionalInterface
          Holds the component functional interface.
private  ManagementInterceptorConfiguration config
          Holds the configuration of the interceptor.
private  org.apache.commons.logging.Log log
          Provides a handle to Apache-commons logger
protected  javax.management.MBeanInfo mBeanInfo
          A cached copy of the MBeanInfo for this registered component.
private  String mbeanServerServiceName
          Name of the mbean server service.
static String METADATA_CONFIG_LOCATION
          Config location of the management information classes.
protected  Interceptor nextInterceptor
          The next interceptor in the chain
private  long notificationSequence
          This long tracks the next sequence number to send in a notification
protected  javax.management.ObjectName objectName
          The ObjectName of the registered component.
private static String PROPERTY_ENVIRONMENT
          Key to the environment of the MBean.
private static String PROPERTY_INSTANCE
          Key to the instance of the MBean.
private static String PROPERTY_NAME
          Key to the name of the MBean.
private static String PROPERTY_TYPE
          Key to the type of the MBean.
private static String PROPERTY_VMID
          Key to the virtual machine id of the MBean.
private  boolean shouldSendNotifications
          Indicates if this should send notifications.
private static String UNIQUE_ID
          Key to the unique id of the MBean.
 
Fields inherited from class javax.management.NotificationBroadcasterSupport
 
Constructor Summary
DefaultManagementInterceptorImpl(ManagementInterceptorConfiguration config, Class componentFunctionalInterface)
          Constructs a ManagementInterceptor that can act as the DynamicMBean Implementation for a component.
 
Method Summary
private  void addConfigurationAttributes(Class configurationClass, List attributesSet)
          Introspects on the class type of a configuration in order to define the MBeanInfo metadata about it.
protected  javax.management.MBeanInfo buildMBeanInfo(Component component)
          This method essentially aggregates all MBean Information about each interface that a component implements into a single MBeanInfo object.
 Object getAttribute(String attribute)
          Obtains the value of a specific attribute of the Dynamic MBean.
 javax.management.AttributeList getAttributes(String[] attributes)
          Enables the values of several attributes of the Dynamic MBean.
 Class getComponentType()
          Gets the class of this component.
 Class[] getExposedInterfaces()
          This should return the list of interfaces that a decorator wishes to expose through the component proxy.
 javax.management.MBeanInfo getMBeanInfo()
          This method returns the MBeanInfo object representing the managable interfaces that are exposed by the Component being assisted.
 Object invoke(Invocation invocation)
          Intercepts calls to the LifecycleInterceptor interface in order to handle deregistering the MBean from the MBeanServer when the component is destroyed.
 Object invoke(String actionName, Object[] params, String[] signature)
          Handles the invocation of operations on the component represented by this MBean Assistant.
private  javax.management.MBeanParameterInfo[] loadParameters(MBeanInfoConfiguration.MBeanParameterInfoConfiguration[] config)
          Loads an array ParameterInfoConfiguration into a JMX ParameterInfo.
 void sendEvent(ComponentEvent componentEvent)
          Sends the supplied event to any listeners who may be listening for events on the managed component.
 void setAttribute(javax.management.Attribute attribute)
          Sets the value of a specific attribute of the Dynamic MBean
 javax.management.AttributeList setAttributes(javax.management.AttributeList attributeList)
          Sets as many attributes as it can from the provided list and returns a list of the attributes that were successfully set.
 void setComponentReference(Component component)
          Called after creation to pass a reference to the component to each of its assistants.
 void setNextInterceptor(Interceptor interceptor)
          This method sets the next interceptor as the next in the chain from the current interceptor.
 
Methods inherited from class javax.management.NotificationBroadcasterSupport
addNotificationListener, getNotificationInfo, removeNotificationListener, sendNotification
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private org.apache.commons.logging.Log log
Provides a handle to Apache-commons logger


notificationSequence

private long notificationSequence
This long tracks the next sequence number to send in a notification


component

protected Component component
A reference to the component that is being monitored by this interceptor.


objectName

protected javax.management.ObjectName objectName
The ObjectName of the registered component. This ObjectName is how a component's MBean would be found via JMX.


mBeanInfo

protected javax.management.MBeanInfo mBeanInfo
A cached copy of the MBeanInfo for this registered component. Because Components are constructed from multiple sub-assistants and the Configuration Assistant may be dynamically mapped, we cache the process to improve speed.


nextInterceptor

protected Interceptor nextInterceptor
The next interceptor in the chain


PROPERTY_NAME

private static final String PROPERTY_NAME
Key to the name of the MBean.

See Also:
Constant Field Values

PROPERTY_TYPE

private static final String PROPERTY_TYPE
Key to the type of the MBean.

See Also:
Constant Field Values

PROPERTY_ENVIRONMENT

private static final String PROPERTY_ENVIRONMENT
Key to the environment of the MBean.

See Also:
Constant Field Values

PROPERTY_INSTANCE

private static final String PROPERTY_INSTANCE
Key to the instance of the MBean.

See Also:
Constant Field Values

PROPERTY_VMID

private static final String PROPERTY_VMID
Key to the virtual machine id of the MBean.

See Also:
Constant Field Values

UNIQUE_ID

private static final String UNIQUE_ID
Key to the unique id of the MBean.


mbeanServerServiceName

private String mbeanServerServiceName
Name of the mbean server service.


shouldSendNotifications

private boolean shouldSendNotifications
Indicates if this should send notifications.


config

private ManagementInterceptorConfiguration config
Holds the configuration of the interceptor.


componentFunctionalInterface

private Class componentFunctionalInterface
Holds the component functional interface.


METADATA_CONFIG_LOCATION

public static final String METADATA_CONFIG_LOCATION
Config location of the management information classes.

See Also:
Constant Field Values
Constructor Detail

DefaultManagementInterceptorImpl

public DefaultManagementInterceptorImpl(ManagementInterceptorConfiguration config,
                                        Class componentFunctionalInterface)
Constructs a ManagementInterceptor that can act as the DynamicMBean Implementation for a component.

Parameters:
config - the configuration for a management interceptor
componentFunctionalInterface - the functional interface to the component
Method Detail

setNextInterceptor

public void setNextInterceptor(Interceptor interceptor)
This method sets the next interceptor as the next in the chain from the current interceptor.

Specified by:
setNextInterceptor in interface Interceptor
Parameters:
interceptor - the next interceptor in the chain

getAttribute

public Object getAttribute(String attribute)
                    throws javax.management.AttributeNotFoundException,
                           javax.management.MBeanException,
                           javax.management.ReflectionException
Obtains the value of a specific attribute of the Dynamic MBean.

Specified by:
getAttribute in interface javax.management.DynamicMBean
Parameters:
attribute - The name of the attribute to be retrieved
Returns:
The value of the attribute retrieved.
Throws:
javax.management.AttributeNotFoundException - Thrown when the specified attribute is not available
javax.management.MBeanException - Wraps a java.lang.Exception thrown by the MBean's getter.
javax.management.ReflectionException - Wraps a java.lang.Exception thrown while trying to invoke the getter.

getAttributes

public javax.management.AttributeList getAttributes(String[] attributes)
Enables the values of several attributes of the Dynamic MBean.

Specified by:
getAttributes in interface javax.management.DynamicMBean
Parameters:
attributes - an array of string attributes to be retrieved.
Returns:
The list of attributes retrieved.

getMBeanInfo

public javax.management.MBeanInfo getMBeanInfo()

This method returns the MBeanInfo object representing the managable interfaces that are exposed by the Component being assisted. This metadata will include information about all manageable roles that this component has been configured to play.

Specified by:
getMBeanInfo in interface javax.management.DynamicMBean
Returns:
the MBeanInfo representing this component's manageability

getComponentType

public Class getComponentType()
Gets the class of this component.

Specified by:
getComponentType in interface ManagementInterceptor
Returns:
class of this component

buildMBeanInfo

protected javax.management.MBeanInfo buildMBeanInfo(Component component)

This method essentially aggregates all MBean Information about each interface that a component implements into a single MBeanInfo object. This is done by loading configuration documents for each interface that implement a set of configuration versions of the various Info metadata objects. These objects are then read in to their MBeanInfo metadata counterparts and aggregated into big lists. Then the final step is to place them into one large MBeanInfo object and return them.

By aggregating the supported management interface for any number of roles that the component can handle we can give a JMX console user the full power of Carbon's generic delegation and configuratively additive functionality.

Parameters:
component - the Component that is being represented by this ManagementInterceptor
Returns:
the MBeanInfo object representing the supported management methods exposed by this configuration of this component.

addConfigurationAttributes

private void addConfigurationAttributes(Class configurationClass,
                                        List attributesSet)
Introspects on the class type of a configuration in order to define the MBeanInfo metadata about it. Configuration interfaces are strictly Java Interfaces that adhere to the Bean standard for attributes and therefore only have attributes.

Parameters:
configurationClass - the Class type to construct metadata for
attributesSet - the set of attributes that will be added to for each attribute in the supplied configuration.

loadParameters

private javax.management.MBeanParameterInfo[] loadParameters(MBeanInfoConfiguration.MBeanParameterInfoConfiguration[] config)

Loads an array ParameterInfoConfiguration into a JMX ParameterInfo.

Parameters:
config - the array of parameter info configurations to be translated into the strictly JMX MBeanParameterInfo objects.
Returns:
an array of MBeanParameterInfo objects.

getExposedInterfaces

public Class[] getExposedInterfaces()
This should return the list of interfaces that a decorator wishes to expose through the component proxy. This is used by the component factory to determine what interfaces the component proxy will implement.

Specified by:
getExposedInterfaces in interface Decorator
Returns:
Class[] an array of interfaces

invoke

public Object invoke(String actionName,
                     Object[] params,
                     String[] signature)
              throws javax.management.MBeanException,
                     javax.management.ReflectionException

Handles the invocation of operations on the component represented by this MBean Assistant.

Specified by:
invoke in interface javax.management.DynamicMBean
Parameters:
actionName - The name of the action to be invoked.
params - An array containing the parameters to be set when the action is invoked.
signature - An array containing the signature of the action. The class objects will be loaded through the same class loader as the one used for loading the MBean on which the action is invoked.
Returns:
The object returned by the action, which represents the result of invoking the action on the MBean specified.
Throws:
javax.management.MBeanException - Wraps a java.lang.Exception thrown by the MBean's invoked method.
javax.management.ReflectionException - Wraps an exception during reflection

setAttribute

public void setAttribute(javax.management.Attribute attribute)
                  throws javax.management.AttributeNotFoundException,
                         javax.management.InvalidAttributeValueException,
                         javax.management.MBeanException,
                         javax.management.ReflectionException
Sets the value of a specific attribute of the Dynamic MBean

Specified by:
setAttribute in interface javax.management.DynamicMBean
Parameters:
attribute - The identification of the attribute to be set and the value it is to be set to.
Throws:
javax.management.AttributeNotFoundException - Thrown when the specified attribute is not found
javax.management.InvalidAttributeValueException - Thrown when the value that is being set was not valid for the attribute
javax.management.MBeanException - Wraps a java.lang.Exception thrown by the MBean's setter.
javax.management.ReflectionException - Wraps a java.lang.Exception thrown while trying to invoke the MBean's setter.

setAttributes

public javax.management.AttributeList setAttributes(javax.management.AttributeList attributeList)
Sets as many attributes as it can from the provided list and returns a list of the attributes that were successfully set. Those that failed to be set will not be in the return list.

Specified by:
setAttributes in interface javax.management.DynamicMBean
Parameters:
attributeList - the list of attributes to set.
Returns:
the list of attributes that were successfully set.

setComponentReference

public void setComponentReference(Component component)
Called after creation to pass a reference to the component to each of its assistants.

Specified by:
setComponentReference in interface Decorator
Parameters:
component - a reference to the component that this interceptor is assisting

invoke

public Object invoke(Invocation invocation)
              throws Throwable
Intercepts calls to the LifecycleInterceptor interface in order to handle deregistering the MBean from the MBeanServer when the component is destroyed.

Specified by:
invoke in interface Interceptor
Parameters:
invocation - the invocation to execute
Returns:
the results of the invocation's execution
Throws:
Throwable - indicates an error in the invokation chain

sendEvent

public void sendEvent(ComponentEvent componentEvent)
Sends the supplied event to any listeners who may be listening for events on the managed component. Will only send events when configured to send them in the ComponentTemplate.

Specified by:
sendEvent in interface EventManager
Parameters:
componentEvent - The event that occured on the component.


Copyright 1999-2003 Sapient Corporation. All Rights Reserved.