public class JmxServer extends Object implements Closeable
Constructor and Description |
---|
JmxServer()
Create 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(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(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 that uses an existing MBeanServer.
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
int |
getRegisteredCount()
Number of registered objects.
|
int |
getRegistryPort() |
int |
getServerPort() |
ObjectName |
register(Object obj)
Register the object parameter for exposure with JMX.
|
ObjectName |
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.
|
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 |
register(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.
|
ObjectName |
register(PublishAllBeanWrapper wrapper)
Register the object parameter for exposure with JMX that is wrapped using the PublishAllBeanWrapper.
|
void |
setInetAddress(InetAddress inetAddress)
Not required.
|
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 |
setServerSocketFactory(RMIServerSocketFactory serverSocketFactory)
Optional server socket factory that can will be used to generate our registry and server ports.
|
void |
setServiceUrl(String serviceUrl)
Optional service URL which is used to specify the connection endpoints.
|
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.
|
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.
|
public JmxServer()
setPort(int)
.public JmxServer(int registryPort)
registryPort
- The "RMI registry port" that you specify in jconsole to connect to the server. See
setRegistryPort(int)
.public JmxServer(InetAddress inetAddress, int registryPort)
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. See
setRegistryPort(int)
.public JmxServer(int registryPort, int serverPort)
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)
. The same port as the registry-port can be used.public JmxServer(InetAddress inetAddress, int registryPort, int serverPort)
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. See
setRegistryPort(int)
.serverPort
- The RMI server port that jconsole uses to transfer data to/from the server. See
setServerPort(int)
. The same port as the registry-port can be used.public JmxServer(MBeanServer mbeanServer)
ManagementFactory.getPlatformMBeanServer()
to use the JVM platform's default server.
NOTE: You can also use the JmxServer(boolean)
or setUsePlatformMBeanServer(boolean)
with
true to set the internal MBeanServer to the platform one already defined.
public JmxServer(boolean usePlatformMBeanServer)
ManagementFactory.getPlatformMBeanServer()
which will create one if it doesn't already
exist.public void start() throws JMException
JmxServer(int)
constructor
or the setRegistryPort(int)
method before this is called.IllegalStateException
- If the registry port has not already been set.JMException
public void stop()
stopThrow()
but this ignores any exceptions.public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
public void stopThrow() throws JMException
JMException
public ObjectName register(Object obj) throws JMException
JmxResource
annotation or must implement JmxSelfNaming
.JMException
public void register(Object obj, ObjectName objectName, JmxAttributeFieldInfo[] attributeFieldInfos, JmxAttributeMethodInfo[] attributeMethodInfos, JmxOperationInfo[] operationInfos) throws JMException
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.JMException
public ObjectName register(PublishAllBeanWrapper wrapper) throws JMException
JMException
public ObjectName register(Object obj, JmxResourceInfo resourceInfo, JmxAttributeFieldInfo[] attributeFieldInfos, JmxAttributeMethodInfo[] attributeMethodInfos, JmxOperationInfo[] operationInfos) throws JMException
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.JMException
public void register(Object obj, ObjectName objectName, String description, JmxAttributeFieldInfo[] attributeFieldInfos, JmxAttributeMethodInfo[] attributeMethodInfos, JmxOperationInfo[] operationInfos) throws JMException
obj
- Object that we are registering.objectName
- Name of the object most likely generated by one of the methods from the ObjectNameUtil
class.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.JMException
public void unregister(Object obj)
unregisterThrow(Object)
except this ignores exceptions.public void unregister(ObjectName objName)
unregisterThrow(ObjectName)
except this ignores exceptions.public void unregisterThrow(Object obj) throws JMException
unregister(Object)
if you
want it to be silent.JMException
public void unregisterThrow(ObjectName objName) throws JMException
unregister(Object)
if you want
it to be silent.JMException
public void setInetAddress(InetAddress inetAddress)
public void setPort(int port)
setRegistryPort(int)
.public int getRegistryPort()
setRegistryPort(int)
public void setRegistryPort(int registryPort)
JmxServer(int)
constructor before start()
is called.public int getServerPort()
setServerPort(int)
public void setServerPort(int serverPort)
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 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.public void setServerSocketFactory(RMIServerSocketFactory serverSocketFactory)
public void setServiceUrl(String serviceUrl)
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.
public void setUsePlatformMBeanServer(boolean usePlatformMBeanServer)
public int getRegisteredCount()
This documentation content is licensed by Gray Watson under the Creative Commons Attribution-Share Alike 3.0 License.