Search in sources :

Example 1 with MBeanServerFileAccessController

use of com.sun.jmx.remote.security.MBeanServerFileAccessController 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.");
    }
}
Also used : InstanceNotFoundException(javax.management.InstanceNotFoundException) IOException(java.io.IOException) NamingException(javax.naming.NamingException) InstanceNotFoundException(javax.management.InstanceNotFoundException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) MBeanServerForwarder(javax.management.remote.MBeanServerForwarder) MBeanServerFileAccessController(com.sun.jmx.remote.security.MBeanServerFileAccessController) NamingException(javax.naming.NamingException)

Aggregations

MBeanServerFileAccessController (com.sun.jmx.remote.security.MBeanServerFileAccessController)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 InstanceNotFoundException (javax.management.InstanceNotFoundException)1 MBeanServerForwarder (javax.management.remote.MBeanServerForwarder)1 NamingException (javax.naming.NamingException)1