I am working on a JavaEE web application which shall be able to fetch data from different sources. The data will be fetched and persisted in a database for later processing and reporting. I started with one default data provider covering a specific source but would like to design the application architecture in a way that either me or even others could write data providers / data provider plugins for different data sources.
The service providers could be implemented independed from the core application and could be packaged in separated jars. Once dropped to the web applications classpath the provider implementation would be recognized as service providers by the application core that is triggering the data fetching job.
I am looking for a standard way of implementing this SPI or extension points, but it shall not bloat my application's code.
I thought of "OSGI extension points" but this is more for rcp platform applications and mine is a web application. So I ruled it out for now.
My second idea is a combination of predefined provider interfaces and then the use of custom "provider" annotations to mark the implementing classes (the service providers).
What mechanisms / approaches / frameworks can you recommend to solve this architectural question?
Many Thanks in advance & Cheers, Michael
I would use an event observer. During application startup, you raise a DiscoverDataProviders
event, which has a registerDataProvider(...)
method. The extension jars can observe the event and register themselves.
See http://docs.oracle.com/javaee/6/api/javax/enterprise/event/Observes.html