Interface JMXConnector

  • All Superinterfaces:
    AutoCloseable, Closeable
    All Known Implementing Classes:
    RMIConnector

    public interface JMXConnector
    extends Closeable

    The client end of a JMX API connector. An object of this type can be used to establish a connection to a connector server.

    A newly-created object of this type is unconnected. Its connect method must be called before it can be used. However, objects created by JMXConnectorFactory.connect are already connected.

    Since:
    1.5
    • Field Detail

      • CREDENTIALS

        static final String CREDENTIALS

        Name of the attribute that specifies the credentials to send to the connector server during connection. The value associated with this attribute, if any, is a serializable object of an appropriate type for the server's JMXAuthenticator.

        See Also:
        Constant Field Values
    • Method Detail

      • connect

        void connect()
              throws IOException

        Establishes the connection to the connector server. This method is equivalent to connect(null).

        Throws:
        IOException - if the connection could not be made because of a communication problem.
        SecurityException - if the connection could not be made for security reasons.
      • connect

        void connect​(Map<String,?> env)
              throws IOException

        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.

        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:
        IOException - if the connection could not be made because of a communication problem.
        SecurityException - if the connection could not be made for security reasons.
      • getMBeanServerConnection

        MBeanServerConnection getMBeanServerConnection()
                                                throws 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.

        Returns:
        an object that implements the MBeanServerConnection interface by forwarding its methods to the remote MBean server.
        Throws:
        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

        MBeanServerConnection getMBeanServerConnection​(Subject delegationSubject)
                                                throws 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.

        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:
        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

        void close()
            throws 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 AutoCloseable
        Specified by:
        close in interface Closeable
        Throws:
        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.
      • getConnectionId

        String getConnectionId()
                        throws 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.

        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:
        IOException - if the connection ID cannot be obtained, for instance because the connection is closed or broken.