当前位置:   article > 正文

Corba开发总结(四)---华为CORBA接口开发

华为 corba

一、华为CORBA接口开发过程

     流程与中兴类似:

  1. 建立连接、建立消息通道
  2. 获取名字服务
  3. 获取EMSSession工厂(注意这里传入的NameComponent参数与中兴不同)
  4. 登录并获取EMSSession
  5. 使用EMSSession初始化管理器对象
  6. 管理器对象调用接口获取数据
  7. 关闭连接

 

     注:调用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码云地址:https://gitee.com/dx/CorbaDemo

 

调用ManagedElement管理器对象的获取所有网元信息接口(getAllManagedElements)示例代码:

  1. package com.dx.corba.hw;
  2. import org.omg.CORBA.ORB;
  3. import org.omg.CORBA.SystemException;
  4. import org.omg.CosNaming.NameComponent;
  5. import org.omg.CosNaming.NamingContext;
  6. import org.omg.CosNaming.NamingContextHelper;
  7. import org.omg.CosNaming.NamingContextPackage.NotFound;
  8. import org.omg.PortableServer.POA;
  9. import org.omg.PortableServer.POAHelper;
  10. import org.omg.hw.common.Common_IHolder;
  11. import org.omg.hw.emsSession.EmsSession_I;
  12. import org.omg.hw.emsSession.EmsSession_IHolder;
  13. import org.omg.hw.emsSessionFactory.EmsSessionFactory_I;
  14. import org.omg.hw.emsSessionFactory.EmsSessionFactory_IHelper;
  15. import org.omg.hw.managedElement.ManagedElementIterator_IHolder;
  16. import org.omg.hw.managedElement.ManagedElementList_THolder;
  17. import org.omg.hw.managedElementManager.ManagedElementMgr_I;
  18. import org.omg.hw.managedElementManager.ManagedElementMgr_IHelper;
  19. import org.omg.hw.nmsSession.NmsSession_I;
  20. import org.omg.hw.nmsSession.NmsSession_IPOATie;
  21. /**
  22. *
  23. * Module: HelloClient.java Description: 客户端的初始化以及调用的代码 Company: Version: 1.0.0
  24. * Author: pantp Date: Jul 8, 2012
  25. */
  26. public class HwDemo {
  27. private static EmsSession_I emsSession = null;
  28. private static ManagedElementMgr_I meMgr = null;
  29. public static void main(String[] args1) {
  30. Object[] objects = getEmsSession();
  31. POA rootpoa = rootpoa = (POA) objects[0];
  32. emsSession = (EmsSession_I) objects[1];
  33. ORB orb = (ORB) objects[2];
  34. System.out.println("EMSsession ---" + emsSession.toString());
  35. try {
  36. System.out.println("初始化 ManagedElement 管理器!");
  37. Common_IHolder mgrHolder = new Common_IHolder();
  38. emsSession.getManager("ManagedElement", mgrHolder);
  39. meMgr = ManagedElementMgr_IHelper.narrow(mgrHolder.value);
  40. } catch (Exception pfe) {
  41. System.out
  42. .println("初始化 ManagedElement 管理器异常!---ProcessingFailureException---");
  43. System.out.println(pfe.toString());
  44. }
  45. try {
  46. ManagedElementList_THolder meList = new ManagedElementList_THolder();
  47. ManagedElementIterator_IHolder meIt = new ManagedElementIterator_IHolder();
  48. meMgr.getAllManagedElements(100, meList, meIt);
  49. System.out.println(meList.value.length);
  50. for (int i = 0, size = meList.value.length; i < size; i++) {
  51. System.out.println(i);
  52. }
  53. meMgr._release();
  54. if (orb != null) {
  55. orb.destroy();
  56. }
  57. } catch (Exception e) {
  58. e.printStackTrace();
  59. } finally {
  60. // 关闭连接
  61. if (emsSession != null) {
  62. emsSession.endSession();
  63. }
  64. if (rootpoa != null) {
  65. rootpoa.destroy(true, true);
  66. }
  67. if (orb != null) {
  68. orb.shutdown(true);
  69. orb.destroy();
  70. }
  71. System.out.println("关闭华为corba连接....");
  72. }
  73. }
  74. public static Object[] getEmsSession() {
  75. Object[] objects = new Object[3];
  76. ORB orb = null;
  77. EmsSession_I emsSession = null;
  78. // 建立连接登录、建立消息通道
  79. try {
  80. String[] args = new String[2];
  81. args[0] = "-ORBInitRef";
  82. args[1] = "NameService=corbaloc::" + "CORBA服务器IP" + ":" + "CORBA服务器端口"
  83. + "/NameService";// 此处使用命名端口
  84. for (int i = 0; i < args.length; i++) {
  85. System.out.println("初始化ORB对象的启动参数为: arg[" + i + "] = "
  86. + args[i]);
  87. }
  88. orb = org.omg.CORBA.ORB.init(args, null);
  89. System.out.println("成功初始化ORB对象!----Initialize Orb");
  90. } catch (SystemException ex) {
  91. System.out.println("初始化ORB对象异常!");
  92. System.out.println(ex.getMessage());
  93. }
  94. if (orb == null) {
  95. System.out.println("orb == null");
  96. return null;
  97. }
  98. // Get Nameservice reference
  99. NamingContext nsRootContext = null;
  100. try {
  101. org.omg.CORBA.Object objRef = orb
  102. .resolve_initial_references("NameService");
  103. nsRootContext = NamingContextHelper.narrow(objRef);
  104. System.out.println("成功获取取名字服务!----Get Nameservice reference");
  105. } catch (org.omg.CORBA.ORBPackage.InvalidName ex) {
  106. System.out.println("取名字服务索引异常!");
  107. ex.printStackTrace();
  108. }
  109. if (nsRootContext == null) {
  110. System.out.println("nsRootContext == null");
  111. return null;
  112. }
  113. // 3.1 Get Reference to EMSSessionFactory
  114. /*
  115. * org.omg.CORBA.Object obj = null; NameComponent[] name = new
  116. * NameComponent[1]; name[0] = new
  117. * NameComponent(strConfigEmsFactoryName, "EMSFactory"); obj =
  118. * nsRootContext.resolve(name); EmsSessionFactory_I emsSessionFactory =
  119. * EmsSessionFactory_IHelper.narrow(obj);
  120. */
  121. NameComponent[] name = new NameComponent[5];
  122. name[0] = new NameComponent("TMF_MTNM", "Class");
  123. name[1] = new NameComponent("HUAWEI", "Vendor");
  124. name[2] = new NameComponent("Huawei/U2000", "EmsInstance");
  125. name[3] = new NameComponent("2.0", "Version");
  126. name[4] = new NameComponent("Huawei/U2000", "EmsSessionFactory_I");
  127. // System.out.println("NameComponent: '" + "ZTE/T3 " +
  128. // "','EMSFactory'");
  129. org.omg.CORBA.Object obj = null;
  130. try {
  131. obj = nsRootContext.resolve(name);
  132. System.out
  133. .println("成功获取EMSSession工厂! Get Reference to EMSSessionFactory");
  134. } catch (NotFound ex) {
  135. System.out.println("取EMSSession工厂异常!---NotFound---");
  136. ex.printStackTrace();
  137. } catch (org.omg.CosNaming.NamingContextPackage.InvalidName ex) {
  138. System.out.println("取EMSSession工厂异常!---InvalidName---");
  139. ex.printStackTrace();
  140. } catch (org.omg.CosNaming.NamingContextPackage.CannotProceed ex) {
  141. System.out.println("取EMSSession工厂异常!---CannotProceed---");
  142. ex.printStackTrace();
  143. }
  144. // 开始准备登陆并且获取EmsSession!
  145. EmsSessionFactory_I m_emsFactory = EmsSessionFactory_IHelper
  146. .narrow(obj);
  147. NmsSession_I csession = null;
  148. POA rootpoa = null;
  149. try {
  150. // get reference to rootpoa & activate the POAManager
  151. System.out.println("取得rootpoa并激活POAManager!");
  152. rootpoa = POAHelper.narrow(orb
  153. .resolve_initial_references("RootPOA"));
  154. rootpoa.the_POAManager().activate();
  155. // create servant and register it with the ORB
  156. System.out.println("注册NmsSession到ORB!");
  157. NmsSessionImpl nmsSessionImpl = new NmsSessionImpl();
  158. // nmsSessionImpl.setORB(orb);
  159. byte[] objectID = rootpoa.activate_object(nmsSessionImpl);
  160. // create a tie, with servant being the delegate.
  161. System.out.println("创建NmsSession并且托管给POA!");
  162. NmsSession_IPOATie tie = new NmsSession_IPOATie(nmsSessionImpl,
  163. rootpoa);
  164. // obtain the objectRef for the tie
  165. // this step also implicitly activates the the object
  166. System.out.println("在orb上激活NmsSession对象!");
  167. csession = tie._this(orb);
  168. objects[0] = rootpoa;
  169. } catch (Exception ex) {
  170. System.out.println("创建NmsSession对象过程,执行异常!");
  171. System.out.println(ex.getMessage());
  172. }
  173. EmsSession_IHolder sessionHolder = new EmsSession_IHolder();
  174. try {
  175. System.out.println("获取EmsSession引用对象");
  176. m_emsFactory.getEmsSession("CORBA服务用户名", "CORBA服务密码", csession,
  177. sessionHolder);
  178. emsSession = sessionHolder.value;
  179. objects[1] = emsSession;
  180. // System.out.println("NMSsession ---" + csession.toString());
  181. } catch (org.omg.hw.globaldefs.ProcessingFailureException ex) {
  182. System.out
  183. .println("获取EmsSession引用对象,异常!---ProcessingFailureException---");
  184. System.out.println("可能是用户名或者密码错误,或者权限不够,或者已登陆的用户还未退出!");
  185. System.out.println(ex.toString());
  186. }
  187. objects[2] = orb;
  188. // System.out.println("EMSsession ---" + emsSession.toString());
  189. return objects;
  190. }
  191. }

 

 

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/496863
推荐阅读
相关标签
  

闽ICP备14008679号