• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How ejb-ref works, when we have to ejb's deployed on two diffrent machines???

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As per the SCBCD book and Also Mastering EJB..

The <ejb-ref> tag is used by the Bean Provider to indicate a psuedo name to the assembler, that he is referring to a EJB in his code. And then it is the responsibilty if the App Assembler to map that psuedo name to the actual EJB's jndi name on the container.

Also by using the <ejb-ref> tag, the developer can directly use the following code..

Context c = new InitialContext();

Here in the InitialContext() the developer need not pass any parameter to specify the jdni factory and server name.

This way the code becomes deployable to any container as no specific env. values are passed in the InitialContext().

Now the question is --

Consider the scenario, i have a Address EJB deployed on a container on machine A. And there is another EJB Customer referring to Address, this Customer EJB is deployed in a container on machine B.

In the code of Customer the developer has used --
Context c = new InitialContext();
for accessing the Address EJB.

And he has specified an <ejb-ref> element for the Customer EJB.

Bean devloper is not passing any info to InitialContext(), and also in the ejb-jar.xml file, for the <ejb-ref> of Customer we do not have any tag which says on which machine the Address EJB is deployed.

Also during deployment the deployer only gives maps the psuedo name of <ejb-ref> to the JNDI name of the referenced EJB. He also not specifies the machine name and address.

So how this <ejb-ref> works, when we have to ejb's deployed on two diffrent machines and One want to use the other?

I hope all the above explanation makes sense, even if not, please help me in knowing the <ejb-ref> element better.
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This just won't work for the following reason (EJB 2.0 spec, section 20.3):


The deployment descriptor also allows the Application Assembler to link an EJB reference declared in one enterprise bean to another enterprise bean contained in the same ejb-jar file, or in another ejb-jar file in the same J2EE application unit. The link is an instruction to the tools used by the Deployer that the EJB reference should be bound to the home of the specified target enterprise bean.



Given that your beans Address and Customer are on two different machines, it means that they are part of two different J2EE applications deployed on each machine and thus the rule mentioned above is not satisfied.

Hope this helps
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
...even if not, please help me in knowing the <ejb-ref> element better.

(1) BeanProvider sanjivcts is implementing the Customer EJB. He is using the Address EJB that is provided by BeanProvider Severin, and he's referring to this bean under the name <ejb-ref-name>ejb/Address<ejb-ref-name>.

(2) BeanProvider Severin is implementing the Address EJB, he's publishing the Bean under the name <ejb-name>CustomerAddresses<ejb-name>

they don't know each other

(3) AppAssembler Valentin links Severin's implementation to sanjivcts, using the <ejb-link>CustomerAddresses<ejb-link> tag in the <ejb-ref>


makes sense?

Severin
 
Valentin Crettaz
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, it is possible for one bean to access another on a different machine and here is how

I have never tried it, though...

Hope this helps
 
Forget Steve. Look at this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic