Friday, November 21, 2008

HowTo Build an OSGI Enterprise Server: EasybeansServiceTracker

We've seen that its not easy to use EasyBeans OSGI - you have to be very carefully how to start bundles, watch many dependencies etc. So we created a „Server - Agent“ - bundle to control and manage these tasks.

This „Server - Agent“ - bundle contains an EasybeansServiceTracker we'll discuss now. 

At first we must be sure that all EasyBeans Components are started - there's an easybeans.agent bundle controlling this. EasyBeans Components are:

Which of these EasyBeans Components you need depends from your reqirements - in this blog series we'll only look at the EJB3 Container.

One component is important in our use case: JDBCPool registers data sources as JNDI names and this must be done before EasyBeans can manage the "EJB - bundles".

If we're sure that all EZB Components are registered and also the JDBCPool Component has registered all data sources, then we can start our  „PersistenceContext - Bundles“ and „EJB - Bundles“. 

While creating an EJB3 - Container for each of our „PersistenceContext - Bundles“ and each of our „EJB - Bundles“ EasyBeans registers for each Business - Interface (@Local, @Remote) a ManagedService. The EasybeansServiceTracker tracks all Remote - Business - Interfaces and registers them as Riena Remote Endpoints.

When the EJB3 Container is completed from EasyBeans - an EZBContainerService will be registered. After checking that EZBContainerServices are registered for all of our EJB - Bundles we can register the RienaEasyBeansServerService: our Server it ready.


You'll have some logic like this in your Tracker:

Is the use of a ServiceTracker the best solution ?

At first it looks good to have all the logic around the EasyBeans EJB3Container at a central point in our EasybeansServiceTracker - and it works well.

Analyzing it in more detail you'll find out that its very complex and difficult to manage - even thinking on multi-threading. Also: does it look like the nature of a dynamic and flexible OSGI solution ? How to react if bundles or services are stopped and started again ?

But there's an alternative way: we'll look again how to solve the EJB3 - Container in our OSGI Enterprise Application using Declarative Services. Then you can decide what you prefer to use: ServiceTracker or Declarative Services.

There's an this index of this blog series in the column right beside the blog entries.

blog in german.


Simon Kelly said...

Thanks for the great blogs, honestly some of the most useful and practical info on actually using OSGI. Looking forward to more great posts with good ideas.

ekke said...

thanks for your kindly words.
...but without the great work from all the teams of
* equinox
* Modeling (EMF, openArchitectureWare)
* Riena
it would not be possible for me to build a business application server with dynamic behavior together with rich clients and great UI
BTW: I made some submissions to eclipsecon 2009 - so perhaps I can also present some of my ideas there