org.jmx4odp.dynamicManagement
Class AgentManager

java.lang.Object
  extended by org.jmx4odp.dynamicManagement.AgentManager

public class AgentManager
extends java.lang.Object

This object is a wrapper to MBeanServerFactory. It carries out the following additional behavior:



This object uses the following properties: If these properties are not set in the agent.properties, it will look at system properties. If not found, it will use defaults of 8082 for html and 8083 for rmi. And if the builder is null, it will just use the MBeanServerFactory to handle all requests. It will only start the BaseServer (HTML Adaptor or RMI Connetor) for the default MBeanServer.s So you can create and locate multiple agents via the AgentManager, but only the default will use these ports.

For example, to pass these parameters via environment variables, you would start the JVM with:
java -Djmx.adaptor.html.port=8080 -Djmx.connector.rmi.port=8081 org.jmx4odp.dynamicManagement.AgentManager

To you the AgentManager:
//The static method will dynamically create an ObjectName based upon the object. //It will use the hashCode to make it unique to this instance of the object AgentManager.registerAsMbean(objToInstrument);

To force a specific ObjectName:
// The string must be a legit ObjectName format, else it will throw an exception AgentManager.registerAsMbean(objToInstrument, "domain=default:name=exampleObj");

To use the default domain name:
String on = AgentManager.getDefaultDomain().concat(":name=exampleObj"); AgentManager.registerAsMbean(objToInstrument, on);

Author:
Lucas McGegor
See Also:
MBeanServerFactory

Field Summary
static java.lang.String DEFAULT_DOMAIN
           
static java.lang.String HTML_ADAPTOR_PORT
           
static java.lang.String JMX_MANAGEMENT_BUILDER
           
static java.lang.String RMI_CONNECTOR_PORT
           
 
Constructor Summary
AgentManager()
           
 
Method Summary
static javax.management.MBeanServer createMBeanServer()
          equivalent to createMBeanServer(null)
static javax.management.MBeanServer createMBeanServer(java.lang.String domain)
          Will return an MBeanServer.
static java.util.ArrayList findMBeanServer(java.lang.String agentId)
          return an list of all MBeanServers held by this factory that have this agentID.
static java.lang.String getDefaultDomain()
           
static int getHtmlAdaptorPort()
          Getter for property htmlAdaptorPort.
static javax.management.MBeanServer getMBeanServer()
          Equivalent to createMBeanServer()
static java.lang.String getMngmtBuilderInitial()
          Getter for property mngmtBuilderInitial.
static java.util.Properties getProperties()
           
static int getRmiConnectorPort()
          Getter for property rmiConnectorPort.
static void main(java.lang.String[] args)
           
static javax.management.ObjectInstance registerAsMbean(java.lang.Object futureMbean)
          Will create a unique ObjectName for this object, wrap it in a DynamicMBean, and register it with the default MBS
static javax.management.ObjectInstance registerAsMbean(java.lang.Object futureMbean, javax.management.ObjectName objectName)
          Will wrap this object in a DynamicMBean and register it with the default MBS using the provided ObjectName
static javax.management.ObjectInstance registerAsMbean(java.lang.Object futureMbean, javax.management.ObjectName name, javax.management.MBeanServer mbs)
          Takes an object, wraps it in a model MBean, and registers it with the given MBeanServer.
static javax.management.ObjectInstance registerAsMbean(java.lang.Object futureMbean, java.lang.String objectName)
          Will try to create an ObjectName from the given string, wrap the Object in a DynamicMBean, and then register it with the default MBS.
static void releaseMBeanServer(javax.management.MBeanServer mbs)
          same as MBeanServerFactory.releaseMBeanServer, but it also makes sure to remove default mbean server is needed
static void renableInitialization()
          set the object to be un initialized, so the next time it is invoked, it will re-init any objects.
static void setHtmlAdaptorPort(int p)
          Setter for property htmlAdaptorPort.
static void setMngmtBuilderInitial(java.lang.String str)
          set the name of the class which extends the javax.management.MBeanServerBuilder object.
static void setProperties(java.util.Properties props)
          Set the properties that will be used to init the agent manager and its services
static void setRmiConnectorPort(int p)
          Setter for property rmiConnectorPort.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HTML_ADAPTOR_PORT

public static final java.lang.String HTML_ADAPTOR_PORT
See Also:
Constant Field Values

RMI_CONNECTOR_PORT

public static final java.lang.String RMI_CONNECTOR_PORT
See Also:
Constant Field Values

JMX_MANAGEMENT_BUILDER

public static final java.lang.String JMX_MANAGEMENT_BUILDER
See Also:
Constant Field Values

DEFAULT_DOMAIN

public static final java.lang.String DEFAULT_DOMAIN
See Also:
Constant Field Values
Constructor Detail

AgentManager

public AgentManager()
Method Detail

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Throws:
java.lang.Exception

releaseMBeanServer

