java中rmi和corba的区别:
1、定义接口: rmi自己定义接口(interface) corba生成idl代码,然后使用idlj -fall name.idl生成接口和几个类文件
2、启动服务: rmi启动的是rmiregistry (port)默认1099 corba启动的是tnameserv
3、实现的继承类: rmi extends UnicastRemoteObject corba extends 运行idlj时 生成的_NameImplBase
4、实现类的rebind rmi可以直接rebind 如:Naming.rebind("rmi://localhost/meeting",meetingserver); corba需要先调用init()如: ORB orb=ORB.init(avgs,null); MOTDImpl impl=new MOTDImpl(motdFile); orb.connect(impl); org.omg.CORBA.Object objRef= orb.resolve_initial_references("NameService"); NamingContext ncRef=NamingContextHelper.narrow(objRef); NameComponent nc=new NameComponent(motdService,""); NameComponent[] path=new NameComponent[]{nc}; ncRef.rebind(path,impl);
这里corba就要麻烦很多了
5、客户端调用corba的调用跟实现类的绑定差不多如: ORB orb=ORB.init(avgs,null); org.omg.CORBA.Object objRef= orb.resolve_initial_references("NameService"); NamingContext ncRef=NamingContextHelper.narrow(objRef); NameComponent nc=new NameComponent("MessageOfTheDay",""); NameComponent path[]=new NameComponent[]{nc} ; org.omg.CORBA.Object motdObj=ncRef.resolve(path); MOTD motdRef=MOTDHelper.narrow(motdObj); System.out.println(motdRef.getMOTD()); rmi只要lookup就可以了
总的来说其实rmi和corba都差不多,都是桩和框架,两者相互竞争,但是在java中都可以相互调用。这归功于rmi_iiop. from-javaresearch.org |