aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes casting home/remote object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "casting home/remote object" Watch "casting home/remote object" New topic
Author

casting home/remote object

ALaxmi Shankaran
Greenhorn

Joined: Feb 23, 2004
Posts: 26
In EJB ,while creating home object we often narrow it as

Context context = new InitialContext();
Object homeObject = context.lookup("Example");

ExampleHome examplehome = (ExampleHome)PortableRemoteObject.narrow(homeObject, ExampleHome.class);

Then in case of remote object instead of using the same way as
Example example = (Example)PortableRemoteObject.narrow(examplehome.create(), Example.class);
why the following way is preffered?
Example example = (Example)examplehome.create();

Is casting differs in these two case??
Natarajan Shankar
Ranch Hand

Joined: Jun 10, 2004
Posts: 53
Hi,
When your doing
>> ExampleHome examplehome = (ExampleHome)PortableRemoteObject.narrow
your doing a actual narrowing.

>> Example example = (Example)examplehome.create();
The above statement actually create a remote object.

So the common scnario is casting not narrowing, I hope.






ExampleHome examplehome = (ExampleHome)PortableRemoteObject.narrow(homeObject, ExampleHome.class);

Then in case of remote object instead of using the same way as
Example example = (Example)PortableRemoteObject.narrow(examplehome.create(), Example.class);
why the following way is preffered?
Example example = (Example)examplehome.create();


Best Regards<br />N.Shankar<br />SCJP, SCWCD
Natarajan Shankar
Ranch Hand

Joined: Jun 10, 2004
Posts: 53
Good, I got the real sense you mean it now.

As per the EJB Architecture the client can access only the HME object and the home is responsible to creat the EJB OBject.

>>ExampleHome examplehome = (ExampleHome)PortableRemoteObject.narrow>>(homeObject, ExampleHome.class);
So the first staement say about casting

>>Example example = (Example)PortableRemoteObject.narrow(examplehome.create(), Example.class);

Now for remote it cannot be like this since we're not CREATING EJBObject, we're getiing only the HANDLE created by EJBHOme.

>>why the following way is preffered?
>>Example example = (Example)examplehome.create();
The above staement says your creating a handle through EJBHOMe. AS we known on examplehome.create(, will call ejbCreate() to create EJBObject.

Hope you got the reason if not key-in query.
Malli Raman
Ranch Hand

Joined: Nov 07, 2001
Posts: 312
Originally posted by Natarajan Shankar:
Good, I got the real sense you mean it now.

As per the EJB Architecture the client can access only the HME object and the home is responsible to creat the EJB OBject.

>>ExampleHome examplehome = (ExampleHome)PortableRemoteObject.narrow>>(homeObject, ExampleHome.class);
So the first staement say about casting

>>Example example = (Example)PortableRemoteObject.narrow(examplehome.create(), Example.class);

Now for remote it cannot be like this since we're not CREATING EJBObject, we're getiing only the HANDLE created by EJBHOme.

>>why the following way is preffered?
>>Example example = (Example)examplehome.create();
The above staement says your creating a handle through EJBHOMe. AS we known on examplehome.create(, will call ejbCreate() to create EJBObject.

Hope you got the reason if not key-in query.


Hi

Can you please explain

1) What is the difference between EJB Handle and EJB Object Reference.

2) Does Local Interface components will have handle?



Regards,
M.S.Raman
Natarajan Shankar
Ranch Hand

Joined: Jun 10, 2004
Posts: 53
Can you please explain

>> 1) What is the difference between EJB Handle and EJB Object Reference.
Boss inthe explanation I given EJBHanle is EJB Object

>> 2) Does Local Interface components will have handle?
** Yes, while doing lookup() process, actually server will return a EJB Home stub to the client.

** Then by using that EJBHome stub client will call create() method which will return EJBObject (Remote intrface) stub to client. Then by using this stub user can invoke business methods.

3) Why we are not doing narrowing in Local EJB Home object lookup?
This question I dont understnad boss, can you explain bit more.
Malli Raman
Ranch Hand

Joined: Nov 07, 2001
Posts: 312
Originally posted by Natarajan Shankar:
Can you please explain

>> 1) What is the difference between EJB Handle and EJB Object Reference.
Boss inthe explanation I given EJBHanle is EJB Object

>> 2) Does Local Interface components will have handle?
** Yes, while doing lookup() process, actually server will return a EJB Home stub to the client.

** Then by using that EJBHome stub client will call create() method which will return EJBObject (Remote intrface) stub to client. Then by using this stub user can invoke business methods.

3) Why we are not doing narrowing in Local EJB Home object lookup?
This question I dont understnad boss, can you explain bit more.



My question is why are not using Narrowing the Home object for Local EJB Home Object Lookup.

Context context = new InitialContext();
Object homeObject = context.lookup("Example");
ExampleLocalHome exampleLocalHome = (ExampleLocalHome) homeObject; --> In this case we are not call for PortableRemoteObject.narrow() method.
Alex Sharkoff
Ranch Hand

Joined: Apr 11, 2004
Posts: 209

1) What is the difference between EJB Handle and EJB Object Reference.


EJB Object Reference is a stub - a thing that lives in a client's JVM and implements component interface. It does not have any biz logic implemented - just acts as a messenger between a client and an ejb object (eg, serialises method arguments and deserialises method result received from the remote object). The actual Remote object (i.e. EJBObject) is never sent to the client - it always lives in server's jvm.

Handle - a client calls getHandle() on an ejb object reference in order to get an object(i.e. handle) that can be serialised and then deserialised. A handle knows how to get to an original ejb object (a stub to the original ejb object). Eg, on one computer a handle is serialised and on another computer it is deserialised and then used to get an original ejb object:


Therefore, the difference bw ejb object reference and a handle is that a handle is used to get a reference to an original ejb object while an ejb object reference (i.e. stub) is used to communicate with the remote object (i.e. ejb object) over the wires.


2) Does Local Interface components will have handle?


No.
Local home and component interfaces live in the same jvm as the actual bean (i.e. ejb container's jvm) and therefore, do not have anything that has to do with the remote method invocations.
Handle on the other hand is something that a remote client uses to get access to the original remote object.



Alex (SCJP 1.4, SCBCD 1.3, SCWCD 1.4, SCJD 1.4)
Malli Raman
Ranch Hand

Joined: Nov 07, 2001
Posts: 312
Originally posted by Alex Sharkoff:


Therefore, the difference bw ejb object reference and a handle is that a handle is used to get a reference to an original ejb object while an ejb object reference (i.e. stub) is used to communicate with the remote object (i.e. ejb object) over the wires.



No.
Local home and component interfaces live in the same jvm as the actual bean (i.e. ejb container's jvm) and therefore, do not have anything that has to do with the remote method invocations.
Handle on the other hand is something that a remote client uses to get access to the original remote object.




Thanks Alex.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: casting home/remote object