public static void releaseMBeanServer(javax.management.MBeanServer mbs)
                               throws java.lang.IllegalArgumentException,
                                      java.lang.SecurityException
same as MBeanServerFactory.releaseMBeanServer, but it also makes sure to remove default mbean server is needed

Throws:
java.lang.IllegalArgumentException
java.lang.SecurityException

getMBeanServer

public static javax.management.MBeanServer getMBeanServer()
                                                   throws java.lang.SecurityException,
                                                          javax.management.JMRuntimeException,
                                                          java.lang.ClassCastException
Equivalent to createMBeanServer()

Throws:
java.lang.SecurityException
javax.management.JMRuntimeException
java.lang.ClassCastException

createMBeanServer

public static javax.management.MBeanServer createMBeanServer()
                                                      throws java.lang.SecurityException,
                                                             javax.management.JMRuntimeException,
                                                             java.lang.ClassCastException
equivalent to createMBeanServer(null)

Throws:
java.lang.SecurityException
javax.management.JMRuntimeException
java.lang.ClassCastException

createMBeanServer

public static javax.management.MBeanServer createMBeanServer(java.lang.String domain)
                                                      throws java.lang.SecurityException,
                                                             javax.management.JMRuntimeException,
                                                             java.lang.ClassCastException
Will return an MBeanServer. The first one that it creates, it will save as the default. As long as the domain is the same, it will keep returning this MBeanServer.

Throws:
java.lang.SecurityException
javax.management.JMRuntimeException
java.lang.ClassCastException

findMBeanServer

public static java.util.ArrayList findMBeanServer(java.lang.String agentId)
                                           throws java.lang.SecurityException
return an list of all MBeanServers held by this factory that have this agentID. If the agentID is null, it should return a list of all the MBeanServers held by this factory

Throws:
java.lang.SecurityException

renableInitialization

public static void renableInitialization()
set the object to be un initialized, so the next time it is invoked, it will re-init any objects. This will use any new properties set since the last init() This will also release the default MBeanServer if it has been created.


registerAsMbean

public static javax.management.ObjectInstance registerAsMbean(java.lang.Object futureMbean)
                                                       throws java.lang.Exception
Will create a unique ObjectName for this object, wrap it in a DynamicMBean, and register it with the default MBS

Throws:
java.lang.Exception

registerAsMbean

public static javax.management.ObjectInstance registerAsMbean(java.lang.Object futureMbean,
                                                              javax.management.ObjectName objectName)
                                                       throws java.lang.Exception
Will wrap this object in a DynamicMBean and register it with the default MBS using the provided ObjectName

Throws:
java.lang.Exception

registerAsMbean

public static javax.management.ObjectInstance registerAsMbean(java.lang.Object futureMbean,
                                                              java.lang.String objectName)
                                                       throws java.lang.Exception
Will try to create an ObjectName from the given string, wrap the Object in a DynamicMBean, and then register it with the default MBS.

Throws:
java.lang.Exception

registerAsMbean

public static javax.management.ObjectInstance registerAsMbean(java.lang.Object futureMbean,
                                                              javax.management.ObjectName name,
                                                              javax.management.MBeanServer mbs)
                                                       throws java.lang.Exception
Takes an object, wraps it in a model MBean, and registers it with the given MBeanServer. If the ObjectName is null, then create one. If the MBean server is null, then use the default one.

Throws:
java.lang.Exception

getHtmlAdaptorPort

public static int getHtmlAdaptorPort()
Getter for property htmlAdaptorPort.

Returns:
Value of property htmlAdaptorPort.

setHtmlAdaptorPort

public static void setHtmlAdaptorPort(int p)
Setter for property htmlAdaptorPort.

Parameters:
htmlAdaptorPort - New value of property htmlAdaptorPort.

getRmiConnectorPort

public static int getRmiConnectorPort()
Getter for property rmiConnectorPort.

Returns:
Value of property rmiConnectorPort.

setRmiConnectorPort

public static void setRmiConnectorPort(int p)
Setter for property rmiConnectorPort.

Parameters:
rmiConnectorPort - New value of property rmiConnectorPort.

getDefaultDomain

public static java.lang.String getDefaultDomain()
Returns:
the defautl domain for xdrv mgmt mbeans

getMngmtBuilderInitial

public static java.lang.String getMngmtBuilderInitial()
Getter for property mngmtBuilderInitial.

Returns:
Value of property mngmtBuilderInitial.

setMngmtBuilderInitial

public static void setMngmtBuilderInitial(java.lang.String str)
set the name of the class which extends the javax.management.MBeanServerBuilder object. This class will be loaded and used to load the MBeanServer. If this is null, it will use the MBeanServerFactory to load whatever MBeanServer it normally will.

Parameters:
mngmtBuilderInitial - New value of property mngmtBuilderInitial.

setProperties

public static void setProperties(java.util.Properties props)
Set the properties that will be used to init the agent manager and its services


getProperties

public static java.util.Properties getProperties()