I have a large ecosystem of applications and libraries which are currently deployed as a collection of .jars in various application servers (e.g. JBoss AS), and I'm trying to figure out a good set of tools to manage dependencies and life-cycles of the various packages.
I think of the packages as being in one of (at least) three possible states: "unloaded", "pending" and "loaded", loosely defined as follows:
(There might also be a few more states, such as "failed" for packages that tried to load but failed for some other reason than that dependencies were not satisfied, etc...)
In the life-cycle of a package, a number of things might cause a package to change state between these three:
I've started working on using OSGi for defining the dependencies - it rolls well with our build system and produces reliable dependency information. However, if I load the two OSGi bundles A
and B
into JBoss, where B
depends on A
, and then unload A
, it seems like B
happily keeps running. I've understood that there are some hooks that I could use to control this on a low level (framework events), but my spider sense is tingling, saying that there must be a better way to do this.
Is there a nice tool/framework/whatever-you-want-to-call-it that will compliment OSGi in these aspects?
If you declare dependancy between modules, the lifecycle is properly managed and the descendant depandancies must be stopped before the top-level module is stopped.
However, stopping a module does nothing more than sending events to the bundle activator and removing references from classloader. Any activities (such as thread or distributed instances) must be manually clean. For example, you must call org.apache.commons.logging.LogFactory.release(ClassLoader) (if using commons logging) or remove any injected UI-component.