views:

50

answers:

3

I'm building a J2EE application in which I want to allows plugins. I'm fairly convince of the goodness of IoC framework, and so the application will have one to manage services.

Now, I want to allows plugins to be added as simple JAR dropped in the classpath + perhaps a simple configuration file to edit to activate them, in no way something looking like Spring XML config files.

Most of the plugin architecture will be base around strategy/pipeline/chain of command patterns: for example the best plugin for an action is chosen by strategy, several plugins add filtering actions to an user input thanks to a pipeline, and so one.

So, I want to be able to:

  • define service interfaces in the core application,
  • set-up core implementation for extensible services with the chosen pattern in the main application,
  • let third party plugins register themselves in these hooks.

The first 2 points are quite easy, with or without IoC. The last one seems more complex without support at the IoC container level, or at least there is a lot of plumbing to do (how to manage classpath/sevice discovery, how to manage service orders in pipeline when the context change (new plugins), how to manage service overriding, etc).

I do know that Tapestry5 is great in that regards[1], but I can't find anything really relevant for Spring and Guice. And my company is more a String/Guice one than a T5 one (well, if I'm able to show that it's the best solution...)

So I'm wondering:

  • if I missed some obvious documentation;
  • if my requirement are so specials;
  • if an IoC container is not the right tool for that, and I should look for OSGi or something else.

Thanks for any tips !

[1] http://tapestry.apache.org/tapestry5.1/tapestry-ioc/configuration.html

A: 

Have you considered having a look at the Java EE 6 solution - CDI, implementation is named Weld based on JBoss Seam - which might be useful?

Thorbjørn Ravn Andersen
A: 

Once you start dropping in jars and their dependencies and then go though a couple of iterations of this with different plugins and different dependency versions, then you will start to feel the pain that many "application host containers" succumb to.
One possible solution to this problem is OSGi, although I did note a Tapestry blog highlighting the pitfalls of the OSGi approach:
http://blog.tapestry5.de/index.php/2010/01/19/tapestry-ioc-modularization-of-web-applications-without-osgi/

crowne
I would try to avoid OSGi, which is really complex and low level for what I need, in particular no runtime plugin loading. The article cleanly sum-up the advantages of T5 IoC in that regard. Nevertheless, I'm going to keep in mind that OSGi will be a simple and productive solution, sometime in the future.
fanf42
A: 

I'm not sure how this would work with exactly what you're looking to do, but Guice's basic mechanic for handling plugins is Multibindings. How you handle discovery of plugins is up to you, but there are a variety of choices including scanning the classpath for implementations of plugin interfaces, having plugins provide a Module that adds their implementation(s) to the multibinder(s), using a config file that lists the plugin implementation classes, etc.

As the link mentions, you'd need OSGi if you need plugins to be addable at runtime with no restart.

ColinD
Ah, great, I think it was exactly what I was looking for and didn't find. So, there is only Spring, the leader, which as not such a thing ? Thanks !
fanf42