Top Description Fields Constructors Methods
javax.management.remote

public abstract Class JMXConnectorServer

extends NotificationBroadcasterSupport
implements JMXConnectorServerMBean, MBeanRegistration, JMXAddressable
Class Inheritance
All Implemented Interfaces
javax.management.remote.JMXAddressable, javax.management.MBeanRegistration, javax.management.remote.JMXConnectorServerMBean
Imports
java.io.IOException, java.util.ArrayList, .List, .Map, javax.management.MBeanNotificationInfo, .MBeanRegistration, .MBeanServer, .Notification, .NotificationBroadcasterSupport, .ObjectName

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

Modifier and TypeField and Description
public static final String
AUTHENTICATOR

Name of the attribute that specifies the authenticator for a connector server.

private final List<String>
private MBeanServer
mbeanServer

The MBeanServer used by this server to execute a client request.

private ObjectName
myName

The name used to registered this server in an MBeanServer.

private static long
private static final int[]

Constructor Summary

AccessConstructor and Description
public
JMXConnectorServer()

Constructs a connector server that will be registered as an MBean in the MBean server it is attached to.

public
JMXConnectorServer(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.
mbeanServer
)

Constructs a connector server that is attached to the given MBean server.

Method Summary

Modifier and TypeMethod and Description
protected void
connectionClosed(String
the ID of the closed connection.
connectionId
,
String
the message for the emitted JMXConnectionNotification. Can be null. See Notification#getMessage().
message
,
Object
the userData for the emitted JMXConnectionNotification. Can be null. See Notification#getUserData().
userData
)

Called by a subclass when a client connection is closed normally.

protected void
connectionFailed(String
the ID of the failed connection.
connectionId
,
String
the message for the emitted JMXConnectionNotification. Can be null. See Notification#getMessage().
message
,
Object
the userData for the emitted JMXConnectionNotification. Can be null. See Notification#getUserData().
userData
)

Called by a subclass when a client connection fails.

protected void
connectionOpened(String
the ID of the new connection. This must be different from the ID of any connection previously opened by this connector server.
connectionId
,
String
the message for the emitted JMXConnectionNotification. Can be null. See Notification#getMessage().
message
,
Object
the userData for the emitted JMXConnectionNotification. Can be null. See Notification#getUserData().
userData
)

Called by a subclass when a new client connection is opened.

public String[]
getConnectionIds()

Implements javax.management.remote.JMXConnectorServerMBean.getConnectionIds.

The list of IDs for currently-open connections to this connector server.

public synchronized MBeanServer

Returns:

the MBean server that this connector server is attached to, or null if it is not yet attached to an MBean server.
getMBeanServer
()

Returns the MBean server that this connector server is attached to.

public MBeanNotificationInfo[]

Returns:

the array of possible notifications.
getNotificationInfo
()

Overrides javax.management.NotificationBroadcasterSupport.getNotificationInfo.

Implements javax.management.NotificationBroadcaster.getNotificationInfo.

Returns an array indicating the notifications that this MBean sends.

private synchronized Object
private static long
public void
postDeregister()

Implements javax.management.MBeanRegistration.postDeregister.

Allows the MBean to perform any operations needed after having been unregistered in the MBean server.
public void
postRegister(Boolean
Indicates whether or not the MBean has been successfully registered in the MBean server. The value false means that the registration phase has failed.
registrationDone
)

Implements javax.management.MBeanRegistration.postRegister.

Allows the MBean to perform any operations needed after having been registered in the MBean server or after the registration has failed.
public synchronized void
preDeregister()

Implements javax.management.MBeanRegistration.preDeregister.

Called by an MBean server when this connector server is unregistered from that MBean server.

public synchronized ObjectName

Returns:

The name under which the MBean is to be registered.
preRegister
(MBeanServer
the MBean server in which this connection server is being registered.
mbs
,
ObjectName
The object name of the MBean.
name
)

Implements javax.management.MBeanRegistration.preRegister.

Called by an MBean server when this connector server is registered in that MBean server.

private void
sendNotification(String type, String connectionId, String message, Object userData)

public synchronized void
setMBeanServerForwarder(MBeanServerForwarder
the new MBeanServerForwarder.
mbsf
)

Implements javax.management.remote.JMXConnectorServerMBean.setMBeanServerForwarder.

