一、华为CORBA接口开发过程
流程与中兴类似:
建立连接、建立消息通道
获取名字服务
获取EMSSession工厂(注意这里传入的NameComponent参数与中兴不同)
登录并获取EMSSession
使用EMSSession初始化管理器对象
管理器对象调用接口获取数据
关闭连接
注:调用corba接口需要用到EMESession对象,如果在你的应用里要多次访问corba接口,那么多次建立连接和获取EMSSession是非常浪费服务器资源且效率低下的,并且一个corba用户名和密码在同一时间只能被一个连接使用。为了优化访问效率、避免登录冲突和减少重连开销,此处应当在服务启动时就建立连接和获取EMSSession(即步骤1、2、3、4),并不断发送心跳维持连接,在服务关闭时关闭连接即可。就这样就实现了一个corba连接的重复使用,可以用单例模式实现。
二、管理器对象定义
高层网管如果要通过U2000 CORBA接口获取数据或交互请求,必须首先获取到相应的CORBA接口管理对象,即CORBA对象,然后通过该管理对象提供的方法来交互请求。目前U2000 CORBA接口中定义的管理对象以及对应的管理对象的名字如表:
管理对象定义
管理对象名称
EMSMgr_I
“EMS”
ManagedElementMgr_I
“ManagedElement”
PerformanceManagementMgr_I
“PerformanceManagement”
待完善…
注:该管理器对象定义只适用于华为corba接口。
三、华为CORBA接口开发示例
demo github地址:https://github.com/dong706/CorbaDemo
调用ManagedElement管理器对象的获取所有网元信息接口(getAllManagedElements)示例代码:
package com.dx.corba.hw;import org.omg.CORBA.ORB;import org.omg.CORBA.SystemException;import org.omg.CosNaming.NameComponent;import org.omg.CosNaming.NamingContext;import org.omg.CosNaming.NamingContextHelper;import org.omg.CosNaming.NamingContextPackage.NotFound;import org.omg.PortableServer.POA;import org.omg.PortableServer.POAHelper;import org.omg.hw.common.Common_IHolder;import org.omg.hw.emsSession.EmsSession_I;import org.omg.hw.emsSession.EmsSession_IHolder;import org.omg.hw.emsSessionFactory.EmsSessionFactory_I;import org.omg.hw.emsSessionFactory.EmsSessionFactory_IHelper;import org.omg.hw.managedElement.ManagedElementIterator_IHolder;import org.omg.hw.managedElement.ManagedElementList_THolder;import org.omg.hw.managedElementManager.ManagedElementMgr_I;import org.omg.hw.managedElementManager.ManagedElementMgr_IHelper;import org.omg.hw.nmsSession.NmsSession_I;import org.omg.hw.nmsSession.NmsSession_IPOATie;public class HwDemo { private static EmsSession_I emsSession = null ; private static ManagedElementMgr_I meMgr = null ; public static void main (String[] args1) { Object[] objects = getEmsSession(); POA rootpoa = rootpoa = (POA) objects[0 ]; emsSession = (EmsSession_I) objects[1 ]; ORB orb = (ORB) objects[2 ]; System.out.println("EMSsession ---" + emsSession.toString()); try { System.out.println("初始化 ManagedElement 管理器!" ); Common_IHolder mgrHolder = new Common_IHolder (); emsSession.getManager("ManagedElement" , mgrHolder); meMgr = ManagedElementMgr_IHelper.narrow(mgrHolder.value); } catch (Exception pfe) { System.out .println("初始化 ManagedElement 管理器异常!---ProcessingFailureException---" ); System.out.println(pfe.toString()); } try { ManagedElementList_THolder meList = new ManagedElementList_THolder (); ManagedElementIterator_IHolder meIt = new ManagedElementIterator_IHolder (); meMgr.getAllManagedElements(100 , meList, meIt); System.out.println(meList.value.length); for (int i = 0 , size = meList.value.length; i < size; i++) { System.out.println(meList.value[i].nativeEMSName); } if (orb != null ) { orb.destroy(); } } catch (Exception e) { e.printStackTrace(); } finally { if (emsSession != null ) { emsSession.endSession(); } if (rootpoa != null ) { rootpoa.destroy(true , true ); } if (orb != null ) { orb.shutdown(true ); orb.destroy(); } System.out.println("关闭华为corba连接...." ); } } public static Object[] getEmsSession() { Object[] objects = new Object [3 ]; ORB orb = null ; EmsSession_I emsSession = null ; try { String[] args = new String [2 ]; args[0 ] = "-ORBInitRef" ; args[1 ] = "NameService=corbaloc::" + "CORBA服务器IP" + ":" + "CORBA服务器端口" + "/NameService" ; for (int i = 0 ; i < args.length; i++) { System.out.println("初始化ORB对象的启动参数为: arg[" + i + "] = " + args[i]); } orb = org.omg.CORBA.ORB.init(args, null ); System.out.println("成功初始化ORB对象!----Initialize Orb" ); } catch (SystemException ex) { System.out.println("初始化ORB对象异常!" ); System.out.println(ex.getMessage()); } if (orb == null ) { System.out.println("orb == null" ); return null ; } NamingContext nsRootContext = null ; try { org.omg.CORBA.Object objRef = orb .resolve_initial_references("NameService" ); nsRootContext = NamingContextHelper.narrow(objRef); System.out.println("成功获取取名字服务!----Get Nameservice reference" ); } catch (org.omg.CORBA.ORBPackage.InvalidName ex) { System.out.println("取名字服务索引异常!" ); ex.printStackTrace(); } if (nsRootContext == null ) { System.out.println("nsRootContext == null" ); return null ; } NameComponent[] name = new NameComponent [5 ]; name[0 ] = new NameComponent ("TMF_MTNM" , "Class" ); name[1 ] = new NameComponent ("HUAWEI" , "Vendor" ); name[2 ] = new NameComponent ("Huawei/U2000" , "EmsInstance" ); name[3 ] = new NameComponent ("2.0" , "Version" ); name[4 ] = new NameComponent ("Huawei/U2000" , "EmsSessionFactory_I" ); org.omg.CORBA.Object obj = null ; try { obj = nsRootContext.resolve(name); System.out .println("成功获取EMSSession工厂! Get Reference to EMSSessionFactory" ); } catch (NotFound ex) { System.out.println("取EMSSession工厂异常!---NotFound---" ); ex.printStackTrace(); } catch (org.omg.CosNaming.NamingContextPackage.InvalidName ex) { System.out.println("取EMSSession工厂异常!---InvalidName---" ); ex.printStackTrace(); } catch (org.omg.CosNaming.NamingContextPackage.CannotProceed ex) { System.out.println("取EMSSession工厂异常!---CannotProceed---" ); ex.printStackTrace(); } EmsSessionFactory_I m_emsFactory = EmsSessionFactory_IHelper .narrow(obj); NmsSession_I csession = null ; POA rootpoa = null ; try { System.out.println("取得rootpoa并激活POAManager!" ); rootpoa = POAHelper.narrow(orb .resolve_initial_references("RootPOA" )); rootpoa.the_POAManager().activate(); System.out.println("注册NmsSession到ORB!" ); NmsSessionImpl nmsSessionImpl = new NmsSessionImpl (); byte [] objectID = rootpoa.activate_object(nmsSessionImpl); System.out.println("创建NmsSession并且托管给POA!" ); NmsSession_IPOATie tie = new NmsSession_IPOATie (nmsSessionImpl, rootpoa); System.out.println("在orb上激活NmsSession对象!" ); csession = tie._this(orb); objects[0 ] = rootpoa; } catch (Exception ex) { System.out.println("创建NmsSession对象过程,执行异常!" ); System.out.println(ex.getMessage()); } EmsSession_IHolder sessionHolder = new EmsSession_IHolder (); try { System.out.println("获取EmsSession引用对象" ); m_emsFactory.getEmsSession("CORBA服务用户名" , "CORBA服务密码" , csession, sessionHolder); emsSession = sessionHolder.value; objects[1 ] = emsSession; } catch (org.omg.hw.globaldefs.ProcessingFailureException ex) { System.out .println("获取EmsSession引用对象,异常!---ProcessingFailureException---" ); System.out.println("可能是用户名或者密码错误,或者权限不够,或者已登陆的用户还未退出!" ); System.out.println(ex.toString()); } objects[2 ] = orb; return objects; } }