博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Corba开发总结(三)---基于ZTECORBA的Client程序
阅读量:6860 次
发布时间:2019-06-26

本文共 8375 字,大约阅读时间需要 27 分钟。

hot3.png

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;static 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 referenceNamingContext 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 EMSSessionFactoryNameComponent[] 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 POAManagerSystem.out.println("取得rootpoa并激活POAManager!");rootpoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));rootpoa.the_POAManager().activate();// create servant and register it with the ORBSystem.out.println("注册NmsSession到ORB!");NmsSessionImpl nmsSessionImpl = new NmsSessionImpl();// nmsSessionImpl.setORB(orb);byte [] objectID=rootpoa.activate_object(nmsSessionImpl);// create a tie, with servant being 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 objectSystem.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("MultiLayerSubnetwork", 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

 

转载于:https://my.oschina.net/dong706/blog/1785621

你可能感兴趣的文章
在Exchange 2013中重置用户密码
查看>>
什么是UTM?
查看>>
微软最新认证体系
查看>>
SQL Server 2012 开发新特性:Sequence
查看>>
集成服务入门(实验9)日志记录和邮件通知
查看>>
玩转百度即用API(5)——空气质量指数查询
查看>>
zabbix中文版安装部署及配置说明
查看>>
Redis 过期淘汰策略
查看>>
运维自动化之puppet基础应用解析(经典版)
查看>>
最新版 WordPress 3.6 “Oscar” 简体中文版介绍及下载
查看>>
golang slice 和 array的区别
查看>>
SSDT Hook的妙用-对抗ring0 inline hook
查看>>
zabbix安装和使用
查看>>
SUSE Login incorrect
查看>>
批量备份脚本
查看>>
安全尽职是企业的阿克琉斯之踵
查看>>
Apache Qpid深入介绍
查看>>
java中获得对象构造器及其构造器参数类型
查看>>
TCP/IP 2.2配置静态路由
查看>>
一个在用的Log日志工具
查看>>