1 获得CORBA Adapter所使用的Naming Service的对象引用,
2 获得所连接的EMS所对应的在NamingService中注册用的名字,记为nameOfEms。(注:即为名字树图中的id值),id值为“ZTE/E300”,kind为“EMSFactory”.
3 根据名字树图构造name, 通过步骤1中得到的NamingService去获取EmsSessionFactory_I对象的引用。
4 获得访问EMS所需的用户名和密码后,在client端构造emsSession_I CORBA对象,并实现emsSession_I接口定义的四个方法,便于Server端能够检测通讯情况和向Client端报告事件通道的可用情况。调用EmsSessionFactory_I对象引用 的getEmsSession 方法得到EmsSession_I对象引用。
5 调用emsSession_I对象的getEventChannel()获取eventChannel。此步骤也可以省略。
6 调用emsSession_I对象的getSupportedManagers操作,获取EMS所支持的所有管理者的名称。
7 根据各个管理者的名称,调用emsSession_I对象的getManager操作,分别获取各个管理者的对象引用,以便对各个管理者所提供的方法进行操作。
8 对于通知上报:client端需实现StructuredPushConsumer对象,同时可以设置过滤条件。过滤条件的设置必须符合CORBA 2.3的通知服务规范,然后调用管理者“Subscriber”对象提供的subscribe方法。以上就完成了某个通知的订阅。若要暂停或停止通知订阅的话,可以根据先前返回的订阅ID,调用“Subscriber”对象的suspendSubscription和unsubscribe方法。
| package com.zte.application.idl;
 import nmsSession.NmsSession_I;
 
 import nmsSession.NmsSession_IPOATie;
 
 import org.omg.CORBA.IntHolder;
 
 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.CosNotifyComm.StructuredPushConsumerHelper;
 
 import org.omg.PortableServer.POA;
 
 import org.omg.PortableServer.POAHelper;
 
 import org.omg.PortableServer.POAPackage.WrongPolicy;
 
 import subscription.EMSSubscriptionMgr_I;
 
 import subscription.EMSSubscriptionMgr_IHelper;
 
 import common.Common_IHolder;
 
 import emsMgr.EMSMgr_I;
 
 import emsMgr.EMSMgr_IHelper;
 
 import emsSession.EmsSession_I;
 
 import emsSession.EmsSession_IHolder;
 
 import emsSession.EmsSession_IPackage.managerNames_THolder;
 
 import emsSessionFactory.EmsSessionFactory_I;
 
 import emsSessionFactory.EmsSessionFactory_IHelper;
 
 import globaldefs.ProcessingFailureException;
 
 import managedElement.ManagedElementList_THolder;
 
 import managedElementManager.ManagedElementMgr_I;
 
 import managedElementManager.ManagedElementMgr_IHelper;
 
 public class test
 
 {
 
 static ORB orb;
 
 static EMSMgr_I emsMgr = null;
 
 static EmsSession_I emsSession=null;
 
 s
 
 tatic ManagedElementMgr_I meMgr = null;
 
 static EMSSubscriptionMgr_I emsSpMgr = null;
 
 public static boolean testTai()
 
 {
 
 //建立连接登录、建立消息通道
 
 try {
 
 String[] args = new String[2];
 
 args[0] = "-ORBInitRef";
 
 args[1] = "NameService=corbaloc::" + "10.217.1.1" + ":" + "6004" + "/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 false;
 
 }
 
 // Get Nameservice reference
 
 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("取名字服务索引异常!");
 
 System.out.println(ex.getMessage());
 
 }
 
 // 3.1 Get Reference to EMSSessionFactory
 
 NameComponent[] name = new NameComponent[1];
 
 name[0] = new NameComponent("ZTE/E300", "EMSFactory");
 
 System.out.println("NameComponent: '" + "ZTE/E300 "+ "','EMSFactory'");
 
 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---");
 
 System.out.println(ex.getMessage());
 
 }
 
 catch (org.omg.CosNaming.NamingContextPackage.InvalidName ex) {
 
 System.out.println("取EMSSession工厂异常!---InvalidName---");
 
 System.out.println(ex.getMessage());
 
 }
 
 catch (org.omg.CosNaming.NamingContextPackage.CannotProceed ex) {
 
 System.out.println("取EMSSession工厂异常!---CannotProceed---");
 
 System.out.println(ex.getMessage());
 
 }
 
 //开始准备登陆并且获取EmsSession!
 
 EmsSessionFactory_I m_emsFactory = EmsSessionFactory_IHelper.narrow(obj);
 
 NmsSession_I csession = null;
 
 POA rootpoa = null;
 
 try {
 
 // get reference to rootpoa & activate the POAManager
 
 System.out.println("取得rootpoa并激活POAManager!");
 
 rootpoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
 
 rootpoa.the_POAManager().activate();
 
 // create servant and register it with the ORB
 
 System.out.println("注册NmsSession到ORB!");
 
 NmsSessionImpl nmsSessionImpl = new NmsSessionImpl();
 
 // nmsSessionImpl.setORB(orb);
 
 byte [] objectID=rootpoa.activate_object(nmsSessionImpl);
 
 // create a tie, with servant b
 
 eing the delegate.
 
 System.out.println("创建NmsSession并且托管给POA!");
 
 NmsSession_IPOATie tie = new NmsSession_IPOATie(nmsSessionImpl,
 
 rootpoa);
 
 // obtain the objectRef for the tie
 
 // this step also implicitly activates the the object
 
 System.out.println("在orb上激活NmsSession对象!");
 
 csession = tie._this(orb);
 
 }
 
 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("root","", csession, sessionHolder);
 
 System.out.println("NMSsession ---" + csession.toString());
 
 }
 
 catch (globaldefs.ProcessingFailureException ex) {
 
 System.out.println("获取EmsSession引用对象,异常!---ProcessingFailureException---");
 
 System.out.println("可能是用户名或者密码错误,或者权限不够,或者已登陆的用户还未退出!");
 
 System.out.println(ex.toString());
 
 }
 
 emsSession = sessionHolder.value;
 
 System.out.println("EMSsession ---" + emsSession.toString());
 
 //获得所支持的管理器
 
 try {
 
 managerNames_THolder mgrHolder = new managerNames_THolder();
 
 emsSession.getSupportedManagers(mgrHolder);
 
 String[] manages = mgrHolder.value;
 
 for (int i = 0; i < manages.length; i++) {
 
 System.out.println("管理器--Manager " + i + " " + manages[i]);
 
 }
 
 }
 
 catch (ProcessingFailureException pfe) {
 
 System.out.println("获得所支持的管理器,异常!---ProcessingFailureException---");
 
 System.out.println(pfe.toString());
 
 }
 
 emsSession.ping();
 
 // 初始化 ManagedElement 管理器
 
 try {
 
 System.out.println("初始化 ManagedElement 管理器!");
 
 Common_IHolder mgrHolder = new Common_IHolder();
 
 emsSession.getManager("ManagedElement", mgrHolder);
 
 meMgr = ManagedElementMgr_IHelper.narrow(mgrHolder.value);
 
 }
 
 catch (ProcessingFailureException pfe) {
 
 System.out.println(
 
 初始化 ManagedElement 管理器异常!---ProcessingFailureException---);
 
 System.out.println(pfe.toString());
 
 }
 
 // 初始化 EquipmentInventory 管理器
 
 // try {
 
 // System.out.println("初始化 EquipmentInventory 管理器!");
 
 // Common_IHolder mgrHolder = new Common_IHolder();
 
 // emsSession.getManager("EquipmentInventory", mgrHolder);
 
 // eiMgr = EquipmentInventoryMgr_IHelper.narrow(mgrHolder.value);
 
 // }
 
 // catch (ProcessingFailureException pfe) {
 
 // System.out.println(
 
 // 初始化 EquipmentInventory 管理器异常!---ProcessingFailureException---);
 
 // System.out.println(pfe);
 
 // }
 
 // 初始化 MultiLayerSubnetwork 管理器
 
 // try {
 
 // System.out.println("初始化 MultiLayerSubnetwork 管理器!");
 
 // Common_IHolder mgrHolder = new Common_IHolder();
 
 // emsSession.getManager("MultiLayerSubnetw
 
 ork", mgrHolder);
 
 // mlsMgr = MultiLayerSubnetworkMgr_IHelper.narrow(mgrHolder.value);
 
 // // mlsMgr.getAllSubnetworkConnections();
 
 // }
 
 // catch (ProcessingFailureException pfe) {
 
 // System.out.println(
 
 // 初始化 MultiLayerSubnetwork 管理器异常!---ProcessingFailureException---);
 
 // System.out.println(pfe);
 
 // }
 
 // 初始化 EMS 管理器
 
 try {
 
 System.out.println("初始化 EMS 管理器!");
 
 Common_IHolder mgrHolder = new Common_IHolder();
 
 emsSession.getManager("EMS", mgrHolder);
 
 emsMgr = EMSMgr_IHelper.narrow(mgrHolder.value);
 
 System.out.println("EMS_Manager To String ---" + emsMgr.toString());
 
 }
 
 catch (ProcessingFailureException pfe) {
 
 System.out.println("初始化 EMS 管理器异常!---ProcessingFailureException---");
 
 System.out.println(pfe.toString());
 
 }
 
 //初始化事件信道管理器(注意这是非标准的自定义管理器!!!!)
 
 try {
 
 System.out.println("初始化事件信道管理器!");
 
 //我方在IDL中定义的一个基类
 
 Common_IHolder mgrHolder = new Common_IHolder();
 
 //获取注册通道管理者(这个对象我方在IDL定义的一个接口)
 
 emsSession.getManager("Subscriber", mgrHolder);
 
 emsSpMgr = EMSSubscriptionMgr_IHelper.narrow(mgrHolder.value);
 
 System.out.println("EMSSubscriptionMgr To String ---" + emsSpMgr.toString());
 
 }
 
 catch (ProcessingFailureException pfe) {
 
 System.out.println("初始化事件信道管理器!---ProcessingFailureException---");
 
 System.out.println(pfe.toString());
 
 }
 
 //
 
 try{
 
 initEvent(emsMgr, rootpoa);
 
 }catch(Exception e){
 
 e.printStackTrace();
 
 }
 
 return true;
 
 }
 
 private static void initEvent(EMSMgr_I emsMgr, POA rootpoa) {
 
 // 通过远程对象获取网元信息
 
 ManagedElementList_THolder meList = null;
 
 try {
 
 meList = new ManagedElementList_THolder();
 
 meMgr.getAllManagedElements(meList);
 
 for(int i=0,size=meList.value.length;i<size;i++)
 
 {
 
 System.out.println(meList.value[i].name[1].value);
 
 }
 
 System.out.println("获得节点列表!");
 
 }
 
 catch (ProcessingFailureException ex) {
 
 System.out.println(ex.toString());
 
 }
 
 }
 
 public static void main(String args[]) {
 
 try {
 
 test ss = new test();
 
 ss.testTai();
 
 } catch (Exception e) {
 
 e.printStackTrace();
 
 }
 
 }
 
 |