|OSGi Service Dependency vs. Direct Dependency [message #104470]
||Sun, 27 January 2008 12:15
Originally posted by: dieter.schulten.d-velop.de|
are there some best practices to decide how to provide functionality
within an OSGi environment. Let me explain my question by a little
(1) THE OSGI SERVICE WAY
Each productive application needs logging. If there is no logging you
have no possibility to find problems in an customer environment. So
i could implement an "OSGi Logging Service" (like that on in the
OSGi specification) and implement the interfaces of this Logging Service
in a special "Logging Bundle". Now each other bundle which needs the
logging facility could create a ServiceListsner, ServiceTracker and so
on to get a reference on that Logging Service. In this case each bundle
needs to write about 10-20 lines of extra code to use the logging
(addServiceListener, removeServiceListener, serviceChanged, test for
serviceReference != null and so on).
(2) THE DIRECT DEPENDENCY WAY
In my java project i add a direct dependency to the "Logging Classes"
(not the OSGi Logging Service). So i don't have to register a
ServiceListener and can directly access the Logging Facility. Using
this way is more comfortable, BUT if there is a change in the
"Implementation" of the Logging Facility, i do have to recompile
all java projects which depend on this implementation.
(3) THE BASE CLASS DEPENDENCY WAY
I create an base Activator class which already provides the logging
methods. This base class is "NO" OSGi bundle. A developer
can use the logging out of the box. No special initialization necessary.
The developer just has to use the base class (extends BaseActivator).
(almost like 2)
(4) OSGi BUNDLE LOGGING DEPENDENCY "SINGLETON"
I create a OSGi Bundle which provides the Logging Methods. I have to
make sure that this Logging Bundle gets loaded as the first or second
bundle by setting the bundle load order in the config.ini. If i use
log4j for logging i would use the "start" method to initialize the
log4j, like "addAppender" and so on. A developer can use the logging
by "private static Logger logger = Logger.getRootLogger();"
Which way do you use in which situation?
Do you have some experiences with one of the possibilities?
What is the best way to provide Logging to an OSGi environment?
What is about little helper methods like "hashFile" or "addToNumbers"?
Whould you also create an OSGi Service for those helper methods?
Thanx for your help,
|Re: OSGi Service Dependency vs. Direct Dependency [message #104488 is a reply to message #104470]
||Mon, 28 January 2008 09:11
> Which way do you use in which situation?
The Riena Project uses something like (4). Riena provides a a core bundle with defines a LogUtil class. The LogUtil handles all the stuff you wrote in (1)
and provides a Log service instance.
> Do you have some experiences with one of the possibilities?
This works fine and is easy to use. Currently we see no disadvantage
> What is the best way to provide Logging to an OSGi environment?
Do you mean ho to provide a implementation e.g. log4j to an OSGI environment? Riena add log4j as LogListener to the OSGi environment
> What is about little helper methods like "hashFile" or "addToNumbers"?
> Whould you also create an OSGi Service for those helper methods?
Instead to provide the OSGi Log Service you can provide you own Log Servie API, wich extends the OSGi Log API. Internal your Log implementation delegates
calls to OSGi Log Service and to your context e.g. "hashFile". This context is maybe also a Service.
Hmm.. may be there is a better approach?
> Thanx for your help,
Powered by FUDForum
. Page generated in 0.01851 seconds