I'd also like to add that with a service model in general you can also
use IoC mechanism such as Spring-DM, OSGi DeclarativeServices, iPojo and
others. IoC is a very sweet programming model that can isolate you from
the fact that services are even being used (and isolate you from the
OSGi API itself)!
(To me, IoC is the KILLER reason to use services)!
John Wells (Aziz)
[EMAIL PROTECTED]
________________________________
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Stuart McCulloch
Sent: Tuesday, April 01, 2008 7:13 AM
To: Equinox development mailing list
Subject: Re: [equinox-dev] Service or Export-Package
On 01/04/2008, Srijith Kochunni <[EMAIL PROTECTED]> wrote:
Hi All,
This is more a generic OSGi question. I
understand the difference between Require-Bundle and Import-Package. But
what i`m not able to understand is when should I register my class as a
service?, and when I should simply export the package, so that other
packages can import and use them?
What is the advantage of registering as a service?
a few more benefits of services:
1) you can use different implementations of a service at the
same time
2) services can have rich metadata, which you can use to
filter on
3) you can customize services per clients (see ServiceFactory
interface)
4) service implementations are POJOs, no need to create
instances
(ie. to use an imported class you may need to create an
instance
which can lead to classloading issues that you might not
see with
services, as they're created by the registering
bundle...)
5) a service has more fine-grained information about who's
using it
(as a bundle could get and unget a service during it's
lifetime)
I'm sure I've missed other benefits - of course there is a
management
overhead to services, but it's not too high compared to the
benefits :)
I`ve gone through the OSGi best practices doc, by BJ
Hargrave and Peter Kriens, and read about dynamism of using service. But
let me say that i have some core bundles which I am going to always have
loaded, then should I expose my classes as a service or use
Export-Package alone.. Which is the better practice.?
I tend to use Export-Package for static dependencies that I know
will
only have a single provider - mostly utility methods - and of
course to
provide service APIs ;)
for major bundle dependencies, especially methods involving
state,
I would typically use services, because of the benefits I listed
above
but there's no golden rule, and a lot of this will come from
experience
- you can always migrate to services over time if you keep your
code
decoupled (you can use Declarative Services, Spring-DM or iPOJO
to inject services, which minimises their impact on client code)
btw, when separating code into bundles it's a good idea to
minimise
dependencies between them by using something like the "CRC card"
design approach - and as part of this exercise see if they look
more
like services or exports...
HTH
Thanks,
Srijith.
_______________________________________________
equinox-dev mailing list
[email protected]
https://dev.eclipse.org/mailman/listinfo/equinox-dev
--
Cheers, Stuart
Notice: This email message, together with any attachments, may contain
information of BEA Systems, Inc., its subsidiaries and affiliated
entities, that may be confidential, proprietary, copyrighted and/or legally
privileged, and is intended solely for the use of the individual or entity
named in this message. If you are not the intended recipient, and have received
this message in error, please immediately return this by email and then delete
it._______________________________________________
equinox-dev mailing list
[email protected]
https://dev.eclipse.org/mailman/listinfo/equinox-dev