package com.vci.dbsync.filesync; import java.util.HashMap; import java.util.Map; import java.util.Properties; import org.omg.CORBA.ORB; import org.omg.CORBA.ORBPackage.InvalidName; import org.omg.CosNaming.NamingContextExt; import org.omg.CosNaming.NamingContextExtHelper; import com.vci.base.common.log.ServerWithLog4j; import com.vci.base.common.resource.CommonProperties; import com.vci.corba.common.VCIError; import com.vci.corba.framework.data.PvolumeInfo; import com.vci.corba.framework.method.FrameworkService; import com.vci.corba.logon.method.LogonFactory; import com.vci.corba.logon.method.LogonFactoryHelper; import com.vci.corba.volumn.method.VolumnFactory; import com.vci.corba.volumn.method.VolumnFactoryHelper; import com.vci.corba.volumn.method.VolumnManagement; /** *
Title:
*Description:
*Copyright: Copyright (c) 2009
*Company: VCI
* @author eddie * @time 2009-4-14 * @version 1.0 */ public final class ORBHelper { private NamingContextExt _context = null; private ORB _orb = null; private VolumnManagement _volService = null; private String _strIdentity = ""; private boolean writeLogInfo = false; //private Properties _properties = new Properties(); public boolean isWriteLogInfo() { return writeLogInfo; } public ORBHelper() { this(true); } /** * 构造 NameServiceUtility 对象 * @param writeLogInfo 是否记录日志信息 */ public ORBHelper(boolean writeLogInfo) { this.writeLogInfo = writeLogInfo; } public void InitORB(String url, String identity) { if (url == null || url.isEmpty()) return; // String[] items = url.split(":"); // String host = items[0]; // String port = items[1]; // String[] args = new String[]{"ORBInitialHost=" + host, "ORBInitialPort=" + port}; // _orb = org.omg.CORBA.ORB.init(args, null); Properties properties = new Properties(); properties.put("org.omg.CORBA.ORBClass", "org.jacorb.orb.ORB"); properties.put("org.omg.CORBA.ORBSingletonClass", "org.jacorb.orb.ORBSingleton"); properties.put("jacorb.retries","0"); properties.put("jacorb.connection.client.connect_timeout", "15000"); properties.put("jacorb.connection.client.idle_timeout", "5000"); String nameService = String.format("corbaloc::%s/NameService", url); properties.put("ORBInitRef.NameService", nameService); //properties.put("org.omg.PortableInterceptor.ORBInitializerClass.initClient", "com.vci.mw.client.ClientInitializer"); //properties.put("org.omg.PortableInterceptor.ORBInitializerClass.initClient", "com.vci.mw.client.ClientInitializer"); //InitORBEnv(url); _orb = org.omg.CORBA.ORB.init(new String[0], properties); _strIdentity = identity; if (_strIdentity == null || _strIdentity.isEmpty()) _strIdentity = CommonProperties.InstanceIdentity(); if(isWriteLogInfo()){ ServerWithLog4j.logger.info("InitORB OK"); } } // private void InitORBEnv(String url) // { //// if(_properties.get("org.omg.CORBA.ORBClass") == null) { //// _properties.put("org.omg.CORBA.ORBClass","org.jacorb.orb.ORB"); //// } // // if(_properties.get("ORBInitRef.NameService") == null) { // String nameService = String.format("corbaloc::%s/NameService", url); // _properties.put("ORBInitRef.NameService", nameService); // } // //// if (_properties.get("org.omg.PortableInterceptor.ORBInitializerClass.initClient") == null) { //// _properties.put("org.omg.PortableInterceptor.ORBInitializerClass.initClient", "com.vci.mw.client.ClientInitializer"); //// } // // _properties.put("jacorb.retries", CommonProperties.getStringProperty("jacorb.retries")); // _properties.put("jacorb.connection.client.connect_timeout", CommonProperties.getStringProperty("jacorb.connection.client.connect_timeout")); // // //_strIdentity = CommonProperties.InstanceIdentity(); // if(isWriteLogInfo()){ // ServerWithLog4j.logger.info("InitOrbEnv OK"); // } // } // 初始化命名服务 public void InitNameContext() { try { if (this._orb == null) { //System.out.println("_currentORB is not null: " + _currentORB.toString()); //_orb = _currentORB; throw new Exception("The ORB is not initialized!"); } if( _context == null ){ _context = org.omg.CosNaming.NamingContextExtHelper.narrow(_orb.resolve_initial_references("NameService")); } if(isWriteLogInfo()){ ServerWithLog4j.logger.info("InitNameContext OK"); } } catch(InvalidName in) { ServerWithLog4j.logger.error(in.getMessage(), in); } catch (Exception e) { ServerWithLog4j.logger.error(e.getMessage(), e); } } public String getNameContextIOR() { return _context.toString(); } /** * 根据服务名获取卷服务,通过主corba的命名服务获取 * @param serviceName * @return * @throws Exception */ public VolumnManagement getVolumnService(String serviceName) throws Exception{ if (_volService != null) return _volService; try { VolumnFactory vf = VolumnFactoryHelper.narrow(getObjectByName(serviceName)); if (vf == null) throw new VCIError("getVolumnService fail", new String[]{""}); _volService = vf.getVolumnService(); return _volService; } catch (VCIError ve) { ve.printStackTrace(); throw ve; } } public org.omg.CORBA.Object getObjectByName(String name) throws Exception { org.omg.CORBA.Object result = null; String strObjName = this._strIdentity + name; if (_context == null) InitNameContext(); if (_context == null) return null; result = _context.resolve_str(strObjName); return result; } private Map