Inserts an object that intercepts requests for the MBean server that arrive through this connector server.

public JMXConnector

Returns:

a client stub that can be used to make a new connection to this connector server.
toJMXConnector
(Map<String, ?>
client connection parameters of the same sort that could be provided to JMXConnector.connect(Map). Can be null, which is equivalent to an empty map.
env
)

Implements javax.management.remote.JMXConnectorServerMBean.toJMXConnector.

Returns a client stub for this connector server.

Inherited from javax.management.NotificationBroadcasterSupport:
addNotificationListenerhandleNotificationremoveNotificationListenerremoveNotificationListenersendNotification

Field Detail

AUTHENTICATORback to summary
public static final String 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.

connectionIdsback to summary
private final List<String> connectionIds
mbeanServerback to summary
private MBeanServer mbeanServer

The MBeanServer used by this server to execute a client request.

myNameback to summary
private ObjectName myName

The name used to registered this server in an MBeanServer. It is null if the this server is not registered or has been unregistered.

sequenceNumberback to summary
private static long sequenceNumber
sequenceNumberLockback to summary
private static final int[] sequenceNumberLock

Constructor Detail

JMXConnectorServerback to summary
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 createMBean methods when creating, within an MBean server, a connector server that makes it available remotely.

JMXConnectorServerback to summary
public JMXConnectorServer(MBeanServer mbeanServer)

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

connectionClosedback to summary
protected void connectionClosed(String connectionId, String message, Object userData)

Called by a subclass when a client connection is closed normally. Removes connectionId from the list returned by getConnectionIds(), then emits a JMXConnectionNotification with type JMXConnectionNotification#CLOSED.

Parameters
connectionId:String

the ID of the closed connection.

message:String

the message for the emitted JMXConnectionNotification. Can be null. See Notification#getMessage().

userData:Object

the userData for the emitted JMXConnectionNotification. Can be null. See Notification#getUserData().

Exceptions
NullPointerException:
if connectionId is null.
connectionFailedback to summary
protected void connectionFailed(String connectionId, String message, Object userData)

Called by a subclass when a client connection fails. Removes connectionId from the list returned by getConnectionIds(), then emits a JMXConnectionNotification with type JMXConnectionNotification#FAILED.

Parameters
connectionId:String

the ID of the failed connection.

message:String

the message for the emitted JMXConnectionNotification. Can be null. See Notification#getMessage().

userData:Object

the userData for the emitted JMXConnectionNotification. Can be null. See Notification#getUserData().

Exceptions
NullPointerException:
if connectionId is null.
connectionOpenedback to summary
protected void connectionOpened(String connectionId, String message, Object userData)

Called by a subclass when a new client connection is opened. Adds connectionId to the list returned by getConnectionIds(), then emits a JMXConnectionNotification with type JMXConnectionNotification#OPENED.

Parameters
connectionId:String

the ID of the new connection. This must be different from the ID of any connection previously opened by this connector server.

message:String

the message for the emitted JMXConnectionNotification. Can be null. See Notification#getMessage().

userData:Object

the userData for the emitted JMXConnectionNotification. Can be null. See Notification#getUserData().

Exceptions
NullPointerException:
if connectionId is null.
getConnectionIdsback to summary
public String[] getConnectionIds()

Implements javax.management.remote.JMXConnectorServerMBean.getConnectionIds.

Doc from javax.management.remote.JMXConnectorServerMBean.getConnectionIds.

The list of IDs for currently-open connections to this connector server.

Returns:String[]

a new string array containing the list of IDs. If there are no currently-open connections, this array will be empty.

getMBeanServerback to summary
public synchronized MBeanServer getMBeanServer()

Returns the MBean server that this connector server is attached to.

Returns:MBeanServer

the MBean server that this connector server is attached to, or null if it is not yet attached to an MBean server.

getNotificationInfoback to summary
public MBeanNotificationInfo[] getNotificationInfo()

Overrides javax.management.NotificationBroadcasterSupport.getNotificationInfo.

Implements javax.management.NotificationBroadcaster.getNotificationInfo.

Returns an array indicating the notifications that this MBean sends. The implementation in JMXConnectorServer returns an array with one element, indicating that it can emit notifications of class JMXConnectionNotification with 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.

Returns:MBeanNotificationInfo[]

the array of possible notifications.

