/* * Copyright (c) 2002, 2007, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.management.remote; import java.io.Closeable; import java.io.IOException; import java.util.Map; import javax.management.ListenerNotFoundException; import javax.management.MBeanServerConnection; import javax.management.NotificationFilter; import javax.management.NotificationListener; import javax.security.auth.Subject; /** *
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 {@link * #connect connect} method must be called before it can be used. * However, objects created by {@link * JMXConnectorFactory#connect(JMXServiceURL, Map) * JMXConnectorFactory.connect} are already connected.
* * @since 1.5 */ public interface JMXConnector extends Closeable { /** *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 {@link * JMXAuthenticator}. */ public static final String CREDENTIALS = "jmx.remote.credentials"; /** *
Establishes the connection to the connector server. This * method is equivalent to {@link #connect(Map) * connect(null)}.
* * @exception IOException if the connection could not be made * because of a communication problem. * * @exception SecurityException if the connection could not be * made for security reasons. */ public void connect() 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,
* {@link #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.
JMXConnector
was created, if any. This parameter
* can be null, which is equivalent to an empty map.
*
* @exception IOException if the connection could not be made
* because of a communication problem.
*
* @exception SecurityException if the connection could not be
* made for security reasons.
*/
public void connect(MapReturns 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
* {@link JMXServerErrorException}, which is seen by the
* client.
Calling this method is equivalent to calling
* {@link #getMBeanServerConnection(Subject) 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.
MBeanServerConnection
interface by forwarding its
* methods to the remote MBean server.
*
* @exception 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 {@link #connect(Map)
* connect} method), or it has been closed, or it has broken.
*/
public MBeanServerConnection getMBeanServerConnection()
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
* {@link JMXServerErrorException}, which is seen by the
* client.
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.
*
* @return an object that implements the MBeanServerConnection
* interface by forwarding its methods to the remote MBean server on behalf
* of a given delegation subject.
*
* @exception 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 {@link #connect(Map)
* connect} method), or it has been closed, or it has broken.
*/
public MBeanServerConnection getMBeanServerConnection(
Subject delegationSubject)
throws IOException;
/**
* Closes the client connection to its server. Any ongoing or new
* request using the MBeanServerConnection returned by {@link
* #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.
* * @exception 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. */ public void close() throws IOException; /** *Adds a listener to be informed of changes in connection * status. The listener will receive notifications of type {@link * 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.
listener
is
* null.
*
* @see #removeConnectionNotificationListener
* @see javax.management.NotificationBroadcaster#addNotificationListener
*/
public void
addConnectionNotificationListener(NotificationListener listener,
NotificationFilter filter,
Object handback);
/**
* 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.
* * @param listener a listener to receive connection status * notifications. * * @exception NullPointerException iflistener
is
* null.
*
* @exception ListenerNotFoundException if the listener is not
* registered with this JMXConnector
.
*
* @see #removeConnectionNotificationListener(NotificationListener,
* NotificationFilter, Object)
* @see #addConnectionNotificationListener
* @see javax.management.NotificationEmitter#removeNotificationListener
*/
public void
removeConnectionNotificationListener(NotificationListener listener)
throws 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.
* * @param l a listener to receive connection status notifications. * @param f a filter to select which notifications are to be * delivered to the listener. Can be null. * @param handback an object to be given to the listener along * with each notification. Can be null. * * @exception ListenerNotFoundException if the listener is not * registered with thisJMXConnector
, or is not
* registered with the given filter and handback.
*
* @see #removeConnectionNotificationListener(NotificationListener)
* @see #addConnectionNotificationListener
* @see javax.management.NotificationEmitter#removeNotificationListener
*/
public void removeConnectionNotificationListener(NotificationListener l,
NotificationFilter f,
Object handback)
throws ListenerNotFoundException;
/**
* 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.
* * @return the unique ID of this connection. This is the same as * the ID that the connector server includes in its {@link * JMXConnectionNotification}s. The {@link * javax.management.remote package description} describes the * conventions for connection IDs. * * @exception IOException if the connection ID cannot be obtained, * for instance because the connection is closed or broken. */ public String getConnectionId() throws IOException; }