javax.management.remote

Class JMXConnectorServer

Implemented Interfaces:
JMXConnectorServerMBean, MBeanRegistration, NotificationBroadcaster, NotificationEmitter
Known Direct Subclasses:
RMIConnectorServer

public abstract class JMXConnectorServer
extends NotificationBroadcasterSupport
implements JMXConnectorServerMBean, MBeanRegistration

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

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

Constructor Summary

JMXConnectorServer()
Constructs 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

protected void
connectionClosed(String connectionId, String message, Object userData)
Called by a subclass when a client connection is closed normally.
protected void
connectionFailed(String connectionId, String message, Object userData)
Called by a subclass when a client connection fails.
protected void
connectionOpened(String connectionId, String message, Object userData)
Called by a subclass when a new client connection is opened.
String[]
getConnectionIds()
MBeanServer
getMBeanServer()
Returns the MBean server that this connector server is attached to.
MBeanNotificationInfo[]
getNotificationInfo()
Returns an array indicating the notifications that this MBean sends.
void
postDeregister()
void
postRegister(Boolean registrationDone)
void
preDeregister()
Called by an MBean server when this connector server is unregistered from that MBean server.
ObjectName
preRegister(MBeanServer mbs, ObjectName name)
Called by an MBean server when this connector server is registered in that MBean server.
void
setMBeanServerForwarder(MBeanServerForwarder mbsf)
JMXConnector
toJMXConnector(Map env)
Returns a client stub for this connector server.

Methods inherited from class javax.management.NotificationBroadcasterSupport

addNotificationListener, getNotificationInfo, handleNotification, removeNotificationListener, removeNotificationListener, sendNotification

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

AUTHENTICATOR

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.
Field Value:
"jmx.remote.authenticator"
Usages and Demos :

View More Examples of JMXConnectorServer.AUTHENTICATOR
   1:             Map options=new HashMap();
   2:             options.put(JMXConnectorServer.AUTHENTICATOR,jmxAuthenticator);
   3:             options.put(JAVA_NAMING_FACTORY_INITIAL,JMXHelper.COM_SUN_JNDI_RMI_REGISTRY_REGISTRY_CONTEXT_FACTORY);
   4:             options.put(RMIConnectorServer.JNDI_REBIND_ATTRIBUTE,"true");
   5:             try {

View Full Code Here

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

JMXConnectorServer

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.
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

connectionClosed

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 - the ID of the closed connection.
message - the message for the emitted JMXConnectionNotification. Can be null. See Notification.getMessage().
userData - the userData for the emitted JMXConnectionNotification. Can be null. See Notification.getUserData().
Throws:
NullPointerException - if connectionId is null.

connectionFailed

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 - the ID of the failed connection.
message - the message for the emitted JMXConnectionNotification. Can be null. See Notification.getMessage().
userData - the userData for the emitted JMXConnectionNotification. Can be null. See Notification.getUserData().
Throws:
NullPointerException - if connectionId is null.

connectionOpened

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 - 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 emitted JMXConnectionNotification. Can be null. See Notification.getMessage().
userData - the userData for the emitted JMXConnectionNotification. Can be null. See Notification.getUserData().
Throws:
NullPointerException - if connectionId is null.

getConnectionIds

public String[] getConnectionIds()
Specified by:
getConnectionIds in interface JMXConnectorServerMBean

getMBeanServer

public MBeanServer 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.

getNotificationInfo

public MBeanNotificationInfo[] 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.
Specified by:
getNotificationInfo in interface NotificationBroadcaster
Overrides:
getNotificationInfo in interface NotificationBroadcasterSupport
Returns:
the array of possible notifications.

postDeregister

public void postDeregister()
Specified by:
postDeregister in interface MBeanRegistration

postRegister

public void postRegister(Boolean registrationDone)
Specified by:
postRegister in interface MBeanRegistration

preDeregister

public void preDeregister()
            throws Exception
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.
Specified by:
preDeregister in interface MBeanRegistration

preRegister

public ObjectName preRegister(MBeanServer mbs,
                              ObjectName name)
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.

Specified by:
preRegister in interface MBeanRegistration
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 - if mbs or name is null.

setMBeanServerForwarder

public void setMBeanServerForwarder(MBeanServerForwarder mbsf)
Specified by:
setMBeanServerForwarder in interface JMXConnectorServerMBean
Usages and Demos :

View More Examples of setMBeanServerForwarder(MBeanServerForwarder mbsf)
   1: import javax.management.remote.JMXAuthenticator;
   2: import javax.management.remote.JMXConnectorServer;
   3: import javax.management.remote.JMXConnectorServerFactory;
   4:         ...
   5:       JMXAuthenticator authenticator = new PasswordAuthenticator(new File(PASSWORD_FILE));
   6:       environment.put(JMXConnectorServer.AUTHENTICATOR, authenticator);
   7: 
   8:         ...
   9:       JMXConnectorServer cntorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, environment, null);
  10:       ObjectName cntorServerName = ObjectName.getInstance(":service=" + JMXConnectorServer.class.getName() + ",protocol=" + url.getProtocol());
  11:         ...
  12:       SubjectTrackingMBeanServer interceptor = new SubjectTrackingMBeanServer();
  13:       cntorServer.setMBeanServerForwarder(interceptor);

View Full Code Here
   1: import javax.management.MBeanServerFactory;
   2: import javax.management.remote.JMXConnectorServer;
   3: import javax.management.remote.JMXConnectorServerFactory;
   4:         ...
   5:             Map options=new HashMap();
   6:             options.put(JMXConnectorServer.AUTHENTICATOR,jmxAuthenticator);
   7:             options.put(JAVA_NAMING_FACTORY_INITIAL,JMXHelper.COM_SUN_JNDI_RMI_REGISTRY_REGISTRY_CONTEXT_FACTORY);
   8:         ...
   9:             try {
  10:                 JMXConnectorServer connectorServer=    JMXConnectorServerFactory.newJMXConnectorServer(url,options,mbs);
  11:                 
  12:         ...
  13:                     MBeanServerForwarder msf = new MBeanServerGuard(authorizationUtils.getAccessController());
  14:                     connectorServer.setMBeanServerForwarder(msf);

View Full Code Here
   1: import javax.management.remote.JMXConnectorFactory;
   2: import javax.management.remote.JMXConnectorServer;
   3: import javax.management.remote.JMXConnectorServerFactory;
   4:         ...
   5:       JMXServiceURL url = createJMXConnectorServerAddress();
   6:       JMXConnectorServer server = JMXConnectorServerFactory.newJMXConnectorServer(url, getEnvironment(), null);
   7:       if (server == null) fail();
   8:         ...
   9:       JMXServiceURL url = createJMXConnectorServerAddress();
  10:       JMXConnectorServer server = JMXConnectorServerFactory.newJMXConnectorServer(url, getEnvironment(), null);
  11:       try
  12:         ...
  13:       {
  14:          server.setMBeanServerForwarder(forwarder);

View Full Code Here

toJMXConnector

public JMXConnector toJMXConnector(Map env)
            throws IOException
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 JMXConnectorServer 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.

Specified by:
toJMXConnector in interface JMXConnectorServerMBean
Parameters:
env - 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:
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 (see JMXConnectorServerMBean.isActive()).
IOException - if a communications problem means that a stub cannot be created.