views:

326

answers:

3

In a J2EE application, we are using EJB2 in weblogic.

To avoid losing time building the initial context and looking up EJB Home interface, I'm considering the Service Locator Pattern.

But after a few search on the web I found that event if this pattern is often recommended for the InitialContext caching, there are some negative opinion about the EJB Home caching.

Questions:

  • Is it safe to cache EJB Home lookup result ?
  • What will happen if one my cluster node is no more working ?
  • What will happen if I install a new version of the EJB without refreshing the service locator's cache ?
+3  A: 
Is it safe to cache EJB Home lookup result ?
What will happen if one my cluster node is no more working ? 

IMHO the purpose of ServiceLocator within J2EE is to cache EJB Home and reduce expensive JNDI look ups. It is safe on Weblogic since by default the EJB Home is load balanced across the cluster, and this will automatically allow failover to the next server.

This value is controlled by the home-is-clusterable value in weblogic-ejb-jar.xml, documented here which defaults to true.

What will happen if I install a new version of the EJB without refreshing 
the service locator's cache ?

I havent tried doing such a change myself. However, I'm guessing as part of your build/deploy, your Service Locator class would also get redeployed along with a change to your EJBs - and thus do a fresh lookup?

If your client is unaffected during the changes to the EJB, then the cached EJBHome will return a stale reference when you call a method on it. So you will have to force the client to be refreshed.

JoseK
A: 

What will happen if I install a new version of the EJB without refreshing the service locator's cache ?

Once your application goes live, new installations should become much less frequent than requests for an EJBHome.
So your focus and concern should lie with the frequent live operations, rather than the transient development operations.
Factor into your design the ability to invalidate caches when necessary.

crowne
+2  A: 

Is it safe to cache EJB Home lookup result ?

Yes.

What will happen if one my cluster node is no more working ?

If your server is configured for clustering/WLM, then the request should silently failover to another server in the cluster. The routing information is encoded in the stub IOR.

What will happen if I install a new version of the EJB without refreshing the service locator's cache ?

Assuming you update the bean and not the component or home interfaces, then everything continues to work. EJBHome is effectively a stateless session bean, so the request can continue to be accessed from the same server if available or on a different server in the cluster if not.

Note that the @EJB injection in EJB3 effectively encourages home caching. (Though, admittedly, it also allows SFSB caching even though this is clearly incorrect, so perhaps @EJB isn't the best support of my claim :-)).

bkail