Tuesday, December 2, 2008

Dependencies and Services in OSGI Enterprise Applications

A busy week has started again:
  • Refactoring my OSGI Enterprise Server: Using Declarative Services instead of ServiceTracker where possible. (I'll report soon in my other blog series)
  • openArchitectureWare 4.3.1RC1 is published and has to be tested against my many modeling templates
  • Some more tests using Eclipse 3.5M3: PDE - supporting Declarative Services and  Cycles in 3rd Party Bundles
  • Development of a new soon-coming project: redView (Riena - EMF - Dynamic Views) and integration of these dynamic view models into my modeling workflow

But now lets start and report some of my experiences of:

Dependencies and Services in OSGI Enterprise Applications

If you follow my blog series „HowTo Build an OSGI Enterprise Server“, you probably have read in the last entry that its difficult to use a ServiceTracker with much logic and dependencies inside. Its not so hard to make it run, but hard to manage all the dynamic of an OSGI application. So the next task is to use Declarative Services instead as possible to solve the requirements. While working in this area I noticed some points I want to blog about.

PDE Tooling

This is really the first what happens: you'll miss the comfortable PDE tooling.
You have to describe the service components in a XML file without support:

... and also an entry in the MANIFEST.MF as reference to this file:

Good news: Dopwnload and test Eclipse 3.5M3: PDE Tooling supports now Declarative Services :-)

Managing Dependencies

Under OSGI the management of dependencies is very important and fundamental to get a well structured application achitecture.

We already know dependencies using Import-Package or Require-Bundle. We can also look at these dependencies from inside eclipse.

The classic way as Plug-In - Dependencies:

or the easy to understand visuell way:

(here's the Updatesite from Graph Visualization Plug-In)

But bundle - dependencies are only one part - we're missing the service - dependencies

If you look at the DataSource example from above:

There are no more bundle dependencies ? Indirectly we have dependencies from Declarative Services: The DataSourceService will only be provided if exactly one service of Type Ejb3ServerComponentsService and one service of type JDBCPoolComponent is available. These two referenced services are declared in two other bundles.

If our declarative Service Component would include bind / unbind methods, then we would have Import-Package dependencies.

Till now I couldn't find a tool displaying service - dependencies in a visual graph.

And if you think more about service - dependencies: there are some different strategies to use services and you can even mix them in one application:

As an Software Architekt I like to get an overview of used Bundles, Services and dependencies. Because there's no tool to show the existing dependencies I'll come the way from another direction: my server project is model-driven, so I can model service - dependencies and -strategies :-)

using openArchitectureWare I'll then generate service - components in XML - files or Javacode for ServiceTracker or Riena - Injection ...

This will be part of another blog ;-)

debug - trace - log Declarative Services

While refactoring my project of course from time to time I reached a point asking why a specific declarative service reference is not resolved from eqinox.ds ;-)

With the help from Equinox - Newsgroup and some searches I learned some important System Properties I didn't found in the Eclipse Help or Equinox Wiki:

  • equinox.ds.debug=true switch debugmode on 
  • equinox.ds.print=true prints the trace-logs on the console. I dont need it because I catch the OSGI LogServices and log them by myself.(s.a. blog series Logging)
  • equinox.ds.perf=true logs the execution times in ms
  • equinox.scr.waitTimeOnBlock=10000 how many ms should equinox.ds wait until a service component is ready. Was very helpful because 10000 ms is default and some  3rdParty components need more then 50000 ms in DEBUG log - mode.

ServiceTracker vs Declarative Services

Can a Service Tracker completely be replaced by Declarative Services ? No - this isn't always possible. 
One example: Using a ServiceTracker you can get access to all methods of a service - using Declarative Services instead you can only use service properties in target - filters.

...enough for the first blog about Declarative Services - there are so many things to talk about in this context, so I can imagine to start a blog series about this - but at first I have to finish the already started blog series ;-)

You can take a look at my blog series about OSGI Enterprise Applications - the index is in the column right beside this blog.

There are also some submissions for EclipseCon 2009 - if you want to hear more about: comments are welcome ;-)

blog in german

No comments: