• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why client-->home-->remote in EJB

 
Naveen Chandra
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi EJB Gurus,
Could some please help me in clarifying my doubt here.
Why does client access an Enterprise JavaBean
by looking up the class implementing its home interface
by name through JNDI and then uses the methods
of home interface to acquire access to
an instance of the class implementing the remote interface ?
Why cannot client access the remote interface directly ?
By doing this client --> EJBHome --> EJBObject
in the EJB architecture what advantage they get ?
It seems I am fully confused now with the EJB implementaion ?
And why did they kept all business methods in the Remote interface and
create and finders in home interface. I think I may be asking
very silly questions, but it really makes me too confusing to
understand the EJB architecture and its implementaion.
Please help me to understand better the EJB architecture.
Thanks,
Naveen.
 
pilania
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am no guru but still i will try to explain why is it the way it is
first of all EJB works the same way as RMI.
by using jndi service and looking up home interface makes the object location transparent to user/client. that means the object may very well be on your machine or it may well be on a networked machine 1000s of miles aways, making it the "Enterprise" bean in true sense of the word.
hope it helps
:
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please note that The Java Ranch has a naming policy, described here and "pilania" is not a valid name. Please choose one which meets the requirements.
Thanks.
 
Carl Desborough
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hmmm good question .... i think its a sensible separation of responsibilities ...
the remote interface represents a particular business object (instance) and has methods for things you might want to do to that object, eg [account for Mr Davis.addMoney()],[account for Mr Jones.subtractMoney()].
the home interface represents a directory/factory of all the business objects of that type, eg. [bank.give me Mr Davis's account()]
There are probably technical issues behind it too, but from an object modelling point of view, the above separation of responsibilities makes sense to me.
 
Venkat Ammisetty
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Naveen
I don't think that question is silly.
The bottom line of EJB architecture is Distributed Nature.
That is one reason we require client-->home-->remote classes.
You imagen a situation where you are calling your bean from JSP ,in doing this you will use JNDI name,this JNDI name is the heart to find your bean where it located.
i.e. Your JSP may reside on one system and Bean on another system.But by this JNDI, the Server will find the bean in distributed world.
That's why they were gone for division of client-->home-->remote.
It's really good arvhitecture,you will know once you do real application.
Bye
Venkat
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Naveen Chandra:
Hi EJB Gurus,
Why does client access an Enterprise JavaBean [via the home interface]? Why cannot client access the remote interface directly ?

I'm missing something simple in the answers so far.
"Access the remote interface directly..." What remote interface? The remote object you want to talk to might not exist in the first place.
No instance, no accessible interface.
And even if it does, there may be many instances of its kind, so how should the relevant instance be bound in the nameserver (be it JNDI or RMI) so you can actually find and access it?
What you need is a factory/finder object that will always exist and be bound under a known name, so that you can use it to create or find the beans you need. You need the home interface.
Sun probably could've used an RMI nameserver to bind the home interface, but JNDI is much more flexible and powerful.
Peter
 
SRINI VASAN
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,
With my littel knowledge i guess i can help..

I would start with a story.. well! In our place there is a xerox shop which almost photocopies all the book & gives u at 1/4 of original. well ! buyers will tempted for getting it that that .. when there is no remarkable difference .. right..

In the same way if u software is sold like the book owners , u will also lose profit.. To avoid this in EJB .. we use this client -> home -> remote -> bean ...

we ensure that all business method is with us & yet authorized client can access it .. we brake the piracy ring .. since only registerd users can use it & we know the users ...

Regards,
srini
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!