Managed Jar Framework |
Managed Jar Framework (MJAR) is a software distribution/packaging framework for Java allowing side-by-side deploying of classloader-separated applications in the same VM. MJAR uses Spring Framework for internal component management.
Managed Service - a self-contained collection of Java code, various resouces and dependency jars packaged as a Managed Jar (MJAR).
Client Jar - a standard Java jar file containing:
MJAR Service URL - a URL data structure in form of mjar://ServiceName/ServiceVersion, for example, mjar://CalculatorService/2.0
Managed Jar - the distribution format for a Managed Service.
A Managed jar (MJAR):
Service Implementation jar contains classes implementing a Managed Service and a Spring context file defining the Service Exporter for this service. By convention, this context file (as well as any other Spring context files you want to use) need to be put in the META-INF directory of the Service Implementation jar file. (Example)
MJAR Deployer - a client side Spring bean managing the lifecycle of MJARs accessible from this client. Defines the location of the MJAR (as absolute or relatie file path or as a URL) and (in the future) how often it needs to check for newer versions of this MJAR. (Example)
Deployer will create an isolated Spring context containg Service Invokers for the Service deployed in each particular MJAR. Then, the client side can use a Service Locator class to bind to and run methods of this service. The only pre-requisites are that the client side has classpath access to the client jar for this Service.
The Spring contexts defined in MJARs are configured, used and destroyed in completely separate classloading environment. This allows using multiple versions of the same classes or library jars at the same time in the same VM, ver much like classloading isolation achieved while deploying J2EE WARs or EARs. Unlike J2EE, it is still possible to call services defined in MJARs directly without penalty associated with serialization or a network call.
If a client program has a client jar of a Service on its classpath, it can use ServiceLocator to call it, as simple as that.
See CalculatorServiceTest in the distribution for an example.
This is achieved by installing a custom BorderClassloader in between the client app and a managed Service im MJAR. This CL controls instantiation and execution of everything in a MJAR. Only the classes from client jar (Service Interface and DTOs) are allowed to bleed in from the calling side to the Service.
Service defined in one MJAR can use client jar from some other service to call it in exactly the same way.
The only limitation of this model is that the same client cannot have access to more than one version of the same service at the same time (however, the multiple versions of the same service can still co-exist in the same JVM).
Bundle that can be downloaded from the SourceForge site includes two subdirectories containing two Eclipse projects: mjar and mjar-testservice.
Mjar-testservice is a simple test Service: a calculator with Hypersonic database backend ;-)
Mjar-testservice project includes the Ant build file that has tasks to build the client jar (mjartest-client.jar) and a properly packaged MJAR (mjartest-service.mjar).
mjar directory contains the actual MJAR framework as another Eclipse project. In the testsrc folder, there are some tests (notably CalculatorServiceTest) to test the whole thing.
Enjoy!
Mikhail Garber, Feb 2006