com.j256.simplejmx.server
Class JmxServer

java.lang.Object
  extended by com.j256.simplejmx.server.JmxServer

public class JmxServer
extends Object

JMX server which allows classes to publish and un-publish themselves as JMX beans.

Author:
graywatson

Constructor Summary
JmxServer()
          Create a JMX server that will be set with the port using setters.
JmxServer(int registryPort)
          Create a JMX server running on a particular registry-port.
JmxServer(int registryPort, int serverPort)
          Create a JMX server running on a particular registry and server port pair.
JmxServer(MBeanServer mbeanServer)
          Create a JmxServer wrapper around an existing MBeanServer.
 
Method Summary
 void register(Object obj)
          Register the object parameter for exposure with JMX.
 void register(Object obj, ObjectName objectName, JmxAttributeFieldInfo[] attributeFieldInfos, JmxAttributeMethodInfo[] attributeMethodInfos, JmxOperationInfo[] operationInfos)
          Register the object parameter for exposure with JMX with user defined field-attribute, method-attribute, and operation information.
 void setPort(int port)
          This is actually calls setRegistryPort(int).
 void setRegistryPort(int registryPort)
          Set our port number to listen for JMX connections.
 void setServerPort(int serverPort)
          Chances are you should be using setPort(int) or setRegistryPort(int) unless you know what you are doing.
 void start()
          Start our JMX service.
 void stop()
          Same as stopThrow() but this ignores any exceptions.
 void stopThrow()
          Stop the JMX server by closing the connector and unpublishing it from the RMI registry.
 void unregister(Object obj)
          Same as unregisterThrow(Object) except this ignores exceptions.
 void unregister(ObjectName objName)
          Same as unregisterThrow(ObjectName) except this ignores exceptions.
 void unregisterThrow(Object obj)
          Un-register the object parameter from JMX but this throws exceptions.
 void unregisterThrow(ObjectName objName)
          Un-register the object name from JMX but this throws exceptions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JmxServer

public JmxServer()
Create a JMX server that will be set with the port using setters. Used with spring. You must at least specify the port number with setPort(int).


JmxServer

public JmxServer(int registryPort)
Create a JMX server running on a particular registry-port. See setRegistryPort(int).


JmxServer

public JmxServer(int registryPort,
                 int serverPort)
Create a JMX server running on a particular registry and server port pair.

Parameters:
registryPort - The "RMI registry port" that you specify in jconsole to connect to the server. See setRegistryPort(int).
serverPort - The RMI server port that jconsole uses to transfer data to/from the server. See setServerPort(int).

JmxServer

public JmxServer(MBeanServer mbeanServer)
Create a JmxServer wrapper around an existing MBeanServer. You may want to use this with ManagementFactory.getPlatformMBeanServer() to use the JVM platform's default server.

Method Detail

start

public void start()
           throws JMException
Start our JMX service. The port must have already been called either in the JmxServer(int) constructor or the setRegistryPort(int) method before this is called.

Throws:
IllegalStateException - If the registry port has not already been set.
JMException

stop

public void stop()
Same as stopThrow() but this ignores any exceptions.


stopThrow

public void stopThrow()
               throws JMException
Stop the JMX server by closing the connector and unpublishing it from the RMI registry. This throws a JMException on any issues.

Throws:
JMException

register

public void register(Object obj)
              throws JMException
Register the object parameter for exposure with JMX. The object passed in must have a JmxResource annotation or must implement JmxSelfNaming.

Throws:
JMException

register

public void register(Object obj,
                     ObjectName objectName,
                     JmxAttributeFieldInfo[] attributeFieldInfos,
                     JmxAttributeMethodInfo[] attributeMethodInfos,
                     JmxOperationInfo[] operationInfos)
              throws JMException
Register the object parameter for exposure with JMX with user defined field-attribute, method-attribute, and operation information.

Parameters:
obj - Object that we are registering.
objectName - Name of the object most likely generated by one of the methods from the ObjectNameUtil class.
attributeFieldInfos - Array of attribute information for fields that are exposed through reflection. Can be null if none.
attributeMethodInfos - Array of attribute information for fields that are exposed through get/set/is methods.
operationInfos - Array of operation information for methods.
Throws:
JMException

unregister

public void unregister(Object obj)
Same as unregisterThrow(Object) except this ignores exceptions.


unregister

public void unregister(ObjectName objName)
Same as unregisterThrow(ObjectName) except this ignores exceptions.


unregisterThrow

public void unregisterThrow(Object obj)
                     throws JMException
Un-register the object parameter from JMX but this throws exceptions. Use the unregister(Object) if you want it to be silent.

Throws:
JMException

unregisterThrow

public void unregisterThrow(ObjectName objName)
                     throws JMException
Un-register the object name from JMX but this throws exceptions. Use the unregister(Object) if you want it to be silent.

Throws:
JMException

setPort

public void setPort(int port)
This is actually calls setRegistryPort(int).


setRegistryPort

public void setRegistryPort(int registryPort)
Set our port number to listen for JMX connections. This is the "RMI registry port" but it is the port that you specify in jconsole to connect to the server. This must be set either here or in the JmxServer(int) constructor before start() is called.


setServerPort

public void setServerPort(int serverPort)
Chances are you should be using setPort(int) or setRegistryPort(int) unless you know what you are doing. This sets what JMX calls the "RMI server port". By default this does not have to be set and a default value of 1 plus the registry port will be used. When you specify a port number in jconsole this is not the port that should be specified -- see the registry port.



This content is licensed by Gray Watson under the Creative Commons Attribution-Share Alike 3.0 License.