Annotations
@Override
getNotificationSourceback to summary
private synchronized Object getNotificationSource()
nextSequenceNumberback to summary
private static long nextSequenceNumber()
postDeregisterback to summary
public void postDeregister()

Implements javax.management.MBeanRegistration.postDeregister.

Doc from javax.management.MBeanRegistration.postDeregister.

Allows the MBean to perform any operations needed after having been unregistered in the MBean server.

If the implementation of this method throws a RuntimeException or an Error, the MBean Server will rethrow those inside a RuntimeMBeanException or RuntimeErrorException, respectively. However, throwing an exception in postDeregister will 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 of postDeregister do not throw Runtime Exceptions or Errors if it can be avoided.

postRegisterback to summary
public void postRegister(Boolean registrationDone)

Implements javax.management.MBeanRegistration.postRegister.

Doc from javax.management.MBeanRegistration.postRegister.

Allows 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 RuntimeException or an Error, the MBean Server will rethrow those inside a RuntimeMBeanException or RuntimeErrorException, respectively. However, throwing an exception in postRegister will not change the state of the MBean: if the MBean was already registered (registrationDone is true), the MBean will remain registered.

This might be confusing for the code calling createMBean() or registerMBean(), as such code might assume that MBean registration has failed when such an exception is raised. Therefore it is recommended that implementations of postRegister do not throw Runtime Exceptions or Errors if it can be avoided.

Parameters
registrationDone:Boolean

Indicates whether or not the MBean has been successfully registered in the MBean server. The value false means that the registration phase has failed.

preDeregisterback to summary
public synchronized void preDeregister() throws Exception

Implements javax.management.MBeanRegistration.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 stop method. If the stop method throws an exception, the unregistration attempt will fail. It is recommended to call the stop method explicitly before unregistering the MBean.

Exceptions
Exception:

Doc from javax.management.MBeanRegistration.preDeregister.

This exception will be caught by the MBean server and re-thrown as an MBeanRegistrationException.

IOException:
if thrown by the stop method.
preRegisterback to summary
public synchronized ObjectName preRegister(MBeanServer mbs, ObjectName name)

Implements javax.management.MBeanRegistration.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 return mbs.

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.

Parameters
mbs:MBeanServer

the MBean server in which this connection server is being registered.

name:ObjectName

The object name of the MBean.

Returns:ObjectName

The name under which the MBean is to be registered.

Exceptions
NullPointerException:
if mbs or name is null.
sendNotificationback to summary
private void sendNotification(String type, String connectionId, String message, Object userData)
setMBeanServerForwarderback to summary
public synchronized void setMBeanServerForwarder(MBeanServerForwarder mbsf)

Implements javax.management.remote.JMXConnectorServerMBean.setMBeanServerForwarder.

Doc from javax.management.remote.JMXConnectorServerMBean.setMBeanServerForwarder.

Inserts an object that intercepts requests for the MBean server that arrive through this connector server. This object will be supplied as the MBeanServer for any new connection created by this connector server. Existing connections are unaffected.

This method can be called more than once with different MBeanServerForwarder objects. 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 MBeanServer object, then that object is given to mbsf.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 MBeanServer object, or if the mbsf.setMBeanServer call just mentioned succeeds, then mbsf becomes this connector server's MBeanServer.

Parameters
mbsf:MBeanServerForwarder

the new MBeanServerForwarder.

toJMXConnectorback to summary
public JMXConnector toJMXConnector(Map<String, ?> env) throws IOException

Implements javax.management.remote.JMXConnectorServerMBean.toJMXConnector.

Returns a client stub for this connector server. A client stub is a serializable object whose connect method 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 getAddress and JMXConnectorFactory to generate the stub, with code equivalent to the following:

JMXServiceURL addr = getAddress();
return JMXConnectorFactory.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.

Parameters
env:Map<String, ?>

client connection parameters of the same sort that could be provided to JMXConnector.connect(Map). Can be null, which is equivalent to an empty map.

Returns:JMXConnector

a client stub that can be used to make a new connection to this connector server.

Exceptions
IOException:
if a communications problem means that a stub cannot be created.
UnsupportedOperationException:
if this connector server does not support the generation of client stubs.
IllegalStateException:
if the JMXConnectorServer is not started (see JMXConnectorServerMBean#isActive()).