初学RMI-IIOP,在能够找到的实例中,服务器端或者客户端的实现,我看到有两种实现方式一种是用指定JNDI由cosnaming实现:大概是这样:
Properties props = new Properties();
props.put("java.naming.factory.initial","com.sun.jndi.cosnaming.CNCtxFactory");
props.put("java.naming.provider.url","iiop://url:port");
InitialContext ctx = new InitialContext(props);
ctx.rebind("jndiname",remoteobj);//服务器端
ctx.lookup("jndiname");//客户端
这种方式我理解,指定了jndi服务为cosnaming。但在一本书上看到了RMI-IIOP的另一种实现方式:
ORB orb = ORB.init(args,System.getProperties());
org.omg.CORBA.Object objref = orb.resolve_initial_reference("NamingService");
NamingContext ctx = NamingContextHelper.narrow(objref);
NameComponent path[] = new NameComponent("QUERY_SERVER_NAME");
org.omg.CORBA.Object obj = ctx.resolve(path);
RemoteInterface rmtitf = (RemoteInterface)PortableRemoteObject.narrow(obj,RemoteInterface.class);
...
大概是这样,服务器端和客户端的实现大概都经过这个过程。我不太明白,这两种实现方式有什么区别?