javax.rmi.PortableRemoteObject.narrow

i am surprised because i have two ejb on two deifferent server which are communicating together via remote interface and i don't need to use javax.rmi.PortableRemoteObject.narrow to cast the stub after the looking method. I can directly doing that :
(MyRemoteHome)initial.lookup("ejb/nameOfMyEjb"); Idem with ever java client connecting to the server and using the remote EJB. I don't understand because every documents i read explain that it's necessary to use PortableRemoteObject to cast the stub. But it's seem to be not necessary when the remote object is a java object. I woul be very happy to know your point of view about that.
Thank you very much

In most of the casses, the EJBs are remotley exposed through RMI. You can have JRMP RMI and IIOP RMI. For IIOP RMI you need to do the narrowing that marshalls the IDLs (used by the IIOP) to/from java classes. JRMP RMI uses a java native protocol and no marshalling is needed, so you can directly do the casting. The narrowing on JRMP RMI it bassically does nothing, just returns the same object.

Most native Java RMI protocols (JRMP and protocols specifically designed by application servers) make use of Java's dynamic class loading to load the stub of the correct runtime type at runtime, so you can do normal casting. Protocols like IIOP that are designed to support systems with no dynamic class loading do not support this feature. So when an IIOP remote stub is returned it does not have the correct runtime type to begin with. You have to explicitly cast it to the type of stub you want.
Because EJB is designed to support IIOP (as well as JRMP and such native protocols) you have to use PortableRemoteObject.narrow if you want your code to be compliant. If you don't, then if you move to some other application server your application may stop working

In both scenarios you described both JRMP and IIOP (as well as other protocols) can be used by the server for communication. It is up to the server to decide which protocol to use. Whether you make calls from within a server of from a J2EE client, you use the stubs generated by the server. These stubs implement whatever protocol the server wants to use.
In addition, EJB servers must be capable of supporting IIOP requests (even if the server uses JRMP for normal communication) so that EJBs can be invoked by non-Java clients using CORBA.

i have read documentation about rmic compiler. If the option -iiop is chosen then stub using iiop are generated and remote proxy are no more skeleton class but tie class (http://java.sun.com/j2se/1.4.2/docs/guide/rmi-iiop/rmi_iiop_pg.html). Sun one application server uses -iiop options. So how can i cast without javax.rmi.PortableRemoteObject.narrow even if iiop seems to be used ?
thank a lot

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值