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

📄 orbinstancefactory.java

📁 java开源的企业总线.xmlBlaster
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*------------------------------------------------------------------------------Name:      OrbInstanceFactory.javaProject:   xmlBlaster.orgCopyright: xmlBlaster.org, see xmlBlaster-LICENSE file------------------------------------------------------------------------------*/package org.xmlBlaster.util.protocol.corba;import java.util.logging.Logger;import java.util.logging.Level;import org.omg.CosNaming.NameComponent;import org.xmlBlaster.util.Global;import org.xmlBlaster.util.Timestamp;import org.xmlBlaster.util.XmlBlasterException;//import org.xmlBlaster.util.JdkCompatible;import java.util.Properties;import java.util.Enumeration;import org.xmlBlaster.util.def.ErrorCode;import org.xmlBlaster.util.qos.address.AddressBase;/** * OrbInstanceFactory singleton to create a CORBA orb instance.  * * Note the IANA assigned official CORBA ports: * <pre> *  corba-iiop      683/tcp    CORBA IIOP  *  corba-iiop      683/udp    CORBA IIOP  *  corba-iiop-ssl  684/tcp    CORBA IIOP SSL *  corba-iiop-ssl  684/udp    CORBA IIOP SSL *   *  corbaloc        2809/tcp   CORBA LOC *  corbaloc        2809/udp   CORBA LOC * </pre> * We use the following CORBA specific ports: * <pre> *   7608 as the default port to look for a naming service *   3412 is the xmlBlaster assigned port, used for bootstrapping (optional) * </pre> * JacORB CORBA socket:<br /> *  org.jacorb.util.Environment.getProperty("OAIAddr");<br /> *  org.jacorb.util.Environment.getProperty("OAPort"); */public final class OrbInstanceFactory{   private static Logger log = Logger.getLogger(OrbInstanceFactory.class.getName());   private static boolean first=true;   private static String origORBClass;   private static boolean nameServiceStarted;   /**    * Sets the environment for CORBA.     * <p />    * Example for JacORB:    * <pre>    *  org.omg.CORBA.ORBClass=org.jacorb.orb.ORB    *  org.omg.CORBA.ORBSingletonClass=org.jacorb.orb.ORBSingleton    *  -ORBInitRef NameService=corbaloc:iiop:localhost:7608/StandardNS/NameServer-POA/_root    * </pre>    *    * Forces to use JacORB instead of JDK internal ORB (which is outdated)    * and looks for NamingService on port 7608    *    * @param glob Handle to access logging, properties etc.    * @param address The address configuration    * @return The used properties for the ORB    */   private synchronized static Properties initializeOrbEnv(Global glob, AddressBase address)   {      glob = (glob == null) ? Global.instance() : glob;      Properties props = new Properties();      //props.put("org.omg.CORBA.ORBClass", "SomeORBImplementation");       if (first) {         first = false;         origORBClass = System.getProperty("org.omg.CORBA.ORBClass");      //   if (origORBClass==null) origORBClass=""; // System.setProperties does not like null values      //   origORBSingletonClass = System.getProperty("org.omg.CORBA.ORBSingletonClass");      //   if (origORBSingletonClass==null) origORBSingletonClass="";      }      /*      # orb.properties file for JacORB, copy to JAVA_HOME/lib      #      # Switches off the default CORBA in JDK (which is outdated),      # and replaces it with JacORB implementation      #      # JDK 1.2 checks following places to replace the builtin Orb:      #  1. check in Applet parameter or application string array, if any      #  2. check in properties parameter, if any      #  3. check in the System properties      #  4. check in the orb.properties file located in the java.home/lib directory      #  5. fall back on a hardcoded default behavior (use the Java IDL implementation)      */      /* OpenOrb:         "org.omg.CORBA.ORBClass=org.openorb.CORBA.ORB"         "org.omg.CORBA.ORBSingletonClass=org.openorb.CORBA.ORBSingleton"         java -Dorg.omg.CORBA.ORBClass=org.openorb.CORBA.ORB -Dorg.omg.CORBA.ORBSingletonClass=org.openorb.CORBA.ORBSingleton org.xmlBlaster.Main      */      // If not set, force to use JacORB instead of JDK internal ORB (which is outdated)      if (origORBClass == null || origORBClass.length() < 1) {         String tmp = glob.getProperty().get("org.omg.CORBA.ORBClass", "org.jacorb.orb.ORB");         if (tmp.length() < 1) {      // As with JDK 1.4.1 i get NPE when trying to reset System.setProperty(key, null) we use an empty string            tmp = "org.jacorb.orb.ORB";         }         //JdkCompatible.setSystemProperty("org.omg.CORBA.ORBClass", tmp);         props.put("org.omg.CORBA.ORBClass", tmp);         tmp = glob.getProperty().get("org.omg.CORBA.ORBSingletonClass", "org.jacorb.orb.ORBSingleton");         if (tmp.length() < 1) {            tmp = "org.jacorb.orb.ORBSingleton";         }         //JdkCompatible.setSystemProperty("org.omg.CORBA.ORBSingletonClass", tmp);         props.put("org.omg.CORBA.ORBSingletonClass", tmp);      }            // -dispatch/connection/plugin/ior/hostname         String hostname = address.getEnv("hostname", (String)null).getValue();      if (log.isLoggable(Level.FINE)) log.fine("initializeOrbEnv(" + address.getEnvLookupKey("hostname") + "=" + hostname);      String orbClass = (String)props.get("org.omg.CORBA.ORBClass");      if (orbClass != null && orbClass.indexOf("jacorb") >= 0) {         // Setting JacORB         if (hostname != null) {            //JdkCompatible.setSystemProperty("OAIAddr", hostname);            props.put("OAIAddr", hostname);            if (log.isLoggable(Level.FINE)) log.fine("Using OAIAddr=" + address.getEnvLookupKey("hostname") + "=" + props.getProperty("OAIAddr"));         }                  int port = address.getEnv("port", 0).getValue();         if (port > 0) {            //JdkCompatible.setSystemProperty("OAPort", ""+port);            props.put("OAPort", ""+port);            if (log.isLoggable(Level.FINE)) log.fine("Using OAPort=" + address.getEnvLookupKey("port") + "=" + props.getProperty("OAPort"));         }         int verbose = glob.getProperty().get("jacorb.log.default.verbosity", -1);         if (verbose >= 0) {            //JdkCompatible.setSystemProperty("jacorb.log.default.verbosity", ""+verbose);            props.put("jacorb.log.default.verbosity", ""+verbose);            if (log.isLoggable(Level.FINE)) log.fine("Using jacorb.log.default.verbosity=" + props.getProperty("jacorb.log.default.verbosity"));         }         // Bug workaround: with JacORB 2.1 we get logging from POA,         // Setting jacorb.poa.log.verbosity=0 in jacorb.properties does not help         // setting ' java -Djacorb.poa.log.verbosity=0 ... ' helps:         int verbosePoa = glob.getProperty().get("jacorb.poa.log.verbosity", 0);         props.put("jacorb.poa.log.verbosity", ""+verbosePoa);         if (log.isLoggable(Level.FINE)) log.fine("Using jacorb.poa.log.verbosity=" + verbosePoa);      }      if (log.isLoggable(Level.FINE)) log.fine("Using org.omg.CORBA.ORBClass=" + props.getProperty("org.omg.CORBA.ORBClass"));      if (log.isLoggable(Level.FINE)) log.fine("Using org.omg.CORBA.ORBSingletonClass=" + props.getProperty("org.omg.CORBA.ORBSingletonClass"));      /*      CHANGED 2003-02-27 Marcel:      The jacorb.properties file has no impact anymore if we set the System.properties      // We use default Port 7608 for naming service to listen ...      // Start Naming service      //    jaco -DOAPort=7608  org.jacorb.naming.NameServer /tmp/ns.ior      // and xmlBlaster will find it automatically if on same host      */      if (glob.getProperty().get("ORBInitRef", (String)null) != null) {         String tmp = glob.getProperty().get("ORBInitRef", "NameService=corbaloc:iiop:localhost:7608/StandardNS/NameServer-POA/_root");         // -ORBInitRef "NameService=corbaloc:iiop:localhost:7608/StandardNS/NameServer-POA/_root"         //JdkCompatible.setSystemProperty("ORBInitRef", tmp);         props.put("ORBInitRef", tmp);         if (log.isLoggable(Level.FINE)) log.fine("Using corbaloc -ORBInitRef NameService="+glob.getProperty().get("ORBInitRef",(String)null)+" to find a naming service");      }      return props;   }   /**    * @param glob    * @param args command line args, see org.omg.CORBA.ORB.init(), use glob.getProperty().getProperties()    * @param props application-specific properties; may be <code>null</code>, see org.omg.CORBA.ORB.init(String[], Properties)    * @param address The address configuration    * @return Access to a new created orb handle    * @see org.omg.CORBA.ORB#init(String[], Properties)    */   public static org.omg.CORBA.ORB createOrbInstance(Global glob, String[] args, Properties props, AddressBase address) {      synchronized (System.class) {         Properties properties = initializeOrbEnv(glob, address);         if (props != null) {            Enumeration e = props.propertyNames();            while (e.hasMoreElements()) {               String key = (String)e.nextElement();               properties.put(key, props.get(key));            }         }         org.omg.CORBA.ORB anOrb = org.omg.CORBA.ORB.init(args, properties);         /*         if (origORBClass != null) {            JdkCompatible.setSystemProperty("org.omg.CORBA.ORBClass", origORBClass);         }         if (origORBSingletonClass != null) {            JdkCompatible.setSystemProperty("org.omg.CORBA.ORBSingletonClass", origORBSingletonClass);         }         */         boolean startNamingService = glob.getProperty().get("plugin/ior/useNameService", false);         if (startNamingService) {            startNameService(glob);         }         return anOrb;      }

⌨️ 快捷键说明

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