[转]javax.rmi.PortableRemoteObject.narrow方法的用途
2011-04-21 22:48
351 查看
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 ?
转自:http://blog.csdn.net/realmud/archive/2004/06/23/23896.aspx
(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 ?
转自:http://blog.csdn.net/realmud/archive/2004/06/23/23896.aspx
相关文章推荐
- javax.rmi.PortableRemoteObject.narrow
- PortableRemoteObject.narrow方法杂谈
- 在远程lookup一个EJB后,要调用PortableRemoteObject.narrow去强制转换
- Discuss about PortableRemoteObject.narrow()
- WebSocket使用javax.websocket.RemoteEndpoint.Basic.sendObject(Object arg0)向页面方法发送对象
- Java中Object.clone方法的用途
- 一个remoteobject调用多个java方法(Flex)
- 关于Flex与Spring整合RemoteObject调用Java方法找不到自定义通道的解决方法
- Spring之RMI 远程方法调用 (Remote Method Invocation)
- Flex Remote Object中直接使用HttpSession的方法
- Weblogic - Failed to bind remote object 错误解决方法
- Flex3在应用RemoteObject出现问题解决方法
- Flex一个RemoteObject调用JAVA对象里面的多个方法(转)
- Flex与后台交互的4种方法 URLLoader、HTTPService、WebService、RemoteObject使用示例
- Flex3在应用RemoteObject出现问题解决方法
- 一个remoteobject调用多个java方法(Actionscript)
- Flex一个RemoteObject调用JAVA对象里面的多个方法
- Weblogic - Failed to bind remote object 错误解决方法
- flex RemoteObject 的两种使用方法
- Flex RemoteObject 限制远程Java对象可访问方法