Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

1 or 2 homes - Part 2

 
Thambi Rajah
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following situation.
RuleBean is a stateless session bean which calls Rule classes such as Rule1, Rule2..... etc where Rule1 and Rule2 are Java classes having only one method, execute( ). A client gets a home reference of RuleHome, home1, through a JNDI lookup. Using home1, the client gets a remote reference, rref1 and invokes runRule( ) method in RuleBean. The method runRule( ) gets a refernce (rule1) to Rule1 class and invokes the rule1.execute( ) method:

In execute ( ) method of Rule1, it needs to run another rule, Rule2. It needs another JNDI lookup for RuleHome, home2, and eventually invokes the rule2.execute( ) method.

My Question is:
Is there any way we can get rref2 from a single RuleHome reference, home1?
OR
should we always need two RuleHome references, home1 and home2, in this situation?
Thanks in advance,
Thambi
 
Anthony Watson
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stateless session beans have access to SessionContext methods that can retrieve references to their own homes or EJBObjects. The bean could pass a reference to one of these to rule1, which could use that get at rule2.
 
Thambi Rajah
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply. Unfortunately, I cannot pass the SessionContext object as reference to every rule.
As is, how many home objects are created in this situation?
Thanks in advance
Thambi
 
Anthony Watson
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I meant that you could pass the home or the EJBObject reference that you get from SessionContext to rule1.
 
Jack Zhou
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As this is a stateless session bean, what's wrong with this:
reff1.runRule(rule2)?
 
Thambi Rajah
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to Anthony Watson for your suggestion.
When I read the HFEJB book (pg. 91), I had the impression that the Container will always create a single instance of RuleHome object. However, when Rule1 class invokes the execute( ) method of Rule2, I believe that the Container will create two RuleHome instances rather than one.
Would anybody confirm exactly how many RuleHome objects are created in this situation?
Thanks in advance,
Thambi
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!