📄 rmidriver.java
字号:
this.xmlBlasterImpl = xmlBlasterImpl; this.addressServer = addressServer; XmlBlasterSecurityManager.createSecurityManager(glob); // plugin/rmi/registryPort int registryPort = addressServer.getEnv("registryPort", DEFAULT_REGISTRY_PORT).getValue(); // default xmlBlaster RMI publishing port is 1099 String hostname = addressServer.getEnv("hostname", glob.getLocalIP()).getValue(); try { if (registryPort > 0) { // Start a 'rmiregistry' if desired try { java.rmi.registry.LocateRegistry.createRegistry(registryPort); log.info("Started RMI registry on port " + registryPort); } catch (java.rmi.server.ExportException e) { // Try to bind to an already running registry: try { java.rmi.registry.LocateRegistry.getRegistry(hostname, registryPort); log.info("Another rmiregistry is running on port " + DEFAULT_REGISTRY_PORT + " we will use this one. You could change the port with e.g. '-plugin/rmi/registryPort 1122' to run your own rmiregistry."); } catch (RemoteException e2) { String text = "Port " + DEFAULT_REGISTRY_PORT + " is already in use, but does not seem to be a rmiregistry. Please can change the port with e.g. -plugin/rmi/registryPortCB=1122 : " + e.toString(); log.severe(text); throw new XmlBlasterException(ME, text); } } } String prefix = "rmi://"; authBindName = prefix + hostname + ":" + registryPort + "/I_AuthServer"; authBindName = addressServer.getEnv("AuthServerUrl", authBindName).getValue(); xmlBlasterBindName = prefix + hostname + ":" + registryPort + "/I_XmlBlaster"; xmlBlasterBindName = addressServer.getEnv("XmlBlasterUrl", xmlBlasterBindName).getValue(); } catch (Exception e) { e.printStackTrace(); throw new XmlBlasterException("InitRmiFailed", "Could not initialize RMI registry: " + e.toString()); } if (log.isLoggable(Level.FINE)) log.fine("Initialized RMI server"); } /** * Activate xmlBlaster access through this protocol. */ public synchronized void activate() throws XmlBlasterException { if (log.isLoggable(Level.FINER)) log.finer("Entering activate"); try { authRmiServer = new AuthServerImpl(glob, this.addressServer, this.authenticate, xmlBlasterImpl); xmlBlasterRmiServer = new XmlBlasterImpl(glob, this.addressServer, xmlBlasterImpl); } catch (RemoteException e) { log.severe(e.toString()); throw new XmlBlasterException("RmiDriverFailed", e.toString()); } bindToRegistry(); isActive = true; log.info("Started successfully RMI driver."); } /** * Deactivate xmlBlaster access (standby), no clients can connect. */ public synchronized void deActivate() throws XmlBlasterException { if (log.isLoggable(Level.FINER)) log.finer("Entering deActivate"); try { if (authBindName != null) { Naming.unbind(authBindName); } // force shutdown, even if we still have calls in progress: java.rmi.server.UnicastRemoteObject.unexportObject(authRmiServer, true); } catch (Exception e) { log.warning("Can't shutdown authentication server: " + e.toString()); } try { if (xmlBlasterBindName != null) Naming.unbind(xmlBlasterBindName); // force shutdown, even if we still have calls in progress: java.rmi.server.UnicastRemoteObject.unexportObject(xmlBlasterRmiServer, true); } catch (Exception e) { log.warning("Can't shutdown xmlBlaster server: " + e.toString()); } isActive = false; log.info("RMI deactivated, no client access possible."); } /** * Instructs RMI to shut down. */ public void shutdown() throws XmlBlasterException { if (log.isLoggable(Level.FINE)) log.fine("Shutting down RMI driver ..."); if (isActive) { try { deActivate(); } catch (XmlBlasterException e) { log.severe(e.toString()); } } authBindName = null; log.info("RMI driver stopped, naming entries released."); } /** * Publish the RMI xmlBlaster server to rmi registry. * <p /> * The bind name is typically "rmi://localhost:1099/xmlBlaster" * @exception XmlBlasterException * RMI registry error handling */ private void bindToRegistry() throws XmlBlasterException { if (log.isLoggable(Level.FINER)) log.finer("bindToRegistry() ..."); // Publish RMI based xmlBlaster server ... try { Naming.bind(authBindName, authRmiServer); log.info("Bound authentication RMI server to registry with name '" + authBindName + "'"); } catch (AlreadyBoundException e) { try { Naming.rebind(authBindName, authRmiServer); log.warning("Removed another entry while binding authentication RMI server to registry with name '" + authBindName + "'"); } catch(Exception e2) { if (log.isLoggable(Level.FINE)) log.fine("RMI registry of '" + authBindName + "' failed: " + e2.toString()); throw new XmlBlasterException(ME+".RmiRegistryFailed", "RMI registry of '" + authBindName + "' failed: " + e2.toString()); } } catch (java.rmi.NoSuchObjectException e) { // 'rmi://noty:7904/I_AuthServer': authRmiServer -> no such object in table if (log.isLoggable(Level.FINE)) log.fine("RMI registry of '" + authBindName + "' authRmiServer=" + authRmiServer + " failed: " + e.getMessage()); throw new XmlBlasterException(glob, ErrorCode.RESOURCE_CONFIGURATION, ME+".RmiRegistryFailed", "RMI registry of '" + authBindName + "' failed, probably another server instance is running already (implementation to handle this is missing): " + e.toString()); } catch (Throwable e) { if (log.isLoggable(Level.FINE)) log.fine("RMI registry of '" + authBindName + "' failed: " + e.getMessage()); throw new XmlBlasterException(glob, ErrorCode.RESOURCE_CONFIGURATION, ME+".RmiRegistryFailed", "RMI registry of '" + authBindName + "' failed: ", e); } try { Naming.bind(xmlBlasterBindName, xmlBlasterRmiServer); log.info("Bound xmlBlaster RMI server to registry with name '" + xmlBlasterBindName + "'"); } catch (AlreadyBoundException e) { try { Naming.rebind(xmlBlasterBindName, xmlBlasterRmiServer); log.warning("Removed another entry while binding xmlBlaster RMI server to registry with name '" + xmlBlasterBindName + "'"); } catch (Exception e2) { log.severe("RMI registry of '" + xmlBlasterBindName + "' failed: " + e.toString()); throw new XmlBlasterException(glob, ErrorCode.RESOURCE_CONFIGURATION, ME+".RmiRegistryFailed", "RMI registry of '" + xmlBlasterBindName + "' failed: " + e.toString()); } } catch (Throwable e) { log.severe("RMI registry of '" + xmlBlasterBindName + "' failed: " + e.toString()); throw new XmlBlasterException(glob, ErrorCode.RESOURCE_CONFIGURATION, ME+".RmiRegistryFailed", "RMI registry of '" + xmlBlasterBindName + "' failed", e); } } /** * Command line usage. */ public String usage() { String text = "\n"; text += "RmiDriver options:\n"; text += " -plugin/rmi/registryPort\n"; text += " Specify a port number where rmiregistry listens.\n"; text += " Default is port "+DEFAULT_REGISTRY_PORT+", the port 0 switches this feature off.\n"; text += " -plugin/rmi/hostname\n"; text += " Specify a hostname where rmiregistry runs.\n"; text += " Default is the localhost.\n"; text += "\n"; return text; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -