org.opends.server.protocols.jmx
Class OpendsJmxConnector

java.lang.Object
  extended by org.opends.server.protocols.jmx.OpendsJmxConnector
All Implemented Interfaces:
java.io.Closeable, javax.management.remote.JMXConnector

public class OpendsJmxConnector
extends java.lang.Object
implements javax.management.remote.JMXConnector

Wrapper class for the JMX's RMI connector. This class has the exact same functionnalities but maintain inner variables which are used during the connection phase.

Note that the javadoc has been copied from the javax.management.remote.JMXConnector interface.


Field Summary
 
Fields inherited from interface javax.management.remote.JMXConnector
CREDENTIALS
 
Constructor Summary
OpendsJmxConnector(java.lang.String serverHostname, int serverPort, java.util.Map<java.lang.String,java.lang.Object> environment)
          Creates a connector client for the connector server at the given host and port.
 
Method Summary
 void addConnectionNotificationListener(javax.management.NotificationListener listener, javax.management.NotificationFilter filter, java.lang.Object handback)
          Adds a listener to be informed of changes in connection status.
 void close()
          Closes the client connection to its server.
 void connect()
          Establishes the connection to the connector server.
 void connect(java.util.Map<java.lang.String,?> env)
          Establishes the connection to the connector server.
 java.util.Map getConnectionEnv()
          Returns the connection environment.
 java.lang.String getConnectionId()
          Gets this connection's ID from the connector server.
 javax.management.MBeanServerConnection getMBeanServerConnection()
          Returns an MBeanServerConnection object representing a remote MBean server.
 javax.management.MBeanServerConnection getMBeanServerConnection(javax.security.auth.Subject delegationSubject)
          Returns an MBeanServerConnection object representing a remote MBean server on which operations are performed on behalf of the supplied delegation subject.
 void removeConnectionNotificationListener(javax.management.NotificationListener listener)
          Removes a listener from the list to be informed of changes in status.
 void removeConnectionNotificationListener(javax.management.NotificationListener l, javax.management.NotificationFilter f, java.lang.Object handback)
          Removes a listener from the list to be informed of changes in status.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OpendsJmxConnector

public OpendsJmxConnector(java.lang.String serverHostname,
                          int serverPort,
                          java.util.Map<java.lang.String,java.lang.Object> environment)
                   throws java.io.IOException
Creates a connector client for the connector server at the given host and port. The resultant client is not connected until its connect method is called.

Parameters:
serverHostname - the target server hostname
serverPort - the target server port
environment - a set of attributes to determine how the connection is made. This parameter can be null. Keys in this map must be Strings. The appropriate type of each associated value depends on the attribute. The contents of environment are not changed by this call.
Throws:
java.io.IOException - if the connector client cannot be made because of a communication problem.
Method Detail

getConnectionEnv

public java.util.Map getConnectionEnv()
Returns the connection environment.

Returns:
Map the connection environment used by new connections

connect

public void connect()
             throws java.io.IOException,
                    java.lang.SecurityException
Establishes the connection to the connector server. This method is equivalent to connect(null).

Specified by:
connect in interface javax.management.remote.JMXConnector
Throws:
java.io.IOException - if the connection could not be made because of a communication problem.
java.lang.SecurityException - if the connection could not be made for security reasons.

connect

public void connect(java.util.Map<java.lang.String,?> env)
             throws java.io.IOException,
                    java.lang.SecurityException
Establishes the connection to the connector server. If connect has already been called successfully on this object, calling it again has no effect. If, however, close() was called after connect, the new connect will throw an IOException. Otherwise, either connect has never been called on this object, or it has been called but produced an exception. Then calling connect will attempt to establish a connection to the connector server.

Specified by:
connect in interface javax.management.remote.JMXConnector
Parameters:
env - the properties of the connection. Properties in this map override properties in the map specified when the JMXConnector was created, if any. This parameter can be null, which is equivalent to an empty map.
Throws:
java.io.IOException - if the connection could not be made because of a communication problem.
java.lang.SecurityException - - if the connection could not be made for security reasons.

getMBeanServerConnection

public javax.management.MBeanServerConnection getMBeanServerConnection()
                                                                throws java.io.IOException
Returns an MBeanServerConnection object representing a remote MBean server. For a given JMXConnector, two successful calls to this method will usually return the same MBeanServerConnection object, though this is not required. For each method in the returned MBeanServerConnection, calling the method causes the corresponding method to be called in the remote MBean server. The value returned by the MBean server method is the value returned to the client. If the MBean server method produces an Exception, the same Exception is seen by the client. If the MBean server method, or the attempt to call it, produces an Error, the Error is wrapped in a JMXServerErrorException, which is seen by the client. Calling this method is equivalent to calling getMBeanServerConnection(null) meaning that no delegation subject is specified and that all the operations called on the MBeanServerConnection must use the authenticated subject, if any.

Specified by:
getMBeanServerConnection in interface javax.management.remote.JMXConnector
Returns:
an object that implements the MBeanServerConnection interface by forwarding its methods to the remote MBean server.
Throws:
java.io.IOException - - if a valid MBeanServerConnection cannot be created, for instance because the connection to the remote MBean server has not yet been established (with the connect method), or it has been closed, or it has broken.

