EJB design: javax.rmi.PortableRemoteObject.narrow

  1. javax.rmi.PortableRemoteObject.narrow (6 messages)

    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

    Threaded Messages (6)

  2. javax.rmi.PortableRemoteObject.narrow[ Go to top ]

    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.
  3. javax.rmi.PortableRemoteObject.narrow[ Go to top ]

    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.

  4. javax.rmi.PortableRemoteObject.narrow[ Go to top ]

    Thank you very mutch.
  5. javax.rmi.PortableRemoteObject.narrow[ Go to top ]

    just an other question: when an application server work with remote java object like ejb, does it use necessarly and only JRMP ?
    Is RMI/IIOP used by the client only in the case of the remote object "work" with IIOP protocole?
    Thank you
  6. javax.rmi.PortableRemoteObject.narrow[ Go to top ]

    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.

  7. javax.rmi.PortableRemoteObject.narrow[ Go to top ]

    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 ( 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