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

📄 orbinstancefactory.java

📁 java开源的企业总线.xmlBlaster
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
   }   /**    * Get (or create) an OrbInstanceWrapper object which is useful to handle one    * CORBA orb instance with reference counting    * @param glob    * @param prefix A unique identifier for the orb, using the same prefix will return    *   the same orb on second and further calls    */   public static OrbInstanceWrapper getOrbInstanceWrapper(Global glob, String prefix) {      if (glob == null) throw new IllegalArgumentException("You called OrbInstanceFactory.getOrbInstanceWrapper() with glob==null");      synchronized (glob) {         OrbInstanceWrapper orbInstanceWrapper =               (OrbInstanceWrapper)glob.getObjectEntry(prefix+":org.xmlBlaster.util.protocol.corba.OrbInstanceWrapper");         if (orbInstanceWrapper == null) {            orbInstanceWrapper = new OrbInstanceWrapper(glob);            glob.addObjectEntry(prefix+":org.xmlBlaster.util.protocol.corba.OrbInstanceWrapper", orbInstanceWrapper);         }         return orbInstanceWrapper;      }   }   /**    * Obtain the host information from the given CORBA object.    * This is accomplished by parsing the object's IOR using CORBA classes    * org.omg.IOP.IORHelper and org.omg.IIOP.ProfileBody_1_1Helper.    * Consequently, CORBA version is 2.x (or higher) is required.    * @param obj the CORBA object to interrogate    * @param orb the ORB to use during interrogation    * @returns the host where the given object resides, or null on error.    * @author Code from adavis@cadrc.calpoly.edu from JacORB mailing list    */   public static String extractHost(org.omg.CORBA.Object obj, org.omg.CORBA.ORB orb)   {      String host = null;      if ( obj != null && orb != null )      {         try         {            String objRef = orb.object_to_string(obj);            org.omg.CORBA.portable.OutputStream out =               orb.create_output_stream();            int cnt = (objRef.length() - 4) / 2;            int o1;            int o2;            Integer b;            for (int i=0; i<cnt; i++)            {               o1 = i*2+4;               o2 = o1+2;               try               {                  b = Integer.valueOf(objRef.substring(o1,o2), 16);                  out.write_octet(b.byteValue());               }               catch (NumberFormatException nfe)               {                  //ErrorLog.logWarning("ObjectUtil", "extractHost",                  //   "'"+objRef.substring(o1,o2)+"' not a valid integer");                  throw nfe;               }            }            org.omg.CORBA.portable.InputStream in = out.create_input_stream();            /*boolean littleEndian =*/ in.read_boolean();            org.omg.IOP.IOR ior = org.omg.IOP.IORHelper.read(in);            org.omg.IIOP.ProfileBody_1_1 body;            for (int i=0; host==null && i<ior.profiles.length; i++)            {               if ( ior.profiles[i].tag == org.omg.IOP.TAG_INTERNET_IOP.value )               {                  org.omg.CORBA.portable.OutputStream prof_out =                     orb.create_output_stream();                  byte[] prof_data = ior.profiles[i].profile_data;                  prof_out.write_octet_array(prof_data, 0, prof_data.length);                  org.omg.CORBA.portable.InputStream prof_in =                     prof_out.create_input_stream();                  body = org.omg.IIOP.ProfileBody_1_1Helper.read(prof_in);                  host = body.host;               }            }         }         catch (Exception e)         {            //ErrorLog.logWarning("ObjectUtil", "extractHost",            //   "exception '"+e+"' during hostname extraction");            System.out.println("OrbInstanceFactory:" + e.toString());         }      }      return host;   }   /**    * Note: This code is not yet tested to be functional (Marcel 2003-12-12)    */   public static void startNameService(Global glob_) {      if (nameServiceStarted)         return;      final String[] s = new String[0]; // new String[]{"-p","1077"}; // See OAPort discussion below      new Thread() {         public void run() {            log.info("Starting embedded Jacorb namingService");            org.xmlBlaster.util.JdkCompatible.setSystemProperty("org.omg.CORBA.ORBClass", "org.jacorb.orb.ORB");            org.xmlBlaster.util.JdkCompatible.setSystemProperty("org.omg.CORBA.ORBSingletonClass", "org.jacorb.orb.ORBSingleton");            // This does not work as the name service will collide with our ORB:            // OAPort=7608 forces both to the same port            // So we need to let the NamingService to choose its own port            //org.xmlBlaster.util.JdkCompatible.setSystemProperty("OAPort", "7608");            org.jacorb.naming.NameServer.main(s);            // How to get the NameServer IOR?         }      }.start();      nameServiceStarted = true;      try { Thread.sleep(2000L); } catch( InterruptedException i) {}   }   /**    * Converts the internal CORBA message unit to the internal representation.    */   public static final org.xmlBlaster.util.MsgUnitRaw convert(Global glob, org.xmlBlaster.protocol.corba.serverIdl.MessageUnit mu) throws XmlBlasterException   {      return new org.xmlBlaster.util.MsgUnitRaw(mu.xmlKey, mu.content, mu.qos);   }   /**    * Converts the internal MsgUnitRaw to the CORBA message unit.    */   public static final org.xmlBlaster.protocol.corba.serverIdl.MessageUnit convert(org.xmlBlaster.util.MsgUnitRaw mu)   {      return new org.xmlBlaster.protocol.corba.serverIdl.MessageUnit(mu.getKey(), mu.getContent(), mu.getQos());   }   /**    * Converts the internal CORBA XmlBlasterException to the util.XmlBlasterException.     */   public static final org.xmlBlaster.util.XmlBlasterException convert(Global glob, org.xmlBlaster.protocol.corba.serverIdl.XmlBlasterException eCorba) {      boolean isServerSide = !glob.isServerSide();      org.xmlBlaster.util.XmlBlasterException ex =          new XmlBlasterException(glob, ErrorCode.toErrorCode(eCorba.errorCodeStr),                               eCorba.node, eCorba.location, eCorba.lang, eCorba.message, eCorba.versionInfo,                               Timestamp.valueOf(eCorba.timestampStr),                               eCorba.stackTrace, eCorba.embeddedMessage,                               eCorba.transactionInfo, isServerSide);      return ex;   }   /**    * Converts the util.XmlBlasterException to the internal CORBA XmlBlasterException.     */   public static final org.xmlBlaster.protocol.corba.serverIdl.XmlBlasterException convert(org.xmlBlaster.util.XmlBlasterException eUtil) {      return new org.xmlBlaster.protocol.corba.serverIdl.XmlBlasterException(                 eUtil.getErrorCodeStr(),                 eUtil.getNode(),                 eUtil.getLocation(),                 eUtil.getLang(),                 eUtil.getRawMessage(),                 eUtil.getVersionInfo(),                 eUtil.getTimestamp().toString(),                 eUtil.getStackTraceStr(),                 eUtil.getEmbeddedMessage(),                 eUtil.getTransactionInfo(),                 ""                 /*eUtil.isServerSide() IS MISSING */); // transform native exception to Corba exception   }   /**    * Converts the internal CORBA message unit array to the internal representation.    */   public static final org.xmlBlaster.util.MsgUnitRaw[] convert(Global glob, org.xmlBlaster.protocol.corba.serverIdl.MessageUnit[] msgUnitArr)               throws XmlBlasterException   {      // convert Corba to internal ...      org.xmlBlaster.util.MsgUnitRaw[] internalUnitArr = new org.xmlBlaster.util.MsgUnitRaw[msgUnitArr.length];      for (int ii=0; ii<msgUnitArr.length; ii++) {         internalUnitArr[ii] = OrbInstanceFactory.convert(glob, msgUnitArr[ii]);      }      return internalUnitArr;   }   /**    * Converts the internal MsgUnitRaw array to the CORBA message unit array.    */   public static final org.xmlBlaster.protocol.corba.serverIdl.MessageUnit[] convert(org.xmlBlaster.util.MsgUnitRaw[] msgUnitArr)   {      // convert internal to Corba ...      org.xmlBlaster.protocol.corba.serverIdl.MessageUnit[] corbaUnitArr = new org.xmlBlaster.protocol.corba.serverIdl.MessageUnit[msgUnitArr.length];      for (int ii=0; ii<msgUnitArr.length; ii++) {         corbaUnitArr[ii] = OrbInstanceFactory.convert(msgUnitArr[ii]);      }      return corbaUnitArr;   }   /**    * Creates a string representation of a NameService name hierarchy.     * This is useful for logging    * @return e.g. "xmlBlaster.MOM/heron.MOM"    */    public static String getString(NameComponent [] nameComponent) {      String ret = "";      for(int i=0; i<nameComponent.length; i++) {         if (i > 0) {            ret += "/";         }         ret += nameComponent[i].id + ((nameComponent[i].kind != null && nameComponent[i].kind.length()>0) ? "." + nameComponent[i].kind : "");      }      return ret;   }}

⌨️ 快捷键说明

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