Thursday, November 04, 2004

Using EJB as Adapters : Multiple Class versions issue !

Recently came across a problem wherein, one application say (A) needs to communicate with another application say(B). But there are many versions of application B (say B1, B2 and B3). Each version has same package, class and API names for their respective implementations and are deployed in different regions. Where as A is a global application with one version and needs to communicate with respective version of B based on region of a request.

Both A and B are pure J2EE applications having their own set of EJBs in business and servlets/jsps in presentation.

There definitely is an issue that why there are various versions with same name of classes and differing in composition for application B. But that more or less happens in the projects either due to vague requirements or incomplete design or last minute changes.

The problem at hand is to allow application A to seamlessly communicate with B1, B2 and B3.

To enable this communication there is following conventional way used by many projects -

***1***
-Change the package names to include the version numbers of the application. But this seems like a very crude and not so maintainable way of achieving the objective. And is also tedious and error-prone at this stage.

***2***
Another approach is to build an Adapter class which will create class-loaders for different versions of the application B and will allow seamless communication. But creation of class-loader inside EJB Container is generally not recommended.

***3***
So I was wondering, can we not develop this Adapter as a simple SLSB and wrap it up in 3 different ejb jars with respective version's value-object classes from B1, B2 and B3. This way the different class-loaders will be provided by the container inherently and A can communicate seamlessly with all three versions of B with ambiguity of classes getting resolved by container class-loader heirarchy.

Only issue is that the application A will need to deploy these Adapter beans in its environment.

1 comment:

Anonymous said...

Amiable brief and this mail helped me alot in my college assignement. Thank you on your information.