Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » DS - Difference between component factory and service factory
DS - Difference between component factory and service factory [message #128781] Tue, 07 April 2009 14:46 Go to next message
Andrea Zoppello is currently offline Andrea ZoppelloFriend
Messages: 48
Registered: July 2009
Member
Hi All,

I'm an OSGi beginner and i'm trying to understand how osgi-ds works and
could fit my needs.

I want to realize a system where i could dinamically register and
unregister services and all of these services implements the same
interface ( for example
IStandardService ).

Then suppose for examples i've two bundle A and B and each of one provide
an implementation of this interface ( AServiceImpl, BServiceImpl).

Actually i've declared a ComponentFactory in bundle A, and a
ComponentFactory in bundle B and each of these factory provide to create
instances of AserviceImpl and of BServiceImpl.

I've used a component factory because i could have both the case:

1 - Different implementations of the same interface
2 - Different instances of the same implementation ( but with different
properties ) for example a custom identifier for instances.

Is this the right approach??? This question is because i've read that it's
possible to have both ComponentFactory and ServiceFactory.

I've buyed the two books about OSGi, and read the free one from neil, but
i'm still having not clear these aspect.

Is there a clear tutorial on DS ComponentFactory/ServiceFactory usage???

Thanks

Andrea Zoppello
Re: DS - Difference between component factory and service factory [message #480454 is a reply to message #128781] Mon, 17 August 2009 08:46 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: daniel.bimschas.com

Hi Andrea,

did you find an answer to your question? I'm currently stuck on a
somewhat similar use case, trying to define a LoggerFactory that returns
a new Logger instance for every bundle requesting one.

However, I can't find a simple example on how to use a ComponentFactory
with DS to get a reference to a component (and the service provided by
it) created by the ComponentFactory. Do you know of an example / tutorial?

I think there should be something like this (Warning: this is not OSGi
specs, only what I wish it would be):

<reference name="log" interface="my.Log" cardinality="1..1"
policy="static" bind="bindLog" unbind="unbindLog">
<property key="loggername" value="TheLogger" />
</reference>

which uses the factory declared for the Logger service and passes the
configuration with the attached <property> values to it. So, this is how
I wish it to be working. But how is it working in the reality? What
classes/interfaces need to be implemented?

I find the OSGi spec is very irritating in describing the whole
component / service factory and DS stuff, as it's audience is OSGi
bundle implementors as well as OSGi framework developers and there is no
clear seperation in it.

I hope somebody of you can help me on this!

Kind regards, Daniel


Am 07.04.09 16:46, schrieb Andrea Zoppello:
> Hi All,
>
> I'm an OSGi beginner and i'm trying to understand how osgi-ds works and
> could fit my needs.
>
> I want to realize a system where i could dinamically register and
> unregister services and all of these services implements the same
> interface ( for example IStandardService ).
>
> Then suppose for examples i've two bundle A and B and each of one
> provide an implementation of this interface ( AServiceImpl, BServiceImpl).
>
> Actually i've declared a ComponentFactory in bundle A, and a
> ComponentFactory in bundle B and each of these factory provide to create
> instances of AserviceImpl and of BServiceImpl.
>
> I've used a component factory because i could have both the case:
>
> 1 - Different implementations of the same interface
> 2 - Different instances of the same implementation ( but with different
> properties ) for example a custom identifier for instances.
>
> Is this the right approach??? This question is because i've read that
> it's possible to have both ComponentFactory and ServiceFactory.
>
> I've buyed the two books about OSGi, and read the free one from neil,
> but i'm still having not clear these aspect.
>
> Is there a clear tutorial on DS ComponentFactory/ServiceFactory usage???
>
> Thanks
> Andrea Zoppello
>
>
>
>
>
Re: DS - Difference between component factory and service factory [message #480602 is a reply to message #480454] Mon, 17 August 2009 19:39 Go to previous message
Eclipse UserFriend
Originally posted by: daniel.bimschas.com

After some further research and tips from Andrea (thanks!) I found this
easy-to-follow manual on how to reference the ComponentFactory and the
instances it produces:

http://dz.prosyst.com/pdoc/mbs_prof_6.1/um/framework/bundles /osgi/scr/scr.html#factory

However, I wonder if there's a way to do it "more declaratively". Now,
I'm referencing a ComponentFactory instance by using

<reference name="LoggerServiceFactory"
interface="org.osgi.service.component.ComponentFactory"
cardinality="1..1" policy="static" bind="bindLogFactory"
unbind="unbindLogFactory"/>

in the XML descriptor. Afterwards I programmatically create a
LoggerService-instance in the referencing component by calling
newInstance():

protected synchronized void activate(ComponentContext context) {
Hashtable loggerConfig = new Hashtable();
loggerConfig.put(Logger.PARAM_LOGGER_NAME,
Configurator.class.getSimpleName());
this.logInstance = logFactory.newInstance(loggerConfig);
this.log = (Logger) logInstance.getInstance();
}

Does anybody know of a way to do it "more declaratively", e.g.
comparable to my previous post?

Greetings, Daniel


Am 17.08.09 10:46, schrieb Daniel Bimschas:
> Hi Andrea,
>
> did you find an answer to your question? I'm currently stuck on a
> somewhat similar use case, trying to define a LoggerFactory that returns
> a new Logger instance for every bundle requesting one.
>
> However, I can't find a simple example on how to use a ComponentFactory
> with DS to get a reference to a component (and the service provided by
> it) created by the ComponentFactory. Do you know of an example / tutorial?
>
> I think there should be something like this (Warning: this is not OSGi
> specs, only what I wish it would be):
>
> <reference name="log" interface="my.Log" cardinality="1..1"
> policy="static" bind="bindLog" unbind="unbindLog">
> <property key="loggername" value="TheLogger" />
> </reference>
>
> which uses the factory declared for the Logger service and passes the
> configuration with the attached <property> values to it. So, this is how
> I wish it to be working. But how is it working in the reality? What
> classes/interfaces need to be implemented?
>
> I find the OSGi spec is very irritating in describing the whole
> component / service factory and DS stuff, as it's audience is OSGi
> bundle implementors as well as OSGi framework developers and there is no
> clear seperation in it.
>
> I hope somebody of you can help me on this!
>
> Kind regards, Daniel
>
>
> Am 07.04.09 16:46, schrieb Andrea Zoppello:
>> Hi All,
>>
>> I'm an OSGi beginner and i'm trying to understand how osgi-ds works and
>> could fit my needs.
>>
>> I want to realize a system where i could dinamically register and
>> unregister services and all of these services implements the same
>> interface ( for example IStandardService ).
>>
>> Then suppose for examples i've two bundle A and B and each of one
>> provide an implementation of this interface ( AServiceImpl,
>> BServiceImpl).
>>
>> Actually i've declared a ComponentFactory in bundle A, and a
>> ComponentFactory in bundle B and each of these factory provide to create
>> instances of AserviceImpl and of BServiceImpl.
>>
>> I've used a component factory because i could have both the case:
>>
>> 1 - Different implementations of the same interface
>> 2 - Different instances of the same implementation ( but with different
>> properties ) for example a custom identifier for instances.
>>
>> Is this the right approach??? This question is because i've read that
>> it's possible to have both ComponentFactory and ServiceFactory.
>>
>> I've buyed the two books about OSGi, and read the free one from neil,
>> but i'm still having not clear these aspect.
>>
>> Is there a clear tutorial on DS ComponentFactory/ServiceFactory usage???
>>
>> Thanks
>> Andrea Zoppello
>>
>>
>>
>>
>>
Previous Topic:addRepository touchpoint instruction ignored
Next Topic:[P2] Problems with Galileo Update Site
Goto Forum:
  


Current Time: Fri Apr 19 23:11:43 GMT 2024

Powered by FUDForum. Page generated in 0.04496 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top