Class JmxServer
java.lang.Object
com.j256.simplejmx.server.JmxServer
- All Implemented Interfaces:
Closeable, AutoCloseable
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a JMX server that will be set with the port using setters.JmxServer(boolean usePlatformMBeanServer) If you pass in true, this will create a JmxServer that uses the existing JVM platform's MBeanServer.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(InetAddress inetAddress, int registryPort) Create a JMX server running on a particular address and registry-port.JmxServer(InetAddress inetAddress, int registryPort, int serverPort) Create a JMX server running on a particular registry and server port pair.JmxServer(MBeanServer mbeanServer) Create a JmxServer that uses an existing MBeanServer. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()intNumber of registered objects.intintregister(PublishAllBeanWrapper wrapper) Register the object parameter for exposure with JMX that is wrapped using the PublishAllBeanWrapper.Register the object parameter for exposure with JMX.register(Object obj, JmxResourceInfo resourceInfo, JmxAttributeFieldInfo[] attributeFieldInfos, JmxAttributeMethodInfo[] attributeMethodInfos, JmxOperationInfo[] operationInfos) Register the object parameter for exposure with JMX with user defined field-attribute, method-attribute, and operation information.voidregister(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.voidregister(Object obj, ObjectName objectName, String description, JmxAttributeFieldInfo[] attributeFieldInfos, JmxAttributeMethodInfo[] attributeMethodInfos, JmxOperationInfo[] operationInfos) Register the object parameter for exposure with JMX with user defined field-attribute, method-attribute, and operation information.voidsetInetAddress(InetAddress inetAddress) Not required.voidsetPort(int port) This is actually callssetRegistryPort(int).voidsetRegistryPort(int registryPort) Set our port number to listen for JMX connections.voidsetServerPort(int serverPort) Chances are you should be usingsetPort(int)orsetRegistryPort(int)unless you know what you are doing.voidsetServerSocketFactory(RMIServerSocketFactory serverSocketFactory) Optional server socket factory that can will be used to generate our registry and server ports.voidsetServiceUrl(String serviceUrl) Optional service URL which is used to specify the connection endpoints.voidsetUsePlatformMBeanServer(boolean usePlatformMBeanServer) Set this to true (default is false) to have the JmxServer use the MBean server defined by the JVM as opposed to making one itself.voidstart()Start our JMX service.voidstop()Same asstopThrow()but this ignores any exceptions.voidStop the JMX server by closing the connector and unpublishing it from the RMI registry.voidunregister(Object obj) Same asunregisterThrow(Object)except this ignores exceptions.voidunregister(ObjectName objName) Same asunregisterThrow(ObjectName)except this ignores exceptions.voidunregisterThrow(Object obj) Un-register the object parameter from JMX but this throws exceptions.voidunregisterThrow(ObjectName objName) Un-register the object name from JMX but this throws exceptions.
-
Constructor Details
-
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 withsetPort(int). -
JmxServer
public JmxServer(int registryPort) Create a JMX server running on a particular registry-port.- Parameters:
registryPort- The "RMI registry port" that you specify in jconsole to connect to the server. SeesetRegistryPort(int).
-
JmxServer
Create a JMX server running on a particular address and registry-port.- Parameters:
inetAddress- Address to bind to. If you use on the non-address constructors, it will bind to all interfaces.registryPort- The "RMI registry port" that you specify in jconsole to connect to the server. SeesetRegistryPort(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. SeesetRegistryPort(int).serverPort- The RMI server port that jconsole uses to transfer data to/from the server. SeesetServerPort(int). The same port as the registry-port can be used.
-
JmxServer
Create a JMX server running on a particular registry and server port pair.- Parameters:
inetAddress- Address to bind to. If you use on the non-address constructors, it will bind to all interfaces.registryPort- The "RMI registry port" that you specify in jconsole to connect to the server. SeesetRegistryPort(int).serverPort- The RMI server port that jconsole uses to transfer data to/from the server. SeesetServerPort(int). The same port as the registry-port can be used.
-
JmxServer
Create a JmxServer that uses an existing MBeanServer. You may want to use this withManagementFactory.getPlatformMBeanServer()to use the JVM platform's default server.NOTE: You can also use the
JmxServer(boolean)orsetUsePlatformMBeanServer(boolean)with true to set the internal MBeanServer to the platform one already defined. -
JmxServer
public JmxServer(boolean usePlatformMBeanServer) If you pass in true, this will create a JmxServer that uses the existing JVM platform's MBeanServer. This calls through to theManagementFactory.getPlatformMBeanServer()which will create one if it doesn't already exist.
-
-
Method Details
-
start
Start our JMX service. The port must have already been called either in theJmxServer(int)constructor or thesetRegistryPort(int)method before this is called.- Throws:
IllegalStateException- If the registry port has not already been set.JMException
-
stop
public void stop()Same asstopThrow()but this ignores any exceptions. -
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
stopThrow
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
Register the object parameter for exposure with JMX. The object passed in must have aJmxResourceannotation or must implementJmxSelfNaming.- 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 theObjectNameUtilclass.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
-
register
Register the object parameter for exposure with JMX that is wrapped using the PublishAllBeanWrapper.- Throws:
JMException
-
register
public ObjectName register(Object obj, JmxResourceInfo resourceInfo, 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.resourceInfo- Resource information used to build the object-name.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.- Returns:
- Resulting object name.
- Throws:
JMException
-
register
public void register(Object obj, ObjectName objectName, String description, 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 theObjectNameUtilclass.description- Optional description of the object for jconsole debug output. Default is "Information about 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
Same asunregisterThrow(Object)except this ignores exceptions. -
unregister
Same asunregisterThrow(ObjectName)except this ignores exceptions. -
unregisterThrow
Un-register the object parameter from JMX but this throws exceptions. Use theunregister(Object)if you want it to be silent.- Throws:
JMException
-
unregisterThrow
Un-register the object name from JMX but this throws exceptions. Use theunregister(Object)if you want it to be silent.- Throws:
JMException
-
setInetAddress
Not required. Default is to bind to local interfaces. -
setPort
public void setPort(int port) This is actually callssetRegistryPort(int). -
getRegistryPort
public int getRegistryPort()- See Also:
-
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 theJmxServer(int)constructor beforestart()is called. -
getServerPort
public int getServerPort()- See Also:
-
setServerPort
public void setServerPort(int serverPort) Chances are you should be usingsetPort(int)orsetRegistryPort(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 the registry-port will be used also as the server-port. Both the registry and the server can be the same port. When you specify a port number in jconsole this is not the port that should be specified -- see the registry port. -
setServerSocketFactory
Optional server socket factory that can will be used to generate our registry and server ports. This is not necessary if you are specifying addresses or ports. -
setServiceUrl
Optional service URL which is used to specify the connection endpoints. You should not use this if you are setting the address or the ports directly. The format is something like:
service:jmx:rmi://your-server-name:server-port/jndi/rmi://registry-host:registry-port/jmxrmi
your-server-name could be an IP of an interface or just localhost. registry-host can also be an interface IP or blank for localhost.
-
setUsePlatformMBeanServer
public void setUsePlatformMBeanServer(boolean usePlatformMBeanServer) Set this to true (default is false) to have the JmxServer use the MBean server defined by the JVM as opposed to making one itself. -
getRegisteredCount
public int getRegisteredCount()Number of registered objects.
-