org.jppf.management
Class JMXConnectionWrapper

java.lang.Object
  extended by org.jppf.utils.ThreadSynchronization
      extended by org.jppf.management.JMXConnectionWrapper
Direct Known Subclasses:
JMXDriverConnectionWrapper, JMXNodeConnectionWrapper

public class JMXConnectionWrapper
extends ThreadSynchronization

Wrapper around a JMX connection, providing a thread-safe way of handling disconnections and recovery.

Author:
Laurent Cohen

Field Summary
protected  boolean local
          Determines whether the connection to the JMX server has been established.
 
Fields inherited from class org.jppf.utils.ThreadSynchronization
stopped
 
Constructor Summary
JMXConnectionWrapper()
          Initialize a local connection (same JVM) to the MBean server.
JMXConnectionWrapper(String host, int port, String rmiSuffix)
          Initialize the connection to the remote MBean server.
 
Method Summary
 void close()
          Close the connection to the remote MBean server.
 void connect()
          Initialize the connection to the remote MBean server.
 void connectAndWait(long timeout)
          Initiate the connection and wait until the connection is established or the timeout has expired, whichever comes first.
 Object getAttribute(String name, String attribute)
          Get the value of an attribute of the specified MBean.
 String getHost()
          Get the host the server is running on.
 String getId()
          Get a string describing this connection.
 MBeanServerConnection getMbeanConnection()
          Get the connection to the MBean server.
 int getPort()
          Get the RMI port used by the server.
<T> T
getProxy(ObjectName objectName, Class<T> inf)
          Obtain a proxy to the soecified remote MBean.
<T> T
getProxy(String name, Class<T> inf)
          Obtain a proxy to the soecified remote MBean.
 Object invoke(String name, String methodName, Object[] params, String[] signature)
          Invoke a method on the specified MBean.
 boolean isConnected()
          Determines whether the connection to the JMX server has been established.
protected  void setConnectedStatus(boolean status)
          Set the connected state of this conenction wrapper.
 
Methods inherited from class org.jppf.utils.ThreadSynchronization
goToSleep, goToSleep, goToSleep, isStopped, setStopped, wakeUp
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

local

protected boolean local
Determines whether the connection to the JMX server has been established.

Constructor Detail

JMXConnectionWrapper

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


JMXConnectionWrapper

public JMXConnectionWrapper(String host,
                            int port,
                            String rmiSuffix)
Initialize the connection to the remote MBean server.

Parameters:
host - the host the server is running on.
port - the RMI port used by the server.
rmiSuffix - RMI registry namespace suffix.
Method Detail

connect

public void connect()
Initialize the connection to the remote MBean server.


connectAndWait

public void connectAndWait(long timeout)
Initiate the connection and wait until the connection is established or the timeout has expired, whichever comes first.

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.

close

public void close()
           throws Exception
Close the connection to the remote MBean server.

Throws:
Exception - if the connection could not be closed.

invoke

public Object invoke(String name,
                     String methodName,
                     Object[] params,
                     String[] signature)
              throws Exception
Invoke a method on the specified MBean.

Parameters:
name - 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.

getAttribute

public Object getAttribute(String name,
                           String attribute)
                    throws Exception
Get the value of an attribute of the specified MBean.

Parameters:
name - the name of the MBean.
attribute - the name of the attribute to read.
Returns:
an object or null.
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 RMI port used by the server.

Returns:
the port as an int.

getId

public String getId()
Get a string describing this connection.

Returns:
a string in the format host:port.

getMbeanConnection

public MBeanServerConnection getMbeanConnection()
Get the connection to the MBean server.

Returns:
a MBeanServerConnection instance.

setConnectedStatus

protected void setConnectedStatus(boolean status)
Set the connected state of this conenction wrapper.

Parameters:
status - true if the jmx connection is established, false otherwise.

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 soecified 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 soecified 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.


Copyright © 2005-2010 JPPF Team.