com.j256.simplejmx.client
Class JmxClient

java.lang.Object
  extended by com.j256.simplejmx.client.JmxClient

public class JmxClient
extends Object

JMX client connection implementation which connects to a JMX server and gets JMX information, gets/sets attributes, and invokes operations.

Author:
graywatson

Constructor Summary
JmxClient(int localPort)
          Connect the client to the local host at a certain port number.
JmxClient(String jmxUrl)
          Connect the client to a JMX server using the full JMX URL format.
JmxClient(String hostName, int port)
          Connect the client to a host and port combination.
JmxClient(String jmxUrl, String userName, String password)
          Connect the client to a JMX server using the full JMX URL format with username/password credentials.
 
Method Summary
 void close()
          Close the client connection to the mbean server.If you want a method that throws then use closeThrow().
 void closeThrow()
          Close the client connection to the mbean server.
static String generalJmxUrlForHostNamePort(String hostName, int port)
          Returns a JMX/RMI URL for a host-name and port.
 Object getAttribute(ObjectName name, String attributeName)
          Return the value of a JMX attribute.
 Object getAttribute(String domain, String beanName, String attributeName)
          Return the value of a JMX attribute.
 MBeanAttributeInfo getAttributeInfo(ObjectName name, String attrName)
          Return information for a particular attribute name.
 List<Attribute> getAttributes(ObjectName name, String[] attributes)
          Get multiple attributes at once from the server.
 List<Attribute> getAttributes(String domain, String beanName, String[] attributes)
          Get multiple attributes at once from the server.
 MBeanAttributeInfo[] getAttributesInfo(ObjectName name)
          Return an array of the attributes associated with the bean name.
 MBeanAttributeInfo[] getAttributesInfo(String domainName, String beanName)
          Return an array of the attributes associated with the bean name.
 String getAttributeString(ObjectName name, String attributeName)
          Return the value of a JMX attribute as a String or null if attribute has a null value.
 String getAttributeString(String domain, String beanName, String attributeName)
          Return the value of a JMX attribute as a String.
 String[] getBeanDomains()
          Return an array of the bean's domain names.
 Set<ObjectName> getBeanNames()
          Return a set of the various bean ObjectName objects associated with the Jmx server.
 Set<ObjectName> getBeanNames(String domain)
          Return a set of the various bean ObjectName objects associated with the Jmx server.
 MBeanOperationInfo getOperationInfo(ObjectName name, String oper)
          Return an array of the operations associated with the bean name.
 MBeanOperationInfo[] getOperationsInfo(ObjectName name)
          Return an array of the operations associated with the bean name.
 MBeanOperationInfo[] getOperationsInfo(String domainName, String beanName)
          Return an array of the operations associated with the bean name.
 Object invokeOperation(ObjectName objectName, String operName, Object... params)
          Invoke a JMX method as an array of objects.
 Object invokeOperation(ObjectName name, String operName, String... paramStrings)
          Invoke a JMX method as an array of parameter strings.
 Object invokeOperation(String domain, String beanName, String operName, Object... params)
          Invoke a JMX method as an array of objects.
 Object invokeOperation(String domain, String beanName, String operName, String... paramStrings)
          Invoke a JMX method with a domain/object-name as an array of parameter strings.
 String invokeOperationToString(ObjectName name, String operName, String... paramStrings)
          Invoke a JMX method as an array of parameter strings.
 void setAttribute(ObjectName name, String attrName, Object value)
          Set the JMX attribute to a particular value.
 void setAttribute(ObjectName name, String attrName, String value)
          Set the JMX attribute to a particular value string.
 void setAttribute(String domainName, String beanName, String attrName, Object value)
          Set the JMX attribute to a particular value string.
 void setAttribute(String domainName, String beanName, String attrName, String value)
          Set the JMX attribute to a particular value string.
 void setAttributes(ObjectName name, List<Attribute> attributes)
          Set a multiple attributes at once on the server.
 void setAttributes(String domainName, String beanName, List<Attribute> attributes)
          Set a multiple attributes at once on the server.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JmxClient

public JmxClient(String jmxUrl)
          throws JMException
Connect the client to a JMX server using the full JMX URL format. The URL should look something like:

 service:jmx:rmi:///jndi/rmi://hostName:portNumber/jmxrmi
 

Throws:
JMException

JmxClient

public JmxClient(String jmxUrl,
                 String userName,
                 String password)
          throws JMException
Connect the client to a JMX server using the full JMX URL format with username/password credentials. The URL should look something like:

 service:jmx:rmi:///jndi/rmi://hostName:portNumber/jmxrmi
 

Throws:
JMException

JmxClient

public JmxClient(int localPort)
          throws JMException
Connect the client to the local host at a certain port number.

Throws:
JMException

JmxClient

public JmxClient(String hostName,
                 int port)
          throws JMException
Connect the client to a host and port combination.

Throws:
JMException
Method Detail

generalJmxUrlForHostNamePort

public static String generalJmxUrlForHostNamePort(String hostName,
                                                  int port)
Returns a JMX/RMI URL for a host-name and port.


close

public void close()
Close the client connection to the mbean server.If you want a method that throws then use closeThrow().


closeThrow

public void closeThrow()
                throws JMException
