Problems and solutions found during my Master degree in Computer Science, related to the Web Architectures course.

martedì 18 giugno 2013

EJB smart lookup

I want to post a nice solution i found for looking up the EJB, easy and simple.
It follows the KISS idea, Keep It Simple and Strong.
Part of this solution is a contribution of Massimiliano.
Let's start from this idea:I want to provide to the user a library that is capable to lookup enterprise beans, without telling him anything about the class that implements the exposed interfaces.
I have many enterprise beans in my application, one of the is for example the account manager:

This class implements the interface IAccount. It is and EJB stateless bean, and the name used to look up this stateless bean is Account. Telling the name of the bean is the first step. Doing so we know the name we have to use for the lookup.

Once deployed the EJB projects an output like this:

java:global/MyBankLogicEAR/MyBankLogic/Account!main.IAccount

java:app/MyBankLogic/Account!main.IAccount

java:module/Account!main.IAccount

java:jboss/exported/MyBankLogicEAR/MyBankLogic/Account!main.IAccount

java:global/MyBankLogicEAR/MyBankLogic/Account

java:app/MyBankLogic/Account

java:module/Account

We need to consider the red part, to look up the EJB. Removing the name of the bean the red part would look like /MyBankLogicEAR/MyBankLogic/NameOfThePackage.AccountManager!main.IAccount

As already said, I want the user NOT to be aware of the path, the name and just avoid him all the problems of looking up the beans.

this is part of the post access EJB on jboss as 7. You may refer to it for more detailed explanations.
Thus this said, i want to avoid the user to use this snipped of code, but instead just tell which interface implementation he wants to lookup.Interfaces are common among the client and the server, and shares the accessible remote methods. A part these methods, user must NOT be aware of everything else.
This is the solution i propose:

Can lookup the EJB which is responsible to provide the methods exposed in the interface IUser.

This is very simple because programmers on server side are aware of the names of the beans, and they may also write an even complex code for look up, like a factory does. Hence they can provide a simple library with this class to lookup the beans.
It is strong because user just knows whether or not an EJB is stateless or not, thus thanks to the interface and using the library it can lookup beans on the Jboss as 7 without having any problem with the name of the application, the EAR, or the module name.