工欲善其事、必先厉其器,进行CORBA开发你需要选择一个ORB和一种熟悉的编程语言,对于学习者而言,omniORBpy和Python就是一对很好的组合。omniORB的官方网站(http://omniorb.sourceforge.net)上是这样介绍omniORB的:omniORB is a robust high performance CORBA ORB for C++ and Python. It is freely available under the terms of the GNU Lesser General Public License (for the libraries), and GNU General Public License (for the tools).
Example one中将对象的IOR写入文件中发布,这样做很不方便,如当服务对象的IOR改变时就要重新发布IOR。想象一下互联网中域名服务器是怎样工作的:SP申请IP地址和域名,在域名服务器注册域名;用户要访问该域名,首先到域名服务器解析其IP地址,再访问该IP地址;当SP的IP地址改变时只要在域名服务器更新注册的IP地址即可,用户端依然可以使用域名访问。对象逻辑名和CORBA命名服务,就可以类比域名和域名服务器来理解。
class OurSecretMessage(messenger__POA.SecretMessage): def __init__(self, secret_message): """Intialize with the secret message we’re going to use. """ self.secret_message = secret_message
def get_message(self): return self.secret_message
our_message = OurSecretMessage("I don’t want any spam!")
#初始化ORB、POA、POA_Manager对象 import sys from omniORB import CORBA
name_service_obj = orb.resolve_initial_references("NameService") name_service_root = name_service_obj._narrow(CosNaming.NamingContext) assert name_service_root is not None, "Failed to narrow to NamingContext."
#激活对象 message_obj = our_message._this()
#将对象绑定到逻辑名"Messenger.SecretMessage" message_name = [CosNaming.NameComponent("Messenger", "SecretMessage")] name_service_root.bind(message_name, message_obj) print "Bound the Message Object to naming service"
#获取命名服务对象,解析服务对象的逻辑名Messenger.SecretMessage name_service_obj = orb.resolve_initial_references("NameService") name_service_root = name_service_obj._narrow(CosNaming.NamingContext) assert name_service_root is not None, "Failed to narrow to NamingContext."
message_name = [CosNaming.NameComponent("Messenger", "SecretMessage")] message_obj = name_service_root.resolve(message_name) result = message_obj.get_message()
print result ---eof---
(3)、运行情况
(a)、首先启动命名服务 C:/〉omninames omniORB: Warning: the local loop back interface (127.0.0.1) is used as this server’s address. Only clients on this machine can talk to this server.
C:/Python24/Scripts/messenger〉secret_message_srv.py omniORB: Warning: the local loop back interface (127.0.0.1) is used as this server’s address. Only clients on this machine can talk to this server. Bound the Message Object to naming service Server is running … …