getMBeanServerConnection

public javax.management.MBeanServerConnection getMBeanServerConnection(javax.security.auth.Subject delegationSubject)
                                                                throws java.io.IOException
Returns an MBeanServerConnection object representing a remote MBean server on which operations are performed on behalf of the supplied delegation subject. For a given JMXConnector and Subject, two successful calls to this method will usually return the same MBeanServerConnection object, though this is not required. For each method in the returned MBeanServerConnection, calling the method causes the corresponding method to be called in the remote MBean server on behalf of the given delegation subject instead of the authenticated subject. The value returned by the MBean server method is the value returned to the client. If the MBean server method produces an Exception, the same Exception is seen by the client. If the MBean server method, or the attempt to call it, produces an Error, the Error is wrapped in a JMXServerErrorException, which is seen by the client.

Specified by:
getMBeanServerConnection in interface javax.management.remote.JMXConnector
Parameters:
delegationSubject - the Subject on behalf of which requests will be performed. Can be null, in which case requests will be performed on behalf of the authenticated Subject, if any.
Returns:
an object that implements the MBeanServerConnection interface by forwarding its methods to the remote MBean server on behalf of a given delegation subject.
Throws:
java.io.IOException - if a valid MBeanServerConnection cannot be created, for instance because the connection to the remote MBean server has not yet been established (with the connect method), or it has been closed, or it has broken.

close

public void close()
           throws java.io.IOException
Closes the client connection to its server. Any ongoing or new request using the MBeanServerConnection returned by getMBeanServerConnection() will get an IOException. If close has already been called successfully on this object, calling it again has no effect. If close has never been called, or if it was called but produced an exception, an attempt will be made to close the connection. This attempt can succeed, in which case close will return normally, or it can generate an exception. Closing a connection is a potentially slow operation. For example, if the server has crashed, the close operation might have to wait for a network protocol timeout. Callers that do not want to block in a close operation should do it in a separate thread.

Specified by:
close in interface java.io.Closeable
Specified by:
close in interface javax.management.remote.JMXConnector
Throws:
java.io.IOException - if the connection cannot be closed cleanly. If this exception is thrown, it is not known whether the server end of the connection has been cleanly closed.

addConnectionNotificationListener

public void addConnectionNotificationListener(javax.management.NotificationListener listener,
                                              javax.management.NotificationFilter filter,
                                              java.lang.Object handback)
                                       throws java.lang.NullPointerException
Adds a listener to be informed of changes in connection status. The listener will receive notifications of type JMXConnectionNotification. An implementation can send other types of notifications too. Any number of listeners can be added with this method. The same listener can be added more than once with the same or different values for the filter and handback. There is no special treatment of a duplicate entry. For example, if a listener is registered twice with no filter, then its handleNotification method will be called twice for each notification.

Specified by:
addConnectionNotificationListener in interface javax.management.remote.JMXConnector
Parameters:
listener - a listener to receive connection status notifications.
filter - a filter to select which notifications are to be delivered to the listener, or null if all notifications are to be delivered.
handback - an object to be given to the listener along with each notification. Can be null.
Throws:
java.lang.NullPointerException - if listener is null.

removeConnectionNotificationListener

public void removeConnectionNotificationListener(javax.management.NotificationListener listener)
                                          throws javax.management.ListenerNotFoundException,
                                                 java.lang.NullPointerException
Removes a listener from the list to be informed of changes in status. The listener must previously have been added. If there is more than one matching listener, all are removed.

Specified by:
removeConnectionNotificationListener in interface javax.management.remote.JMXConnector
Parameters:
listener - - a listener to receive connection status notifications.
Throws:
java.lang.NullPointerException - if listener is null.
javax.management.ListenerNotFoundException - if the listener is not registered with this JMXConnector.

removeConnectionNotificationListener

public void removeConnectionNotificationListener(javax.management.NotificationListener l,
                                                 javax.management.NotificationFilter f,
                                                 java.lang.Object handback)
                                          throws javax.management.ListenerNotFoundException
Removes a listener from the list to be informed of changes in status. The listener must previously have been added with the same three parameters. If there is more than one matching listener, only one is removed.

Specified by:
removeConnectionNotificationListener in interface javax.management.remote.JMXConnector
Parameters:
l - a listener to receive connection status notifications.
f - a filter to select which notifications are to be delivered to the listener. Can be null. handback - an object to be given to the listener along with each notification. Can be null.
handback - an object to be given to the listener along with each notification. Can be null.
Throws:
javax.management.ListenerNotFoundException - if the listener is not registered with this JMXConnector, or is not registered with the given filter and handback.

getConnectionId

public java.lang.String getConnectionId()
                                 throws java.io.IOException
Gets this connection's ID from the connector server. For a given connector server, every connection will have a unique id which does not change during the lifetime of the connection.

Specified by:
getConnectionId in interface javax.management.remote.JMXConnector
Returns:
the unique ID of this connection. This is the same as the ID that the connector server includes in its JMXConnectionNotifications. The package description describes the conventions for connection IDs.
Throws:
java.io.IOException - if the connection ID cannot be obtained, for instance because the connection is closed or broken.