org.jsesoft.mmbi
Class NamedModelMBean

java.lang.Object
  extended by javax.management.modelmbean.RequiredModelMBean
      extended by org.jsesoft.mmbi.NamedModelMBean
All Implemented Interfaces:
javax.management.DynamicMBean, javax.management.MBeanRegistration, javax.management.modelmbean.ModelMBean, javax.management.modelmbean.ModelMBeanNotificationBroadcaster, javax.management.NotificationBroadcaster, javax.management.NotificationEmitter, javax.management.PersistentMBean

public class NamedModelMBean
extends javax.management.modelmbean.RequiredModelMBean

Couples the Model MBean with its ObjectInstance information (eg ObjectName).

This convenience class provides a ModelMBean with attached ObjectInstance information. Especially, it provides the ObjectName.

If the managed resource emits JMX notification (i.e. implements the NotificationEmitter interface, adding and removing Notification listeners is forwarded to the managed resource (which should be done by the RequiredModelMBean).

Example:

 NamedModelMBean mbean = new NamedModelMBean();
 mbean.setModelMBeanInfo( ... );
 mbean.setManagedResource( ..., "ObjectReference");
 ObjectName objectName = new ObjectName( ... );
 MBeanServer server =
     java.lang.management.ManagementFactory.getPlatformMBeanServer();
 mbean.setInstance( server.registerMBean( mbean, objectName ) );
 ...
 server.unregisterMBean( mbean.getName() );
 

Version:
1.0
Author:
JSESoft

Constructor Summary
NamedModelMBean()
          Creates an NamedModelMBean instance from the RequiredModelMBean.
 
Method Summary
 void addNotificationEmitter(javax.management.NotificationEmitter emitter)
          Registers a notification emitter.
 void addNotificationListener(javax.management.NotificationListener listener, javax.management.NotificationFilter filter, java.lang.Object handback)
          
 javax.management.ObjectInstance getInstance()
          Gets the instance attribute.
 java.lang.Object getManagedResource()
          Gets the managed resource.
 javax.management.ObjectName getName()
          Gets the object name.
 void register(javax.management.ObjectName objectName)
          Registers an object at MBean server.
 void removeNotificationListener(javax.management.NotificationListener listener)
          
 void removeNotificationListener(javax.management.NotificationListener listener, javax.management.NotificationFilter filter, java.lang.Object handback)
          
 void sendNotification(javax.management.Notification ntfyObj)
          
 void setInstance(javax.management.ObjectInstance theInstance)
          Sets the instance attribute.
 void setManagedResource(java.lang.Object managed, java.lang.String type)
          
 void unregister()
          Unregisters and object at MBean server.
 
Methods inherited from class javax.management.modelmbean.RequiredModelMBean
addAttributeChangeNotificationListener, getAttribute, getAttributes, getClassLoaderRepository, getMBeanInfo, getNotificationInfo, invoke, load, postDeregister, postRegister, preDeregister, preRegister, removeAttributeChangeNotificationListener, sendAttributeChangeNotification, sendAttributeChangeNotification, sendNotification, setAttribute, setAttributes, setModelMBeanInfo, store
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NamedModelMBean

public NamedModelMBean()
                throws java.lang.Exception
Creates an NamedModelMBean instance from the RequiredModelMBean.

Throws:
java.lang.Exception - if RequiredModelMBean construction fails
Method Detail

setInstance

public void setInstance(javax.management.ObjectInstance theInstance)
Sets the instance attribute.

Parameters:
theInstance - ObjectInstance
See Also:
getInstance()

getInstance

public javax.management.ObjectInstance getInstance()
Gets the instance attribute.

Returns:
the instance value (maybe null)
See Also:
setInstance(javax.management.ObjectInstance)

getName

public javax.management.ObjectName getName()
Gets the object name.

Returns:
the MBean's object name from the instance.

setManagedResource

public void setManagedResource(java.lang.Object managed,
                               java.lang.String type)
                        throws javax.management.MBeanException,
                               javax.management.RuntimeOperationsException,
                               javax.management.InstanceNotFoundException,
                               javax.management.modelmbean.InvalidTargetObjectTypeException

Specified by:
setManagedResource in interface javax.management.modelmbean.ModelMBean
Overrides:
setManagedResource in class javax.management.modelmbean.RequiredModelMBean
Throws:
javax.management.MBeanException
javax.management.RuntimeOperationsException
javax.management.InstanceNotFoundException
javax.management.modelmbean.InvalidTargetObjectTypeException

getManagedResource

public java.lang.Object getManagedResource()
Gets the managed resource.

Returns:
the managed resource

addNotificationEmitter

public void addNotificationEmitter(javax.management.NotificationEmitter emitter)
Registers a notification emitter.

Parameters:
emitter - the emitter to add

addNotificationListener

public void addNotificationListener(javax.management.NotificationListener listener,
                                    javax.management.NotificationFilter filter,
                                    java.lang.Object handback)

Specified by:
addNotificationListener in interface javax.management.NotificationBroadcaster
Overrides:
addNotificationListener in class javax.management.modelmbean.RequiredModelMBean

removeNotificationListener

public void removeNotificationListener(javax.management.NotificationListener listener,
                                       javax.management.NotificationFilter filter,
                                       java.lang.Object handback)
                                throws javax.management.ListenerNotFoundException

Specified by:
removeNotificationListener in interface javax.management.NotificationEmitter
Overrides:
removeNotificationListener in class javax.management.modelmbean.RequiredModelMBean
Throws:
javax.management.ListenerNotFoundException

removeNotificationListener

public void removeNotificationListener(javax.management.NotificationListener listener)
                                throws javax.management.ListenerNotFoundException

Specified by:
removeNotificationListener in interface javax.management.NotificationBroadcaster
Overrides:
removeNotificationListener in class javax.management.modelmbean.RequiredModelMBean
Throws:
javax.management.ListenerNotFoundException

sendNotification

public void sendNotification(javax.management.Notification ntfyObj)
                      throws javax.management.MBeanException,
                             javax.management.RuntimeOperationsException

Specified by:
sendNotification in interface javax.management.modelmbean.ModelMBeanNotificationBroadcaster
Overrides:
sendNotification in class javax.management.modelmbean.RequiredModelMBean
Throws:
javax.management.MBeanException
javax.management.RuntimeOperationsException

register

public void register(javax.management.ObjectName objectName)
              throws javax.management.InstanceAlreadyExistsException,
                     javax.management.MBeanRegistrationException,
                     javax.management.NotCompliantMBeanException
Registers an object at MBean server.

Parameters:
objectName - the object's name
Throws:
javax.management.InstanceAlreadyExistsException - if already registered
javax.management.MBeanRegistrationException - on registration failure
javax.management.NotCompliantMBeanException - if object not compliant

unregister

public void unregister()
                throws javax.management.InstanceNotFoundException,
                       javax.management.MBeanRegistrationException
Unregisters and object at MBean server.

Throws:
javax.management.InstanceNotFoundException - if not registered
javax.management.MBeanRegistrationException - on registration failure


Copyright © 2010 JSESoft. All Rights Reserved.