📄 rmiconnectorserver.java
字号:
* <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. */ 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."); } MBeanServer mbs = getMBeanServer(); if (mbs == null) throw new IllegalStateException("This connector server is not " + "attached to an MBean server"); // Check the internal access file property to see // if an MBeanServerForwarder is to be provided // 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 = null; try { mbsf = new MBeanServerFileAccessController(accessFile); } catch (IOException e) { throw (IllegalArgumentException) EnvHelp.initCause( new IllegalArgumentException(e.getMessage()), e); } // Set the MBeanServerForwarder // setMBeanServerForwarder(mbsf); mbs = getMBeanServer(); } } try { if (tracing) logger.trace("start", "setting default class loader"); defaultClassLoader = EnvHelp.resolveServerClassLoader(attributes, mbs); } catch (InstanceNotFoundException infc) { IllegalArgumentException x = new IllegalArgumentException("ClassLoader not found: "+infc); throw (IllegalArgumentException)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(mbs); 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); final boolean rebind; String rebindS = (String) attributes.get(JNDI_REBIND_ATTRIBUTE); if (rebindS == null) rebind = false; else if (rebindS.equalsIgnoreCase("true")) rebind = true; else if (rebindS.equalsIgnoreCase("false")) rebind = false; else throw new IllegalArgumentException(JNDI_REBIND_ATTRIBUTE + "must" + " be \"true\" or \"false\""); if (tracing) logger.trace("start", JNDI_REBIND_ATTRIBUTE + "=" + rebind); try { if (tracing) logger.trace("start", "binding to " + jndiUrl); final Hashtable usemap = EnvHelp.mapToHashtable(attributes); final boolean isIiop = isIiopURL(address, true); if (isIiop) { // Make sure java.naming.corba.orb is in the Map. usemap.put(EnvHelp.DEFAULT_ORB, RMIConnector.resolveOrb(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."); } } /** * <p>Deactivates the connector server, that is, stops listening for * client connections. Calling this method will also close all * client connections that were made by this server. After this * method returns, whether normally or with an exception, the * connector server will not create any new client * connections.</p> * * <p>Once a connector server has been stopped, it cannot be started * again.</p> * * <p>Calling this method when the connector server has already * been stopped has no effect. Calling this method when the * connector server has not yet been started will disable the * connector server object permanently.</p> * * <p>If closing a client connection produces an exception, that * exception is not thrown from this method. A {@link * JMXConnectionNotification} is emitted from this MBean with the * connection ID of the connection that could not be closed.</p> * * <p>Closing a connector server is a potentially slow operation. * For example, if a client machine with an open connection has * crashed, the close operation might have to wait for a network * protocol timeout. Callers that do not want to block in a close * operation should do it in a separate thread.</p> * * <p>This method calls the method {@link RMIServerImpl#close() * close} on the connector server's <code>RMIServerImpl</code> * object.</p> * * <p>If the <code>RMIServerImpl</code> was bound to a JNDI * directory by the {@link #start() start} method, it is unbound * from the directory by this method.</p> * * @exception IOException if the server cannot be closed cleanly, * or if the <code>RMIServerImpl</code> cannot be unbound from the * directory. When this exception is thrown, the server has * already attempted to close all client connections, if * appropriate; to call {@link RMIServerImpl#close()}; and to * unbind the <code>RMIServerImpl</code> from its directory, if * appropriate. All client connections are closed except possibly * those that generated exceptions when the server attempted to * close them. */ public void stop() throws IOException { final boolean tracing = logger.traceOn(); synchronized (this) { if (state == STOPPED) { if (tracing) logger.trace("stop","already stopped."); return; } else if (state == CREATED) { if (tracing) logger.trace("stop","not started yet."); } if (tracing) logger.trace("stop", "stopping."); state = STOPPED; } synchronized(openedServers) { openedServers.remove(this); } IOException exception = null; // rmiServerImpl can be null if stop() called without start() if (rmiServerImpl != null) { try { if (tracing) logger.trace("stop", "closing RMI server."); rmiServerImpl.close(); } catch (IOException e) { if (tracing) logger.trace("stop", "failed to close RMI server: " + e); if (logger.debugOn()) logger.debug("stop",e); exception = e; } } if (boundJndiUrl != null) { try { if (tracing) logger.trace("stop", "unbind from external directory: " + boundJndiUrl); final Hashtable usemap = EnvHelp.mapToHashtable(attributes); final boolean isIiop = isIiopURL(address, true); if (isIiop) { // Make sure java.naming.corba.orb is in the Map. usemap.put(EnvHelp.DEFAULT_ORB,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -