1. /*
  2. * @(#)JMXConnector.java 1.30 04/05/05
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.management.remote;
  8. import java.io.IOException;
  9. import java.util.Map;
  10. import javax.management.ListenerNotFoundException;
  11. import javax.management.MBeanServerConnection;
  12. import javax.management.NotificationBroadcaster;
  13. import javax.management.NotificationEmitter;
  14. import javax.management.NotificationFilter;
  15. import javax.management.NotificationListener;
  16. import javax.security.auth.Subject;
  17. /**
  18. * <p>The client end of a JMX API connector. An object of this type can
  19. * be used to establish a connection to a connector server.</p>
  20. *
  21. * <p>A newly-created object of this type is unconnected. Its {@link
  22. * #connect connect} method must be called before it can be used.
  23. * However, objects created by {@link
  24. * JMXConnectorFactory#connect(JMXServiceURL, Map)
  25. * JMXConnectorFactory.connect} are already connected.</p>
  26. *
  27. * @since 1.5
  28. * @since.unbundled 1.0
  29. */
  30. public interface JMXConnector {
  31. /**
  32. * <p>Name of the attribute that specifies the credentials to send
  33. * to the connector server during connection. The value
  34. * associated with this attribute, if any, is a serializable
  35. * object of an appropriate type for the server's {@link
  36. * JMXAuthenticator}.
  37. */
  38. public static final String CREDENTIALS =
  39. "jmx.remote.credentials";
  40. /**
  41. * <p>Establishes the connection to the connector server. This
  42. * method is equivalent to {@link #connect(Map)
  43. * connect(null)}.</p>
  44. *
  45. * @exception IOException if the connection could not be made
  46. * because of a communication problem.
  47. *
  48. * @exception SecurityException if the connection could not be
  49. * made for security reasons.
  50. */
  51. public void connect() throws IOException;
  52. /**
  53. * <p>Establishes the connection to the connector server.</p>
  54. *
  55. * <p>If <code>connect</code> has already been called successfully
  56. * on this object, calling it again has no effect. If, however,
  57. * {@link #close} was called after <code>connect</code>, the new
  58. * <code>connect</code> will throw an <code>IOException</code>.<p>
  59. *
  60. * <p>Otherwise, either <code>connect</code> has never been called
  61. * on this object, or it has been called but produced an
  62. * exception. Then calling <code>connect</code> will attempt to
  63. * establish a connection to the connector server.</p>
  64. *
  65. * @param env the properties of the connection. Properties in
  66. * this map override properties in the map specified when the
  67. * <code>JMXConnector</code> was created, if any. This parameter
  68. * can be null, which is equivalent to an empty map.
  69. *
  70. * @exception IOException if the connection could not be made
  71. * because of a communication problem.
  72. *
  73. * @exception SecurityException if the connection could not be
  74. * made for security reasons.
  75. */
  76. public void connect(Map<String,?> env) throws IOException;
  77. /**
  78. * <p>Returns an <code>MBeanServerConnection</code> object
  79. * representing a remote MBean server. For a given
  80. * <code>JMXConnector</code>, two successful calls to this method
  81. * will usually return the same <code>MBeanServerConnection</code>
  82. * object, though this is not required.</p>
  83. *
  84. * <p>For each method in the returned
  85. * <code>MBeanServerConnection</code>, calling the method causes
  86. * the corresponding method to be called in the remote MBean
  87. * server. The value returned by the MBean server method is the
  88. * value returned to the client. If the MBean server method
  89. * produces an <code>Exception</code>, the same
  90. * <code>Exception</code> is seen by the client. If the MBean
  91. * server method, or the attempt to call it, produces an
  92. * <code>Error</code>, the <code>Error</code> is wrapped in a
  93. * {@link JMXServerErrorException}, which is seen by the
  94. * client.</p>
  95. *
  96. * <p>Calling this method is equivalent to calling
  97. * {@link #getMBeanServerConnection(Subject) getMBeanServerConnection(null)}
  98. * meaning that no delegation subject is specified and that all the
  99. * operations called on the <code>MBeanServerConnection</code> must
  100. * use the authenticated subject, if any.</p>
  101. *
  102. * @return an object that implements the
  103. * <code>MBeanServerConnection</code> interface by forwarding its
  104. * methods to the remote MBean server.
  105. *
  106. * @exception IOException if a valid
  107. * <code>MBeanServerConnection</code> cannot be created, for
  108. * instance because the connection to the remote MBean server has
  109. * not yet been established (with the {@link #connect(Map)
  110. * connect} method), or it has been closed, or it has broken.
  111. */
  112. public MBeanServerConnection getMBeanServerConnection()
  113. throws IOException;
  114. /**
  115. * <p>Returns an <code>MBeanServerConnection</code> object representing
  116. * a remote MBean server on which operations are performed on behalf of
  117. * the supplied delegation subject. For a given <code>JMXConnector</code>
  118. * and <code>Subject</code>, two successful calls to this method will
  119. * usually return the same <code>MBeanServerConnection</code> object,
  120. * though this is not required.</p>
  121. *
  122. * <p>For each method in the returned
  123. * <code>MBeanServerConnection</code>, calling the method causes
  124. * the corresponding method to be called in the remote MBean
  125. * server on behalf of the given delegation subject instead of the
  126. * authenticated subject. The value returned by the MBean server
  127. * method is the value returned to the client. If the MBean server
  128. * method produces an <code>Exception</code>, the same
  129. * <code>Exception</code> is seen by the client. If the MBean
  130. * server method, or the attempt to call it, produces an
  131. * <code>Error</code>, the <code>Error</code> is wrapped in a
  132. * {@link JMXServerErrorException}, which is seen by the
  133. * client.</p>
  134. *
  135. * @param delegationSubject the <code>Subject</code> on behalf of
  136. * which requests will be performed. Can be null, in which case
  137. * requests will be performed on behalf of the authenticated
  138. * Subject, if any.
  139. *
  140. * @return an object that implements the <code>MBeanServerConnection</code>
  141. * interface by forwarding its methods to the remote MBean server on behalf
  142. * of a given delegation subject.
  143. *
  144. * @exception IOException if a valid <code>MBeanServerConnection</code>
  145. * cannot be created, for instance because the connection to the remote
  146. * MBean server has not yet been established (with the {@link #connect(Map)
  147. * connect} method), or it has been closed, or it has broken.
  148. */
  149. public MBeanServerConnection getMBeanServerConnection(
  150. Subject delegationSubject)
  151. throws IOException;
  152. /**
  153. * <p>Closes the client connection to its server. Any ongoing or new
  154. * request using the MBeanServerConnection returned by {@link
  155. * #getMBeanServerConnection()} will get an
  156. * <code>IOException</code>.</p>
  157. *
  158. * <p>If <code>close</code> has already been called successfully
  159. * on this object, calling it again has no effect. If
  160. * <code>close</code> has never been called, or if it was called
  161. * but produced an exception, an attempt will be made to close the
  162. * connection. This attempt can succeed, in which case
  163. * <code>close</code> will return normally, or it can generate an
  164. * exception.</p>
  165. *
  166. * <p>Closing a connection is a potentially slow operation. For
  167. * example, if the server has crashed, the close operation might
  168. * have to wait for a network protocol timeout. Callers that do
  169. * not want to block in a close operation should do it in a
  170. * separate thread.</p>
  171. *
  172. * @exception IOException if the connection cannot be closed
  173. * cleanly. If this exception is thrown, it is not known whether
  174. * the server end of the connection has been cleanly closed.
  175. */
  176. public void close() throws IOException;
  177. /**
  178. * <p>Adds a listener to be informed of changes in connection
  179. * status. The listener will receive notifications of type {@link
  180. * JMXConnectionNotification}. An implementation can send other
  181. * types of notifications too.</p>
  182. *
  183. * <p>Any number of listeners can be added with this method. The
  184. * same listener can be added more than once with the same or
  185. * different values for the filter and handback. There is no
  186. * special treatment of a duplicate entry. For example, if a
  187. * listener is registered twice with no filter, then its
  188. * <code>handleNotification</code> method will be called twice for
  189. * each notification.</p>
  190. *
  191. * @param listener a listener to receive connection status
  192. * notifications.
  193. * @param filter a filter to select which notifications are to be
  194. * delivered to the listener, or null if all notifications are to
  195. * be delivered.
  196. * @param handback an object to be given to the listener along
  197. * with each notification. Can be null.
  198. *
  199. * @exception NullPointerException if <code>listener</code> is
  200. * null.
  201. *
  202. * @see #removeConnectionNotificationListener
  203. * @see NotificationBroadcaster#addNotificationListener
  204. */
  205. public void
  206. addConnectionNotificationListener(NotificationListener listener,
  207. NotificationFilter filter,
  208. Object handback);
  209. /**
  210. * <p>Removes a listener from the list to be informed of changes
  211. * in status. The listener must previously have been added. If
  212. * there is more than one matching listener, all are removed.</p>
  213. *
  214. * @param listener a listener to receive connection status
  215. * notifications.
  216. *
  217. * @exception NullPointerException if <code>listener</code> is
  218. * null.
  219. *
  220. * @exception ListenerNotFoundException if the listener is not
  221. * registered with this <code>JMXConnector</code>.
  222. *
  223. * @see #removeConnectionNotificationListener(NotificationListener,
  224. * NotificationFilter, Object)
  225. * @see #addConnectionNotificationListener
  226. * @see NotificationEmitter#removeNotificationListener
  227. */
  228. public void
  229. removeConnectionNotificationListener(NotificationListener listener)
  230. throws ListenerNotFoundException;
  231. /**
  232. * <p>Removes a listener from the list to be informed of changes
  233. * in status. The listener must previously have been added with
  234. * the same three parameters. If there is more than one matching
  235. * listener, only one is removed.</p>
  236. *
  237. * @param l a listener to receive connection status notifications.
  238. * @param f a filter to select which notifications are to be
  239. * delivered to the listener. Can be null.
  240. * @param handback an object to be given to the listener along
  241. * with each notification. Can be null.
  242. *
  243. * @exception ListenerNotFoundException if the listener is not
  244. * registered with this <code>JMXConnector</code>, or is not
  245. * registered with the given filter and handback.
  246. *
  247. * @see #removeConnectionNotificationListener(NotificationListener)
  248. * @see #addConnectionNotificationListener
  249. * @see NotificationEmitter#removeNotificationListener
  250. */
  251. public void removeConnectionNotificationListener(NotificationListener l,
  252. NotificationFilter f,
  253. Object handback)
  254. throws ListenerNotFoundException;
  255. /**
  256. * <p>Gets this connection's ID from the connector server. For a
  257. * given connector server, every connection will have a unique id
  258. * which does not change during the lifetime of the
  259. * connection.</p>
  260. *
  261. * @return the unique ID of this connection. This is the same as
  262. * the ID that the connector server includes in its {@link
  263. * JMXConnectionNotification}s. The {@link
  264. * javax.management.remote package description} describes the
  265. * conventions for connection IDs.
  266. *
  267. * @exception IOException if the connection ID cannot be obtained,
  268. * for instance because the connection is closed or broken.
  269. */
  270. public String getConnectionId() throws IOException;
  271. }