Daniel

>>Consider a logging service that wants to provide a different logger 
>>instance for every bundle requesting a logger.

If all you want to do is provide a unique instance of the Logger service 
to each bundle that requires one, consider using a service factory rather 
than a component factory:

         <service servicefactory="true">
             <provide interface="the.package.Logger"/>
         </service>

// 112.4.6
"If servicefactory is set to true, a different component configuration is 
created, activated and its component instance returned as the service 
object for each distinct bundle that requests the service. Each of these 
component configurations has the same component properties."

The bundle that references the Logger service does not know that its 
getting a unique instance.

I hope this help.

Simon



From:
Daniel Bimschas <[email protected]>
To:
[email protected]
Date:
08/17/2009 04:09 PM
Subject:
[osgi-dev] Declarative Services and Component Factories
Sent by:
[email protected]



Hi,

I'm using the OSGi DS spec, respectively the SCR runtime, to declare 
my components and their required references. Now I have the following 
use-case for which I'm unsure about on how to implement it:

Consider a logging service that want's to provide a different logger 
instance for every bundle requesting a logger. Therefore I've 
implemented a service implement, class Logger and declared it the 
following way:

<scr:component enabled="true" name="LoggerService" 
factory="LoggerServiceFactory">
         <implementation class="the.package.impl.LoggerImpl"/>
         <service>
             <provide interface="the.package.Logger"/>
         </service>
</scr:component>

So now, the only way I found out on how to get a reference to a 
LoggerService instance is to get a reference to the ComponentFactory 
"LoggerServiceFactory" and programmatically calling 
newInstance(Dictionary) on it.

I wonder if there's no "more declarative" way for referencing a 
component produced by the declared component factory. Something like 
this would be straightforward in my opinion, allowing to declare 
references with passing configuration:

<reference name="log" interface="the.package.Logger" 
cardinality="1..1" policy="static" bind="bindLog" unbind="unbindLog">
     <property key="loggername" value="The loggers instance name" />
</reference>

Thanks for your help or clarification in advance!

Kind regards,
                 Daniel Bimschas
_______________________________________________
OSGi Developer Mail List
[email protected]
https://mail.osgi.org/mailman/listinfo/osgi-dev


_______________________________________________
OSGi Developer Mail List
[email protected]
https://mail.osgi.org/mailman/listinfo/osgi-dev

Reply via email to