J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2002-2007 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. Sun designates this |
| 8 | * particular file as subject to the "Classpath" exception as provided |
| 9 | * by Sun in the LICENSE file that accompanied this code. |
| 10 | * |
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | * accompanied this code). |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License version |
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 23 | * have any questions. |
| 24 | */ |
| 25 | |
| 26 | |
| 27 | package javax.management.remote; |
| 28 | |
| 29 | import java.io.IOException; |
| 30 | import java.util.Map; |
| 31 | |
| 32 | /** |
| 33 | * <p>MBean interface for connector servers. A JMX API connector server |
| 34 | * is attached to an MBean server, and establishes connections to that |
| 35 | * MBean server for remote clients.</p> |
| 36 | * |
| 37 | * <p>A newly-created connector server is <em>inactive</em>, and does |
| 38 | * not yet listen for connections. Only when its {@link #start start} |
| 39 | * method has been called does it start listening for connections.</p> |
| 40 | * |
| 41 | * @since 1.5 |
| 42 | */ |
| 43 | public interface JMXConnectorServerMBean { |
| 44 | /** |
| 45 | * <p>Activates the connector server, that is, starts listening for |
| 46 | * client connections. Calling this method when the connector |
| 47 | * server is already active has no effect. Calling this method |
| 48 | * when the connector server has been stopped will generate an |
| 49 | * {@link IOException}.</p> |
| 50 | * |
| 51 | * @exception IOException if it is not possible to start listening |
| 52 | * or if the connector server has been stopped. |
| 53 | * |
| 54 | * @exception IllegalStateException if the connector server has |
| 55 | * not been attached to an MBean server. |
| 56 | */ |
| 57 | public void start() throws IOException; |
| 58 | |
| 59 | /** |
| 60 | * <p>Deactivates the connector server, that is, stops listening for |
| 61 | * client connections. Calling this method will also close all |
| 62 | * client connections that were made by this server. After this |
| 63 | * method returns, whether normally or with an exception, the |
| 64 | * connector server will not create any new client |
| 65 | * connections.</p> |
| 66 | * |
| 67 | * <p>Once a connector server has been stopped, it cannot be started |
| 68 | * again.</p> |
| 69 | * |
| 70 | * <p>Calling this method when the connector server has already |
| 71 | * been stopped has no effect. Calling this method when the |
| 72 | * connector server has not yet been started will disable the |
| 73 | * connector server object permanently.</p> |
| 74 | * |
| 75 | * <p>If closing a client connection produces an exception, that |
| 76 | * exception is not thrown from this method. A {@link |
| 77 | * JMXConnectionNotification} with type {@link |
| 78 | * JMXConnectionNotification#FAILED} is emitted from this MBean |
| 79 | * with the connection ID of the connection that could not be |
| 80 | * closed.</p> |
| 81 | * |
| 82 | * <p>Closing a connector server is a potentially slow operation. |
| 83 | * For example, if a client machine with an open connection has |
| 84 | * crashed, the close operation might have to wait for a network |
| 85 | * protocol timeout. Callers that do not want to block in a close |
| 86 | * operation should do it in a separate thread.</p> |
| 87 | * |
| 88 | * @exception IOException if the server cannot be closed cleanly. |
| 89 | * When this exception is thrown, the server has already attempted |
| 90 | * to close all client connections. All client connections are |
| 91 | * closed except possibly those that generated exceptions when the |
| 92 | * server attempted to close them. |
| 93 | */ |
| 94 | public void stop() throws IOException; |
| 95 | |
| 96 | /** |
| 97 | * <p>Determines whether the connector server is active. A connector |
| 98 | * server starts being active when its {@link #start start} method |
| 99 | * returns successfully and remains active until either its |
| 100 | * {@link #stop stop} method is called or the connector server |
| 101 | * fails.</p> |
| 102 | * |
| 103 | * @return true if the connector server is active. |
| 104 | */ |
| 105 | public boolean isActive(); |
| 106 | |
| 107 | /** |
| 108 | * <p>Adds an object that intercepts requests for the MBean server |
| 109 | * that arrive through this connector server. This object will be |
| 110 | * supplied as the <code>MBeanServer</code> for any new connection |
| 111 | * created by this connector server. Existing connections are |
| 112 | * unaffected.</p> |
| 113 | * |
| 114 | * <p>If this connector server is already associated with an |
| 115 | * <code>MBeanServer</code> object, then that object is given to |
| 116 | * {@link MBeanServerForwarder#setMBeanServer |
| 117 | * mbsf.setMBeanServer}. If doing so produces an exception, this |
| 118 | * method throws the same exception without any other effect.</p> |
| 119 | * |
| 120 | * <p>If this connector is not already associated with an |
| 121 | * <code>MBeanServer</code> object, or if the |
| 122 | * <code>mbsf.setMBeanServer</code> call just mentioned succeeds, |
| 123 | * then <code>mbsf</code> becomes this connector server's |
| 124 | * <code>MBeanServer</code>.</p> |
| 125 | * |
| 126 | * @param mbsf the new <code>MBeanServerForwarder</code>. |
| 127 | * |
| 128 | * @exception IllegalArgumentException if the call to {@link |
| 129 | * MBeanServerForwarder#setMBeanServer mbsf.setMBeanServer} fails |
| 130 | * with <code>IllegalArgumentException</code>. This includes the |
| 131 | * case where <code>mbsf</code> is null. |
| 132 | */ |
| 133 | public void setMBeanServerForwarder(MBeanServerForwarder mbsf); |
| 134 | |
| 135 | /** |
| 136 | * <p>The list of IDs for currently-open connections to this |
| 137 | * connector server.</p> |
| 138 | * |
| 139 | * @return a new string array containing the list of IDs. If |
| 140 | * there are no currently-open connections, this array will be |
| 141 | * empty. |
| 142 | */ |
| 143 | public String[] getConnectionIds(); |
| 144 | |
| 145 | /** |
| 146 | * <p>The address of this connector server.</p> |
| 147 | * <p> |
| 148 | * The address returned may not be the exact original {@link JMXServiceURL} |
| 149 | * that was supplied when creating the connector server, since the original |
| 150 | * address may not always be complete. For example the port number may be |
| 151 | * dynamically allocated when starting the connector server. Instead the |
| 152 | * address returned is the actual {@link JMXServiceURL} of the |
| 153 | * {@link JMXConnectorServer}. This is the address that clients supply |
| 154 | * to {@link JMXConnectorFactory#connect(JMXServiceURL)}. |
| 155 | * </p> |
| 156 | * <p>Note that the address returned may be {@code null} if |
| 157 | * the {@code JMXConnectorServer} is not yet {@link #isActive active}. |
| 158 | * </p> |
| 159 | * |
| 160 | * @return the address of this connector server, or null if it |
| 161 | * does not have one. |
| 162 | */ |
| 163 | public JMXServiceURL getAddress(); |
| 164 | |
| 165 | /** |
| 166 | * <p>The attributes for this connector server.</p> |
| 167 | * |
| 168 | * @return a read-only map containing the attributes for this |
| 169 | * connector server. Attributes whose values are not serializable |
| 170 | * are omitted from this map. If there are no serializable |
| 171 | * attributes, the returned map is empty. |
| 172 | */ |
| 173 | public Map<String,?> getAttributes(); |
| 174 | |
| 175 | /** |
| 176 | * <p>Returns a client stub for this connector server. A client |
| 177 | * stub is a serializable object whose {@link |
| 178 | * JMXConnector#connect(Map) connect} method can be used to make |
| 179 | * one new connection to this connector server.</p> |
| 180 | * |
| 181 | * <p>A given connector need not support the generation of client |
| 182 | * stubs. However, the connectors specified by the JMX Remote API do |
| 183 | * (JMXMP Connector and RMI Connector).</p> |
| 184 | * |
| 185 | * @param env client connection parameters of the same sort that |
| 186 | * can be provided to {@link JMXConnector#connect(Map) |
| 187 | * JMXConnector.connect(Map)}. Can be null, which is equivalent |
| 188 | * to an empty map. |
| 189 | * |
| 190 | * @return a client stub that can be used to make a new connection |
| 191 | * to this connector server. |
| 192 | * |
| 193 | * @exception UnsupportedOperationException if this connector |
| 194 | * server does not support the generation of client stubs. |
| 195 | * |
| 196 | * @exception IllegalStateException if the JMXConnectorServer is |
| 197 | * not started (see {@link JMXConnectorServerMBean#isActive()}). |
| 198 | * |
| 199 | * @exception IOException if a communications problem means that a |
| 200 | * stub cannot be created. |
| 201 | * |
| 202 | */ |
| 203 | public JMXConnector toJMXConnector(Map<String,?> env) |
| 204 | throws IOException; |
| 205 | } |