Close the client connection to the mbean server. If you want a method that does not throw then use close().

Throws:
JMException

getBeanDomains

public String[] getBeanDomains()
                        throws JMException
Return an array of the bean's domain names.

Throws:
JMException

getBeanNames

public Set<ObjectName> getBeanNames()
                             throws JMException
Return a set of the various bean ObjectName objects associated with the Jmx server.

Throws:
JMException

getBeanNames

public Set<ObjectName> getBeanNames(String domain)
                             throws JMException
Return a set of the various bean ObjectName objects associated with the Jmx server.

Throws:
JMException

getAttributesInfo

public MBeanAttributeInfo[] getAttributesInfo(String domainName,
                                              String beanName)
                                       throws JMException
Return an array of the attributes associated with the bean name.

Throws:
JMException

getAttributesInfo

public MBeanAttributeInfo[] getAttributesInfo(ObjectName name)
                                       throws JMException
Return an array of the attributes associated with the bean name.

Throws:
JMException

getAttributeInfo

public MBeanAttributeInfo getAttributeInfo(ObjectName name,
                                           String attrName)
                                    throws JMException
Return information for a particular attribute name.

Throws:
JMException

getOperationsInfo

public MBeanOperationInfo[] getOperationsInfo(String domainName,
                                              String beanName)
                                       throws JMException
Return an array of the operations associated with the bean name.

Throws:
JMException

getOperationsInfo

public MBeanOperationInfo[] getOperationsInfo(ObjectName name)
                                       throws JMException
Return an array of the operations associated with the bean name.

Throws:
JMException

getOperationInfo

public MBeanOperationInfo getOperationInfo(ObjectName name,
                                           String oper)
                                    throws JMException
Return an array of the operations associated with the bean name.

Throws:
JMException

getAttribute

public Object getAttribute(String domain,
                           String beanName,
                           String attributeName)
                    throws Exception
Return the value of a JMX attribute.

Throws:
Exception

getAttribute

public Object getAttribute(ObjectName name,
                           String attributeName)
                    throws Exception
Return the value of a JMX attribute.

Throws:
Exception

getAttributeString

public String getAttributeString(String domain,
                                 String beanName,
                                 String attributeName)
                          throws Exception
Return the value of a JMX attribute as a String.

Throws:
Exception

getAttributeString

public String getAttributeString(ObjectName name,
                                 String attributeName)
                          throws Exception
Return the value of a JMX attribute as a String or null if attribute has a null value.

Throws:
Exception

getAttributes

public List<Attribute> getAttributes(ObjectName name,
                                     String[] attributes)
                              throws Exception
Get multiple attributes at once from the server.

Throws:
Exception

getAttributes

public List<Attribute> getAttributes(String domain,
                                     String beanName,
                                     String[] attributes)
                              throws Exception
Get multiple attributes at once from the server.

Throws:
Exception

setAttribute

public void setAttribute(String domainName,
                         String beanName,
                         String attrName,
                         String value)
                  throws Exception
Set the JMX attribute to a particular value string.

Throws:
Exception

setAttribute

public void setAttribute(ObjectName name,
                         String attrName,
                         String value)
                  throws Exception
Set the JMX attribute to a particular value string.

Throws:
Exception

setAttribute

public void setAttribute(String domainName,
                         String beanName,
                         String attrName,
                         Object value)
                  throws Exception
Set the JMX attribute to a particular value string.

Throws:
Exception

setAttribute

public void setAttribute(ObjectName name,
                         String attrName,
                         Object value)
                  throws Exception
Set the JMX attribute to a particular value.

Throws:
Exception

setAttributes

public void setAttributes(ObjectName name,
                          List<Attribute> attributes)
                   throws Exception
Set a multiple attributes at once on the server.

Throws:
Exception

setAttributes

public void setAttributes(String domainName,
                          String beanName,
                          List<Attribute> attributes)
                   throws Exception
Set a multiple attributes at once on the server.

Throws:
Exception

invokeOperation

public Object invokeOperation(String domain,
                              String beanName,
                              String operName,
                              String... paramStrings)
                       throws Exception
Invoke a JMX method with a domain/object-name as an array of parameter strings.

Returns:
The value returned by the method or null if none.
Throws:
Exception

invokeOperation

public Object invokeOperation(ObjectName name,
                              String operName,
                              String... paramStrings)
                       throws Exception
Invoke a JMX method as an array of parameter strings.

Returns:
The value returned by the method or null if none.
Throws:
Exception

invokeOperationToString

public String invokeOperationToString(ObjectName name,
                                      String operName,
                                      String... paramStrings)
                               throws Exception
Invoke a JMX method as an array of parameter strings.

Returns:
The value returned by the method as a string or null if none.
Throws:
Exception

invokeOperation

public Object invokeOperation(String domain,
                              String beanName,
                              String operName,
                              Object... params)
                       throws Exception
Invoke a JMX method as an array of objects.

Returns:
The value returned by the method or null if none.
Throws:
Exception

invokeOperation

public Object invokeOperation(ObjectName objectName,
                              String operName,
                              Object... params)
                       throws Exception
Invoke a JMX method as an array of objects.

Returns:
The value returned by the method or null if none.
Throws:
Exception


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