⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rmiconnection.java

📁 java开源的企业总线.xmlBlaster
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*------------------------------------------------------------------------------Name:      RmiConnection.javaProject:   xmlBlaster.orgCopyright: xmlBlaster.org, see xmlBlaster-LICENSE fileComment:   Helper to connect to xmlBlaster using RMI------------------------------------------------------------------------------*/package org.xmlBlaster.client.protocol.rmi;import org.xmlBlaster.protocol.rmi.I_AuthServer;import org.xmlBlaster.protocol.rmi.I_XmlBlaster;import org.xmlBlaster.protocol.rmi.RmiUrl;import org.xmlBlaster.client.protocol.I_XmlBlasterConnection;import java.util.logging.Logger;import java.util.logging.Level;import org.xmlBlaster.util.Global;import org.xmlBlaster.util.XmlBlasterException;import org.xmlBlaster.util.def.ErrorCode;import org.xmlBlaster.util.XmlBlasterSecurityManager;import org.xmlBlaster.util.MsgUnitRaw;import org.xmlBlaster.client.qos.ConnectReturnQos;import org.xmlBlaster.util.qos.address.Address;import org.xmlBlaster.util.xbformat.I_ProgressListener;import java.rmi.RemoteException;import java.rmi.Naming;import java.rmi.NotBoundException;import java.rmi.Remote;import java.net.MalformedURLException;import java.applet.Applet;/** * This is a helper class, helping a Java client to connect to xmlBlaster * using RMI. * <p> * Please note that you don't need to use this wrapper, you can use the raw RMI * interface as well. You can also hack your own little wrapper, which does exactly * what you want. * <p> * There is a constructor for applets, and standalone Java clients. * <p /> * If you need a failsafe client, you can invoke the xmlBlaster RMI methods * through this class as well (for example use rmiConnection.publish() instead of the direct * RMI server.publish()). * <p /> * If you want to connect from a servlet, please use the framework in xmlBlaster/src/java/org/xmlBlaster/protocol/http * <pre> *  # Configure RMI plugin to load: *  ClientProtocolPlugin[RMI][1.0]=org.xmlBlaster.client.protocol.rmi.RmiConnection * </pre> * * @see <a href="http://www.xmlBlaster.org/xmlBlaster/doc/requirements/protocol.rmi.html">The RMI requirement</a> * @author <a href="mailto:xmlBlaster@marcelruff.info">Marcel Ruff</a>. */public class RmiConnection implements I_XmlBlasterConnection{   private String ME = "RmiConnection";   private Global glob;   private static Logger log = Logger.getLogger(RmiConnection.class.getName());   private I_AuthServer authServer = null;   private I_XmlBlaster blasterServer = null;   private String sessionId = null;   protected Address clientAddress;   private RmiUrl rmiUrl;   /** XmlBlaster RMI registry listen port is 1099, to access for bootstrapping */   public static final int DEFAULT_REGISTRY_PORT = 1099; // org.xmlBlaster.protocol.rmi.RmiDriver.DEFAULT_REGISTRY_PORT;   private boolean verbose = true;   /**    * Called by plugin loader which calls init(Global, PluginInfo) thereafter.     */   public RmiConnection() {   }   /**    * RMI client access to xmlBlaster for <strong>normal client applications</strong>.    * <p />    * @param arg  parameters given on command line    */   public RmiConnection(Global glob) throws XmlBlasterException {      init(glob, null);   }   /**    * RMI client access to xmlBlaster for <strong>applets</strong>.    * <p />    * @param ap  Applet handle    */   public RmiConnection(Global glob, Applet ap) throws XmlBlasterException {      init(glob, null);   }   /** Enforced by I_Plugin */   public String getType() {      return getProtocol();   }   /** Enforced by I_Plugin */   public String getVersion() {      return "1.0";   }   /**    * This method is called by the PluginManager (enforced by I_Plugin).     * @see org.xmlBlaster.util.plugin.I_Plugin#init(org.xmlBlaster.util.Global,org.xmlBlaster.util.plugin.PluginInfo)    */   public void init(org.xmlBlaster.util.Global glob, org.xmlBlaster.util.plugin.PluginInfo pluginInfo) throws XmlBlasterException {      this.glob = (glob == null) ? Global.instance() : glob;      XmlBlasterSecurityManager.createSecurityManager(this.glob);      log.info("Created '" + getProtocol() + "' protocol plugin to connect to xmlBlaster server");   }   /**    * Connect to RMI server.    */   public void connectLowlevel(Address address) throws XmlBlasterException {      if (log.isLoggable(Level.FINER)) log.finer("connectLowlevel() ...");      if (this.authServer != null) {         return;      }      this.clientAddress = address;      // default xmlBlaster RMI publishing registryPort is 1099      this.rmiUrl = new RmiUrl(glob, this.clientAddress);      String authServerUrl = this.rmiUrl.getUrl() + "I_AuthServer";      String addr = this.clientAddress.getEnv("AuthServerUrl", authServerUrl).getValue();      Remote rem = lookup(addr);      if (rem instanceof org.xmlBlaster.protocol.rmi.I_AuthServer) {         this.authServer = (I_AuthServer)rem;         this.clientAddress.setRawAddress(addr);         log.info("Accessed xmlBlaster authentication reference with '" + addr + "'");      }      else {         throw new XmlBlasterException(glob, ErrorCode.RESOURCE_CONFIGURATION_ADDRESS, ME, "No connect to '" + addr + "' possible, class needs to implement interface I_AuthServer.");      }      String xmlBlasterUrl = this.rmiUrl.getUrl() + "I_XmlBlaster";      addr = this.clientAddress.getEnv("XmlBlasterUrl", xmlBlasterUrl).getValue();      rem = lookup(addr);      if (rem instanceof org.xmlBlaster.protocol.rmi.I_XmlBlaster) {         this.blasterServer = (I_XmlBlaster)rem;         log.info("Accessed xmlBlaster server reference with '" + addr + "'");      }      else {         throw new XmlBlasterException(glob, ErrorCode.RESOURCE_CONFIGURATION_ADDRESS, ME, "No connect to '" + addr + "' possible, class needs to implement interface I_XmlBlaster.");      }   }   /**    * Connect to RMI server.    * @see I_XmlBlasterConnection#connectLowlevel(Address)    */   private Remote lookup(String addr) throws XmlBlasterException {      try {         return Naming.lookup(addr);      }      catch (RemoteException e) {         if (this.verbose) log.warning("Can't access address ='" + addr + "', no rmi registry running");         throw new XmlBlasterException(glob, ErrorCode.COMMUNICATION_NOCONNECTION, ME, "Can't access address ='" + addr + "', no rmi registry running");      }      catch (NotBoundException e) {         if (this.verbose) log.warning("The given address ='" + addr + "' is not bound to rmi registry: " + e.toString());         throw new XmlBlasterException(glob, ErrorCode.COMMUNICATION_NOCONNECTION, ME, "The given address '" + addr + "' is not bound to rmi registry: " + e.toString());      }      catch (MalformedURLException e) {         log.severe("The given address ='" + addr + "' is invalid: " + e.toString());         throw new XmlBlasterException(glob, ErrorCode.RESOURCE_CONFIGURATION_ADDRESS, ME, "The given address '" + addr + "' is invalid: " + e.toString());      }      catch (Throwable e) {         log.severe("The given address ='" + addr + "' is invalid : " + e.toString());         throw new XmlBlasterException(glob, ErrorCode.RESOURCE_CONFIGURATION_ADDRESS, ME, "The given address '" + addr + "' is invalid : " + e.toString());      }      finally {         this.verbose = false;      }   }   /**    * Reset    */   public void resetConnection(){      this.authServer = null;      this.blasterServer = null;      this.sessionId = null;   }   /**    * Accessing the xmlBlaster handle.    * For internal use, throws an ordinary Exception if xmlBlaster==null    * We use this for similar handling as org.omg exceptions.    * @return Server    */   private I_XmlBlaster getXmlBlaster() throws XmlBlasterException {      if (this.blasterServer == null) {         if (log.isLoggable(Level.FINE)) log.fine("No RMI connection available.");         throw new XmlBlasterException(glob, ErrorCode.COMMUNICATION_NOCONNECTION, ME,                                       "The RMI xmlBlaster handle is null, no connection available");      }      return this.blasterServer;   }   /**    * @return The connection protocol name "RMI"    */   public final String getProtocol() {      return "RMI";   }   /**    * Login to the server.     * <p />    * @param connectQos The encrypted connect QoS     * @exception   XmlBlasterException if login fails    */   public String connect(String connectQos) throws XmlBlasterException {      if (connectQos == null)         throw new XmlBlasterException(ME+".connect()", "Please specify a valid QoS");      if (log.isLoggable(Level.FINER)) log.finer("connect() ...");      if (this.sessionId != null) {         log.warning("You are already logged in.");         return "";      }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -