org.jmx4odp.j4oNet
Class MBeanServerManager

java.lang.Object
  extended by org.jmx4odp.j4oNet.MBeanServerManager

public class MBeanServerManager
extends java.lang.Object

This is a convience class. It creates an instance of the MBeanServer via a call to MBeanServerFactory.createMBeanServer(), but it keeps a static refernce to the agentId, so you can call this class to get the instance of the MBeanServer that it created.

Author:
Lucas McGegor

Constructor Summary
MBeanServerManager()
          Creates a new instance of MBeanServerManager
 
Method Summary
 java.lang.String getDefaultDomain()
           
 javax.management.MBeanServer getLocalMBeanServer()
          The same as calling getLocalMBeanServer(false);
 javax.management.MBeanServer getLocalMBeanServer(boolean create)
          This will return the MBeanServer created by this class.
 javax.management.ObjectInstance registerObjectToLocalAgent(java.lang.Object object, boolean useHashInName)
          This is a convience method.
 javax.management.ObjectInstance registerObjectToLocalAgent(java.lang.Object object, java.lang.String objectName)
          This is a convience method.
 void releaseMBeanServer()
          removes the reference to the MBeanServer from the factory and blanks out the agentId.
 void setDefaultDomain(java.lang.String s)
          Whenever this object creates a mbean to manage, it will use this JMX Domain by default.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MBeanServerManager

public MBeanServerManager()
Creates a new instance of MBeanServerManager

Method Detail

registerObjectToLocalAgent

public javax.management.ObjectInstance registerObjectToLocalAgent(java.lang.Object object,
                                                                  boolean useHashInName)
                                                           throws javax.management.MBeanException,
                                                                  javax.management.modelmbean.InvalidTargetObjectTypeException,
                                                                  javax.management.InstanceNotFoundException,
                                                                  javax.management.InstanceAlreadyExistsException,
                                                                  javax.management.MBeanRegistrationException,
                                                                  javax.management.NotCompliantMBeanException,
                                                                  javax.management.RuntimeOperationsException,
                                                                  javax.management.MalformedObjectNameException
This is a convience method. It takes the object passed in and uses the ObjectIntrospector to dynamically generate a managing ModelBean which is a proxy to the object. It will use the format "MNGT:class=" + object.getClass().getName()" for the name of the Object. If useHashInName in name is true, it will append "",instance=" + object.hashCode()" This naming format means that any unique instance of an object will get a unique name. But trying to register the same instance twice will result in an InstanceAlreadyExistsException.

Parameters:
object, - the object to wrap in a proxy ModelMBean and register
useHashInName, - append the instance ID. Or just name it after the class itself.
Returns:
ObjectInstance poiting to the proxy ModelMBean
Throws:
javax.management.MBeanException - if the Object cannot be introspected for a proxy ModelMBean
javax.management.InstanceAlreadyExistsException - if there already is an MBean of this ObjectName
javax.management.MBeanRegistrationException - wraps exceptions thrown by the preRegister(), preDeregister() methods of the MBeanRegistration interface.
javax.management.NotCompliantMBeanException - occurs when trying to register an object in the MBean server that is not a JMX compliant MBean.
javax.management.RuntimeOperationsException - thrown in the agent when performing operations on MBeans. It wraps the actual java.lang.RuntimeException thrown.
javax.management.MalformedObjectNameException - This should not be thrown, as this method guantees a good name.
javax.management.modelmbean.InvalidTargetObjectTypeException
javax.management.InstanceNotFoundException

registerObjectToLocalAgent

public javax.management.ObjectInstance registerObjectToLocalAgent(java.lang.Object object,
                                                                  java.lang.String objectName)
                                                           throws javax.management.MBeanException,
                                                                  javax.management.modelmbean.InvalidTargetObjectTypeException,
                                                                  javax.management.InstanceNotFoundException,
                                                                  javax.management.InstanceAlreadyExistsException,
                                                                  javax.management.MBeanRegistrationException,
                                                                  javax.management.NotCompliantMBeanException,
                                                                  javax.management.RuntimeOperationsException,
                                                                  javax.management.MalformedObjectNameException
This is a convience method. It takes the object passed in and uses the ObjectIntrospector to dynamically generate a managing ModelBean which is a proxy to the object. It will use the passed in name as the ObjectName and register the proxy ModelMBean with the local JMX agent.

Parameters:
object, - the object to wrap in a proxy ModelMBean and register
objectName, - the object name to register the object with.
Returns:
ObjectInstance poiting to the proxy ModelMBean
Throws:
javax.management.MBeanException - if the Object cannot be introspected for a proxy ModelMBean
javax.management.InstanceAlreadyExistsException - if there already is an MBean of this ObjectName
javax.management.MBeanRegistrationException - wraps exceptions thrown by the preRegister(), preDeregister() methods of the MBeanRegistration interface.
javax.management.NotCompliantMBeanException - occurs when trying to register an object in the MBean server that is not a JMX compliant MBean.
javax.management.RuntimeOperationsException - thrown in the agent when performing operations on MBeans. It wraps the actual java.lang.RuntimeException thrown.
javax.management.MalformedObjectNameException - if the format of the objectName string does not correspond to a valid ObjectName
javax.management.modelmbean.InvalidTargetObjectTypeException
javax.management.InstanceNotFoundException

getLocalMBeanServer

public javax.management.MBeanServer getLocalMBeanServer()
The same as calling getLocalMBeanServer(false);


getLocalMBeanServer

public javax.management.MBeanServer getLocalMBeanServer(boolean create)
This will return the MBeanServer created by this class. If called with a true, then it will create the MBeanServer is none is found, if set to false it will return a null if the MBeanServer cannot be found. It must be called with a true at least once.


releaseMBeanServer

public void releaseMBeanServer()
                        throws java.lang.Exception
removes the reference to the MBeanServer from the factory and blanks out the agentId.

Throws:
java.lang.Exception

setDefaultDomain

public void setDefaultDomain(java.lang.String s)
Whenever this object creates a mbean to manage, it will use this JMX Domain by default. It is global.


getDefaultDomain

public java.lang.String getDefaultDomain()