Class JMXConnectorServer
- All Implemented Interfaces:
MBeanRegistration,NotificationBroadcaster,NotificationEmitter,JMXAddressable,JMXConnectorServerMBean
- Direct Known Subclasses:
RMIConnectorServer
Superclass of every connector server. A connector server is attached to an MBean server. It listens for client connection requests and creates a connection for each one.
A connector server is associated with an MBean server either by registering it in that MBean server, or by passing the MBean server to its constructor.
A connector server is inactive when created. It only starts
listening for client connections when the start
method is called. A connector server stops listening for client
connections when the stop method is called or when
the connector server is unregistered from its MBean server.
Stopping a connector server does not unregister it from its MBean server. A connector server once stopped cannot be restarted.
Each time a client connection is made or broken, a notification
of class JMXConnectionNotification is emitted.
- Since:
- 1.5
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringName of the attribute that specifies the authenticator for a connector server. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a connector server that will be registered as an MBean in the MBean server it is attached to.JMXConnectorServer(MBeanServer mbeanServer) Constructs a connector server that is attached to the given MBean server. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidconnectionClosed(String connectionId, String message, Object userData) Called by a subclass when a client connection is closed normally.protected voidconnectionFailed(String connectionId, String message, Object userData) Called by a subclass when a client connection fails.protected voidconnectionOpened(String connectionId, String message, Object userData) Called by a subclass when a new client connection is opened.String[]The list of IDs for currently-open connections to this connector server.Returns the MBean server that this connector server is attached to.Returns an array indicating the notifications that this MBean sends.voidAllows the MBean to perform any operations needed after having been unregistered in the MBean server.voidpostRegister(Boolean registrationDone) Allows the MBean to perform any operations needed after having been registered in the MBean server or after the registration has failed.voidCalled by an MBean server when this connector server is unregistered from that MBean server.preRegister(MBeanServer mbs, ObjectName name) Called by an MBean server when this connector server is registered in that MBean server.voidInserts an object that intercepts requests for the MBean server that arrive through this connector server.toJMXConnector(Map<String, ?> env) Returns a client stub for this connector server.Methods declared in class javax.management.NotificationBroadcasterSupport
addNotificationListener, handleNotification, removeNotificationListener, removeNotificationListener, sendNotificationMethods declared in class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods declared in interface javax.management.remote.JMXAddressable
getAddressMethods declared in interface javax.management.remote.JMXConnectorServerMBean
getAddress, getAttributes, isActive, start, stop
-
Field Details
-
AUTHENTICATOR
Name of the attribute that specifies the authenticator for a connector server. The value associated with this attribute, if any, must be an object that implements the interface
JMXAuthenticator.- See Also:
-
-
Constructor Details
-
JMXConnectorServer
public JMXConnectorServer()Constructs a connector server that will be registered as an MBean in the MBean server it is attached to. This constructor is typically called by one of the
createMBeanmethods when creating, within an MBean server, a connector server that makes it available remotely. -
JMXConnectorServer
Constructs a connector server that is attached to the given MBean server. A connector server that is created in this way can be registered in a different MBean server, or not registered in any MBean server.
- Parameters:
mbeanServer- the MBean server that this connector server is attached to. Null if this connector server will be attached to an MBean server by being registered in it.
-
-
Method Details
-
getMBeanServer
Returns the MBean server that this connector server is attached to.
- Returns:
- the MBean server that this connector server is attached to, or null if it is not yet attached to an MBean server.
-
setMBeanServerForwarder
Description copied from interface:JMXConnectorServerMBeanInserts an object that intercepts requests for the MBean server that arrive through this connector server. This object will be supplied as the
MBeanServerfor any new connection created by this connector server. Existing connections are unaffected.This method can be called more than once with different
MBeanServerForwarderobjects. The result is a chain of forwarders. The last forwarder added is the first in the chain. In more detail:If this connector server is already associated with an
MBeanServerobject, then that object is given tombsf.setMBeanServer. If doing so produces an exception, this method throws the same exception without any other effect.If this connector is not already associated with an
MBeanServerobject, or if thembsf.setMBeanServercall just mentioned succeeds, thenmbsfbecomes this connector server'sMBeanServer.
- Specified by:
setMBeanServerForwarderin interfaceJMXConnectorServerMBean- Parameters:
mbsf- the newMBeanServerForwarder.
-
getConnectionIds
Description copied from interface:JMXConnectorServerMBeanThe list of IDs for currently-open connections to this connector server.
- Specified by:
getConnectionIdsin interfaceJMXConnectorServerMBean- Returns:
- a new string array containing the list of IDs. If there are no currently-open connections, this array will be empty.
-
toJMXConnector
Returns a client stub for this connector server. A client stub is a serializable object whose
connectmethod can be used to make one new connection to this connector server.A given connector need not support the generation of client stubs. However, the connectors specified by the JMX Remote API do (JMXMP Connector and RMI Connector).
The default implementation of this method uses
JMXConnectorServerMBean.getAddress()andJMXConnectorFactoryto generate the stub, with code equivalent to the following:JMXServiceURL addr =
getAddress(); returnJMXConnectorFactory.newJMXConnector(addr, env);A connector server for which this is inappropriate must override this method so that it either implements the appropriate logic or throws
UnsupportedOperationException.- Specified by:
toJMXConnectorin interfaceJMXConnectorServerMBean- Parameters:
env- client connection parameters of the same sort that could be provided toJMXConnector.connect(Map). Can be null, which is equivalent to an empty map.- Returns:
- a client stub that can be used to make a new connection to this connector server.
- Throws:
UnsupportedOperationException- if this connector server does not support the generation of client stubs.IllegalStateException- if the JMXConnectorServer is not started (seeJMXConnectorServerMBean.isActive()).IOException- if a communications problem means that a stub cannot be created.
-
getNotificationInfo
Returns an array indicating the notifications that this MBean sends. The implementation in
JMXConnectorServerreturns an array with one element, indicating that it can emit notifications of classJMXConnectionNotificationwith the types defined in that class. A subclass that can emit other notifications should return an array that contains this element plus descriptions of the other notifications.- Specified by:
getNotificationInfoin interfaceNotificationBroadcaster- Returns:
- the array of possible notifications.
-
connectionOpened
Called by a subclass when a new client connection is opened. Adds
connectionIdto the list returned bygetConnectionIds(), then emits aJMXConnectionNotificationwith typeJMXConnectionNotification.OPENED.- Parameters:
connectionId- the ID of the new connection. This must be different from the ID of any connection previously opened by this connector server.message- the message for the emittedJMXConnectionNotification. Can be null. SeeNotification.getMessage().userData- theuserDatafor the emittedJMXConnectionNotification. Can be null. SeeNotification.getUserData().- Throws:
NullPointerException- ifconnectionIdis null.
-
connectionClosed
Called by a subclass when a client connection is closed normally. Removes
connectionIdfrom the list returned bygetConnectionIds(), then emits aJMXConnectionNotificationwith typeJMXConnectionNotification.CLOSED.- Parameters:
connectionId- the ID of the closed connection.message- the message for the emittedJMXConnectionNotification. Can be null. SeeNotification.getMessage().userData- theuserDatafor the emittedJMXConnectionNotification. Can be null. SeeNotification.getUserData().- Throws:
NullPointerException- ifconnectionIdis null.
-
connectionFailed
Called by a subclass when a client connection fails. Removes
connectionIdfrom the list returned bygetConnectionIds(), then emits aJMXConnectionNotificationwith typeJMXConnectionNotification.FAILED.- Parameters:
connectionId- the ID of the failed connection.message- the message for the emittedJMXConnectionNotification. Can be null. SeeNotification.getMessage().userData- theuserDatafor the emittedJMXConnectionNotification. Can be null. SeeNotification.getUserData().- Throws:
NullPointerException- ifconnectionIdis null.
-
preRegister
Called by an MBean server when this connector server is registered in that MBean server. This connector server becomes attached to the MBean server and its
getMBeanServer()method will returnmbs.If this connector server is already attached to an MBean server, this method has no effect. The MBean server it is attached to is not necessarily the one it is being registered in.
- Specified by:
preRegisterin interfaceMBeanRegistration- Parameters:
mbs- the MBean server in which this connection server is being registered.name- The object name of the MBean.- Returns:
- The name under which the MBean is to be registered.
- Throws:
NullPointerException- ifmbsornameis null.
-
postRegister
Description copied from interface:MBeanRegistrationAllows the MBean to perform any operations needed after having been registered in the MBean server or after the registration has failed.If the implementation of this method throws a
RuntimeExceptionor anError, the MBean Server will rethrow those inside aRuntimeMBeanExceptionorRuntimeErrorException, respectively. However, throwing an exception inpostRegisterwill not change the state of the MBean: if the MBean was already registered (registrationDoneistrue), the MBean will remain registered.This might be confusing for the code calling
createMBean()orregisterMBean(), as such code might assume that MBean registration has failed when such an exception is raised. Therefore it is recommended that implementations ofpostRegisterdo not throw Runtime Exceptions or Errors if it can be avoided.- Specified by:
postRegisterin interfaceMBeanRegistration- Parameters:
registrationDone- Indicates whether or not the MBean has been successfully registered in the MBean server. The value false means that the registration phase has failed.
-
preDeregister
Called by an MBean server when this connector server is unregistered from that MBean server. If this connector server was attached to that MBean server by being registered in it, and if the connector server is still active, then unregistering it will call the
stopmethod. If thestopmethod throws an exception, the unregistration attempt will fail. It is recommended to call thestopmethod explicitly before unregistering the MBean.- Specified by:
preDeregisterin interfaceMBeanRegistration- Throws:
IOException- if thrown by thestopmethod.Exception- This exception will be caught by the MBean server and re-thrown as anMBeanRegistrationException.
-
postDeregister
public void postDeregister()Description copied from interface:MBeanRegistrationAllows the MBean to perform any operations needed after having been unregistered in the MBean server.If the implementation of this method throws a
RuntimeExceptionor anError, the MBean Server will rethrow those inside aRuntimeMBeanExceptionorRuntimeErrorException, respectively. However, throwing an exception inpostDeregisterwill not change the state of the MBean: the MBean was already successfully deregistered and will remain so.This might be confusing for the code calling
unregisterMBean(), as it might assume that MBean deregistration has failed. Therefore it is recommended that implementations ofpostDeregisterdo not throw Runtime Exceptions or Errors if it can be avoided.- Specified by:
postDeregisterin interfaceMBeanRegistration
-