Class JMXConnectionWrapper

All Implemented Interfaces:
Serializable, AutoCloseable, JPPFAdminMBean
Direct Known Subclasses:
JMXDriverConnectionWrapper, JMXNodeConnectionWrapper

public class JMXConnectionWrapper extends AbstractJMXConnectionWrapper
Wrapper around a JMX connection, providing a thread-safe way of handling disconnections and recovery.
Author:
Laurent Cohen
See Also:
  • Constructor Details

    • JMXConnectionWrapper

      public JMXConnectionWrapper()
      Initialize a local connection (same JVM) to the MBean server.
    • JMXConnectionWrapper

      public JMXConnectionWrapper(String host, int port, boolean sslEnabled)
      Initialize the connection to the remote MBean server.
      Parameters:
      host - the host the server is running on.
      port - the port used by the server.
      sslEnabled - specifies whether the jmx connection should be secure or not.
  • Method Details

    • connect

      public void connect()
      Initialize the connection to the remote MBean server.
      Specified by:
      connect in class AbstractJMXConnectionWrapper
    • connectAndWait

      public boolean connectAndWait(long timeout)
      Initiate the connection and wait until the connection is established or the timeout has expired, whichever comes first.
      Specified by:
      connectAndWait in class AbstractJMXConnectionWrapper
      Parameters:
      timeout - the maximum time to wait for, a value of zero means no timeout and this method just waits until the connection is established.
      Returns:
      true if the connection was established in the specified time, false otherwise.
    • close

      public void close()
    • invoke

      public Object invoke(String mbeanName, String methodName, Object[] params, String[] signature) throws Exception
      Invoke a method on the specified MBean.
      Parameters:
      mbeanName - the name of the MBean.
      methodName - the name of the method to invoke.
      params - the method parameter values.
      signature - the types of the method parameters.
      Returns:
      an object or null.
      Throws:
      Exception - if the invocation failed.
    • invoke

      public Object invoke(String mbeanName, String methodName) throws Exception
      Invoke a method on the specified MBean. This is a convenience method to be used when invoking a remote MBean method with no parameters.
      This is equivalent to calling invoke(name, methodName, (Object[]) null, (String[]) null).
      Parameters:
      mbeanName - the name of the MBean.
      methodName - the name of the method to invoke.
      Returns:
      an object or null.
      Throws:
      Exception - if the invocation failed.
    • getAttribute

      public Object getAttribute(String mbeanName, String attribute) throws Exception
      Get the value of an attribute of the specified MBean.
      Parameters:
      mbeanName - the name of the MBean.
      attribute - the name of the attribute to read.
      Returns:
      an object or null.
      Throws:
      Exception - if the invocation failed.
    • setAttribute

      public void setAttribute(String mbeanName, String attribute, Object value) throws Exception
      Set the value of an attribute of the specified MBean.
      Parameters:
      mbeanName - the name of the MBean.
      attribute - the name of the attribute to write.
      value - the value to set on the attribute.
      Throws:
      Exception - if the invocation failed.
    • getHost

      public String getHost()
      Get the host the server is running on.
      Returns:
      the host as a string.
    • getPort

      public int getPort()
      Get the JMX remote port used by the server.
      Returns:
      the port as an int.
    • getURL

      public JMXServiceURL getURL()
      Get the service URL of the MBean server.
      Returns:
      a JMXServiceURL instance, or null if this object represents a local MBean server connection.
    • getMbeanConnection

      public MBeanServerConnection getMbeanConnection()
      Get the connection to the MBean server.
      Returns:
      a MBeanServerConnection instance.
    • isConnected

      public boolean isConnected()
      Determines whether the connection to the JMX server has been established.
      Returns:
      true if the connection is established, false otherwise.
    • getProxy

      public <T> T getProxy(String name, Class<T> inf) throws Exception
      Obtain a proxy to the specified remote MBean.
      Type Parameters:
      T - the type of the MBean (must be an interface).
      Parameters:
      name - the name of the mbean to retrieve.
      inf - the class of the MBean interface.
      Returns:
      an instance of the specified proxy interface.
      Throws:
      Exception - if any error occurs.
    • getProxy

      public <T> T getProxy(ObjectName objectName, Class<T> inf) throws Exception
      Obtain a proxy to the specified remote MBean.
      Type Parameters:
      T - the type of the MBean (must be an interface).
      Parameters:
      objectName - the name of the mbean to retrieve.
      inf - the class of the MBean interface.
      Returns:
      an instance of the specified proxy interface.
      Throws:
      Exception - if any error occurs.
    • getDiagnosticsProxy

      public DiagnosticsMBean getDiagnosticsProxy() throws Exception
      Get a proxy to the diagnostics/JVM health MBean.
      Returns:
      a DiagnosticsMBean instance.
      Throws:
      Exception - if any error occurs.
    • addNotificationListener

      public void addNotificationListener(String mBeanName, NotificationListener listener) throws Exception
      Adds a listener to the specified MBean.
      Parameters:
      mBeanName - the name of the MBean on which the listener should be added.
      listener - the listener to add.
      Throws:
      Exception - if any error occurs.
    • addNotificationListener

      public void addNotificationListener(String mBeanName, NotificationListener listener, NotificationFilter filter, Object handback) throws Exception
      Adds a listener to the specified MBean.
      Parameters:
      mBeanName - the name of the MBean on which the listener should be added.
      listener - the listener to add.
      filter - the filter object.
      handback - the handback object to use.
      Throws:
      Exception - if any error occurs.
    • removeNotificationListener

      public void removeNotificationListener(String mBeanName, NotificationListener listener) throws Exception
      Remove a listener from the specified MBean.
      Parameters:
      mBeanName - the name of the MBean from which the listener should be removed.
      listener - the listener to remove.
      Throws:
      Exception - if any error occurs.
    • removeNotificationListener

      public void removeNotificationListener(String mBeanName, NotificationListener listener, NotificationFilter filter, Object handback) throws Exception
      Remove a listener from the specified MBean.
      Parameters:
      mBeanName - the name of the MBean from which the listener should be removed.
      listener - the listener to remove.
      filter - the filter object.
      handback - the handback object used.
      Throws:
      Exception - if any error occurs.
    • getNotificationInfo

      public MBeanNotificationInfo[] getNotificationInfo(String mBeanName) throws Exception
      Get the MBeanNotificationInfo descriptors for the specified MBean.
      Parameters:
      mBeanName - the name of the MBean.
      Returns:
      a an array of MBeanNotificationInfo, which is empty if the MBean does not implement NotificationBroadcaster.
      Throws:
      Exception - if any error occurs.
    • systemInformation

      public JPPFSystemInformation systemInformation() throws Exception
      Description copied from interface: JPPFAdminMBean
      Get detailed information about the node's JVM properties, environment variables and runtime information such as memory usage and available processors.
      Returns:
      a JPPFSystemInformation instance.
      Throws:
      Exception - if any error occurs.
    • isSecure

      public boolean isSecure()
      Determine whether the JMX connection is secure or not.
      Returns:
      true if this connection is secure, false otherwise.
    • getJmxconnector

      public JMXConnector getJmxconnector()
      The JMX client connector.
      Returns:
      a JMXConnector instance.
    • addJMXConnectionWrapperListener

      public void addJMXConnectionWrapperListener(JMXConnectionWrapperListener listener)
      Add a listener to this connection wrapper.
      Parameters:
      listener - the listener to add.
    • removeJMXConnectionWrapperListener

      public void removeJMXConnectionWrapperListener(JMXConnectionWrapperListener listener)
      Remove a listener from this connection wrapper.
      Parameters:
      listener - the listener to add.