views:

1597

answers:

4

We're trying to determine how to implement a simple plugin framework for a service we are implementing that allows different types of calculators to be "plugged-in".

After reading a number of posts about Java plugin frameworks, it seems like the most common options are:

OSGI seems to be more than we need.

"Rolling your own" is ok but it would be nice to reuse a common library.

So we're down to the JPF and JSPF. JPF seems to not be in active development right now.

JSPF seems very simple and really all we need. However I haven't heard much about it. I've only seen one post on StackOverflow about it. Does anyone else have any experience with JSPF? Or any other comments on this design choice?


Update: There isn't necessarily a correct answer to this.. however we're going to go with Pavol's idea as we need just a really, really simple solution. Thanks EoH for the nice guide.

+3  A: 

If you are planning to have just one (or only a few) not very complex 'extension points' than perhaps a well-defined SPI and a piece of configuration might be sufficient. No need to use a plugin framework.

By piece of configuration I mean some mechanism to find your plugins. For example something like META-INF/services/ or simply listing your plugins in a configuration file.

More details (upon request):

SPI = Service Provider Interface, an "implementer-side equivalent of an API". To learn more try searching for a difference between API and SPI. However in this context it is just a fancy term for an interface to be implemented by your plugins (i.e. defines the contract for your plugins).

A nice, short article "Creating a Service Provider Interface" by Ethan Nicholas describes how to create your own SPI in similar way as it is done in several part of the Java Platform itself.

META-INF/services/ can be seen as a more generalized approach to creating SPIs. More information can be found in the respective section of the JAR File Specification.

Pavol Juhos
API or SPI? What's SPI?
Egwor
We are just having one (or at most a few) straight forward extensions. Can you elaborate on your idea?
Marcus
Sorry for a late response. I've updated my original answer with more details.
Pavol Juhos
Got it. That's a nice simple solution.. thanks.
Marcus
+4  A: 

(Disclaimer: I am the author of JSPF, so better take my comment with a grain of salt ;-)

The main reason I started with the JSPF was because I had the same problem as you have now: I was looking for a simple solution to make my thesis-project 1) extensible and 2) give it a more or less clear code structure.

The reason why I haven't decided to use an existing framework was because most of them were so heavyweight to start with, that I got lost in reading documentation and was almost forgetting my original task. So, according to your statement

We're trying to determine how to implement a simple plugin framework for a service we are implementing that allows different types of calculators to be "plugged-in".

I'd think that you could give JSPF a shot and see how far you come within one or two hours.

However, the final decision also depends a bit on what exactly you want to achieve, and the specific circumstances.

I have heard positive results from a number of individuals who have been using it to structure their projects or load plugins in their projects. On the other hand, I also know of one person in our department who discarded it again because he didn't feel it was mixing well with his programming style.

So, to answer your question briefly (and surely in a biased way), I would use

OSGi for projects and teams

  • which are large and have many people working on it
  • that justify the overhead of setting up the infrastructure
  • in need of the specific services offered

JPF for projects and teams

  • of medium size (?, honestly I am not sure about the project / team size they are targeting)
  • which are in need of more structured facilities to organize their code, like XML configurations, detailed plugin lifecycle management, extensible plugins ...

JSPF for projects and teams

  • of small size, following an agile paradigm
  • that just need something that works out of the box, without the need of configurations or setup
  • willing to sacrifice some features for simplicity

I hope you find the plugin framework most suitable for your scenario. And, no matter what you try, I would be happy to hear about your results.

EoH
A: 

How do I define extension points with OSGI?

servlet
@Servlet, this should be a new question, not an answer..
Marcus
A: 

If you need a really simple solution, try jin-plugin. It is a minimalistic plugin framework for Java and PHP.

Faz