• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

casting home/remote object

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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??
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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();
 
Natarajan Shankar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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.

 
Malli Raman
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 can't take it! You are too smart for me! Here is the tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic