use of javax.management.remote.MBeanServerForwarder in project jdk8u_jdk by JetBrains.
the class RMIConnectorServer method start.
/**
* <p>Activates the connector server, that is starts listening for
* client connections. Calling this method when the connector
* server is already active has no effect. Calling this method
* when the connector server has been stopped will generate an
* <code>IOException</code>.</p>
*
* <p>The behavior of this method when called for the first time
* depends on the parameters that were supplied at construction,
* as described below.</p>
*
* <p>First, an object of a subclass of {@link RMIServerImpl} is
* required, to export the connector server through RMI:</p>
*
* <ul>
*
* <li>If an <code>RMIServerImpl</code> was supplied to the
* constructor, it is used.
*
* <li>Otherwise, if the protocol part of the
* <code>JMXServiceURL</code> supplied to the constructor was
* <code>iiop</code>, an object of type {@link RMIIIOPServerImpl}
* is created.
*
* <li>Otherwise, if the <code>JMXServiceURL</code>
* was null, or its protocol part was <code>rmi</code>, an object
* of type {@link RMIJRMPServerImpl} is created.
*
* <li>Otherwise, the implementation can create an
* implementation-specific {@link RMIServerImpl} or it can throw
* {@link MalformedURLException}.
*
* </ul>
*
* <p>If the given address includes a JNDI directory URL as
* specified in the package documentation for {@link
* javax.management.remote.rmi}, then this
* <code>RMIConnectorServer</code> will bootstrap by binding the
* <code>RMIServerImpl</code> to the given address.</p>
*
* <p>If the URL path part of the <code>JMXServiceURL</code> was
* empty or a single slash (<code>/</code>), then the RMI object
* will not be bound to a directory. Instead, a reference to it
* will be encoded in the URL path of the RMIConnectorServer
* address (returned by {@link #getAddress()}). The encodings for
* <code>rmi</code> and <code>iiop</code> are described in the
* package documentation for {@link
* javax.management.remote.rmi}.</p>
*
* <p>The behavior when the URL path is neither empty nor a JNDI
* directory URL, or when the protocol is neither <code>rmi</code>
* nor <code>iiop</code>, is implementation defined, and may
* include throwing {@link MalformedURLException} when the
* connector server is created or when it is started.</p>
*
* @exception IllegalStateException if the connector server has
* not been attached to an MBean server.
* @exception IOException if the connector server cannot be
* started, or in the case of the {@code iiop} protocol, that
* RMI/IIOP is not supported.
*/
public synchronized void start() throws IOException {
final boolean tracing = logger.traceOn();
if (state == STARTED) {
if (tracing)
logger.trace("start", "already started");
return;
} else if (state == STOPPED) {
if (tracing)
logger.trace("start", "already stopped");
throw new IOException("The server has been stopped.");
}
if (getMBeanServer() == null)
throw new IllegalStateException("This connector server is not " + "attached to an MBean server");
//
if (attributes != null) {
// Check if access file property is specified
//
String accessFile = (String) attributes.get("jmx.remote.x.access.file");
if (accessFile != null) {
// Access file property specified, create an instance
// of the MBeanServerFileAccessController class
//
MBeanServerForwarder mbsf;
try {
mbsf = new MBeanServerFileAccessController(accessFile);
} catch (IOException e) {
throw EnvHelp.initCause(new IllegalArgumentException(e.getMessage()), e);
}
// Set the MBeanServerForwarder
//
setMBeanServerForwarder(mbsf);
}
}
try {
if (tracing)
logger.trace("start", "setting default class loader");
defaultClassLoader = EnvHelp.resolveServerClassLoader(attributes, getMBeanServer());
} catch (InstanceNotFoundException infc) {
IllegalArgumentException x = new IllegalArgumentException("ClassLoader not found: " + infc);
throw EnvHelp.initCause(x, infc);
}
if (tracing)
logger.trace("start", "setting RMIServer object");
final RMIServerImpl rmiServer;
if (rmiServerImpl != null)
rmiServer = rmiServerImpl;
else
rmiServer = newServer();
rmiServer.setMBeanServer(getMBeanServer());
rmiServer.setDefaultClassLoader(defaultClassLoader);
rmiServer.setRMIConnectorServer(this);
rmiServer.export();
try {
if (tracing)
logger.trace("start", "getting RMIServer object to export");
final RMIServer objref = objectToBind(rmiServer, attributes);
if (address != null && address.getURLPath().startsWith("/jndi/")) {
final String jndiUrl = address.getURLPath().substring(6);
if (tracing)
logger.trace("start", "Using external directory: " + jndiUrl);
String stringBoolean = (String) attributes.get(JNDI_REBIND_ATTRIBUTE);
final boolean rebind = EnvHelp.computeBooleanFromString(stringBoolean);
if (tracing)
logger.trace("start", JNDI_REBIND_ATTRIBUTE + "=" + rebind);
try {
if (tracing)
logger.trace("start", "binding to " + jndiUrl);
final Hashtable<?, ?> usemap = EnvHelp.mapToHashtable(attributes);
bind(jndiUrl, usemap, objref, rebind);
boundJndiUrl = jndiUrl;
} catch (NamingException e) {
// fit e in the nested exception if we are on 1.4
throw newIOException("Cannot bind to URL [" + jndiUrl + "]: " + e, e);
}
} else {
// if jndiURL is null, we must encode the stub into the URL.
if (tracing)
logger.trace("start", "Encoding URL");
encodeStubInAddress(objref, attributes);
if (tracing)
logger.trace("start", "Encoded URL: " + this.address);
}
} catch (Exception e) {
try {
rmiServer.close();
} catch (Exception x) {
// OK: we are already throwing another exception
}
if (e instanceof RuntimeException)
throw (RuntimeException) e;
else if (e instanceof IOException)
throw (IOException) e;
else
throw newIOException("Got unexpected exception while " + "starting the connector server: " + e, e);
}
rmiServerImpl = rmiServer;
synchronized (openedServers) {
openedServers.add(this);
}
state = STARTED;
if (tracing) {
logger.trace("start", "Connector Server Address = " + address);
logger.trace("start", "started.");
}
}
use of javax.management.remote.MBeanServerForwarder in project jdk8u_jdk by JetBrains.
the class CommunicatorServer method setMBeanServer.
/**
* Set the <code>MBeanServer</code> object to which incoming
* requests are sent. This must be either the MBean server in
* which this connector is registered, or an
* <code>MBeanServerForwarder</code> leading to that server. An
* <code>MBeanServerForwarder</code> <code>mbsf</code> leads to an
* MBean server <code>mbs</code> if
* <code>mbsf.getMBeanServer()</code> is either <code>mbs</code>
* or an <code>MBeanServerForwarder</code> leading to
* <code>mbs</code>.
*
* @exception IllegalArgumentException if <code>newMBS</code> is neither
* the MBean server in which this connector is registered nor an
* <code>MBeanServerForwarder</code> leading to that server.
*
* @exception IllegalStateException This method has been invoked
* while the communicator was ONLINE or STARTING.
*/
public synchronized void setMBeanServer(MBeanServer newMBS) throws IllegalArgumentException, IllegalStateException {
synchronized (stateLock) {
if (state == ONLINE || state == STARTING)
throw new IllegalStateException("Stop server before " + "carrying out this operation");
}
final String error = "MBeanServer argument must be MBean server where this " + "server is registered, or an MBeanServerForwarder " + "leading to that server";
Vector<MBeanServer> seenMBS = new Vector<>();
for (MBeanServer mbs = newMBS; mbs != bottomMBS; mbs = ((MBeanServerForwarder) mbs).getMBeanServer()) {
if (!(mbs instanceof MBeanServerForwarder))
throw new IllegalArgumentException(error);
if (seenMBS.contains(mbs))
throw new IllegalArgumentException("MBeanServerForwarder " + "loop");
seenMBS.addElement(mbs);
}
topMBS = newMBS;
}
use of javax.management.remote.MBeanServerForwarder in project jdk8u_jdk by JetBrains.
the class MBeanServerBuilderImpl method newMBeanServer.
public MBeanServer newMBeanServer(String defaultDomain, MBeanServer outer, MBeanServerDelegate delegate) {
final MBeanServerForwarder mbsf = MBeanServerForwarderInvocationHandler.newProxyInstance();
final MBeanServer innerMBeanServer = inner.newMBeanServer(defaultDomain, (outer == null ? mbsf : outer), delegate);
mbsf.setMBeanServer(innerMBeanServer);
return mbsf;
}
use of javax.management.remote.MBeanServerForwarder in project jdk8u_jdk by JetBrains.
the class MBeanServerForwarderInvocationHandler method newProxyInstance.
public static MBeanServerForwarder newProxyInstance() {
final InvocationHandler handler = new MBeanServerForwarderInvocationHandler();
final Class[] interfaces = new Class[] { MBeanServerForwarder.class };
Object proxy = Proxy.newProxyInstance(MBeanServerForwarder.class.getClassLoader(), interfaces, handler);
return MBeanServerForwarder.class.cast(proxy);
}
use of javax.management.remote.MBeanServerForwarder in project jdk8u_jdk by JetBrains.
the class MBSFPreStartPostStartTest method runTest.
/**
* Run test
*/
public int runTest(boolean setBeforeStart) throws Exception {
echo("=-=-= MBSFPreStartPostStartTest: Set MBSF " + (setBeforeStart ? "before" : "after") + " starting the connector server =-=-=");
JMXConnectorServer server = null;
JMXConnector client = null;
// Create a new MBeanServer
//
final MBeanServer mbs = MBeanServerFactory.createMBeanServer();
try {
// Create the JMXServiceURL
//
final JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://");
// Create a JMXConnectorServer
//
server = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
// Create MBeanServerForwarder
//
MBeanServerForwarder mbsf = MBSFInvocationHandler.newProxyInstance();
//
if (setBeforeStart)
server.setMBeanServerForwarder(mbsf);
// Start the JMXConnectorServer
//
server.start();
//
if (!setBeforeStart)
server.setMBeanServerForwarder(mbsf);
// Create a JMXConnector
//
client = server.toJMXConnector(null);
// Connect to the connector server
//
client.connect(null);
// Get non-secure MBeanServerConnection
//
final MBeanServerConnection mbsc = client.getMBeanServerConnection();
// Run method
//
mbsc.getDefaultDomain();
// Check flag in MBeanServerForwarder
//
MBSFInvocationHandler mbsfih = (MBSFInvocationHandler) Proxy.getInvocationHandler(mbsf);
if (mbsfih.getFlag() == true) {
echo("OK: Did go into MBeanServerForwarder!");
} else {
echo("KO: Didn't go into MBeanServerForwarder!");
return 1;
}
} catch (Exception e) {
echo("Failed to perform operation: " + e);
return 1;
} finally {
//
if (client != null)
client.close();
//
if (server != null)
server.stop();
//
if (mbs != null)
MBeanServerFactory.releaseMBeanServer(mbs);
}
return 0;
}
Aggregations