0

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

Michael
  • 131
  • 5

1 Answers1

1

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

ruediste
  • 2,434
  • 1
  • 21
  • 30
  • I have read a bit into the javax.enterprise.event javadoc. Interesting idea! Can you elaborate a bit on this? Where store kepp the registrations during the application's whole uptime would be the next big question of mine. Just in a RAM as a SingletonRegistry ? Any better idea? One more question: Raising the event at startup time? How would I do that (any pointer)? It is not becoming clear from the event package description you linked. – Michael Jun 22 '14 at 18:24
  • Just recognized there is one drawback to this approach. I could not test the extension mechanism outside the JavaEE container say in an eclipse IDE with JUnit for instance... – Michael Jun 22 '14 at 18:36
  • Raising event at startup time: use a (at)Singleton with the (at)Startup annotation – ruediste Jun 23 '14 at 05:47
  • Testing: use http://arquillian.org/ – ruediste Jun 23 '14 at 05:48
  • Hi Ruediste, thanks for your replies. With arquillian I would have to bundle my tests and deploy them to the server. I would like prevent this and run it from within the IDE. So ideally the extension mechanism does not need a container. I figure there should be other options but it seems the question is not interesting enough for others to provide answers. I will wait till evening CET and then mark it as resolved. If no other answer came up your is the winner ;-). – Michael Jun 23 '14 at 06:28
  • You add the (at)RunWith(Arquillian.class) annotation. If you use an embedded Adapter, the adapter will download the container, bundle your test and run it, all from within your IDE – ruediste Jun 23 '14 at 06:31
  • You got me now. :-) Thanks for your replies. I will close the question already now. – Michael Jun 23 '14 at 07:16