在远程lookup一个EJB后,要调用PortableRemoteObject.narrow去强制转换

When we execute a lookup to get the home interface of our bean, we normally use the lookup() method of the javax.naming.InitialContext interface.This method will return us an Object that needs to be casted to the home interface we've asked for. Unfortunately, this cannot be done using the normal/explicit casting [MyHome myHome = (MyHome)returnedObject].
As we have already found out, the reason is connected to CORBA. Why?
For EJB, the communication between the server and the client is based on RMI (both remote and local interfaces, in fact, do implements the java.rmi.Remote interface).
The underlying protocol that it is used for the communication is IIOP , that is part of CORBA standards. It is normally used to describe this communication system using the Java RMI over IIOP.
IIOP has not been designed for Java, but for generic languages, and this means that there are some limitations. Some languages, in fact, do not have the concept of casting.

Java RMI-IIOP provides a mechanism to narrow the the Object we have received from from our lookup, to the appropriate type. This is done through the javax.rmi.PortableRemoteObject class and, more specifically, using the narrow() method.

Just a note: when we are using the new EJB 2.0 Local Client API, you should be able to do a direct/explicit cast from the looked up Object, to the interface you need.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值