[ 
https://issues.apache.org/jira/browse/FELIX-5769?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16318156#comment-16318156
 ] 

Carsten Ziegeler commented on FELIX-5769:
-----------------------------------------

The SCR service tracker (which is a modified version of the framework service 
tracker) is using three filters: one to do the initial query against the 
service registry, one to add a service listeners and finally a filter to filter 
the events send to that listener.
The initial filter is an and combination of the listener filter and the event 
filter. The listener filter uses only the service interface for filtering while 
the event filter is used to filter based on a provided target and the prototype 
required option.
It seems, right now this event filter is not calculated correctly and only 
works if a target is provided in addition. If no target is provided, it's 
always empty

> SCR should not bind prototype_required reference to bundle scope service
> ------------------------------------------------------------------------
>
>                 Key: FELIX-5769
>                 URL: https://issues.apache.org/jira/browse/FELIX-5769
>             Project: Felix
>          Issue Type: Bug
>          Components: Declarative Services (SCR)
>    Affects Versions: scr-2.0.14
>            Reporter: Neil Bartlett
>         Attachments: scr-debug.log
>
>
> I have a consumer component that refers to a service using prototype_required 
> service scope:
> {code:java}
> @Component
> public class ConsumerComponent {
>     @Reference(scope = ReferenceScope.PROTOTYPE_REQUIRED)
>     Runnable runnable;
> }
> {code}
> And another component that provides the correct service type BUT uses bundle 
> scope:
> {code:java}
> @Component(scope = ServiceScope.BUNDLE)
> public class ProviderComponent implements Runnable {
>     @Override
>     public void run() {}
> }
> {code}
> According to the OSGi R6 Compendium spec, section 112.3.5, the reference 
> should not bind to the service because "for a bound service of a reference 
> with prototype required reference scope, only services registered with 
> prototype service scope can be considered as target services ... A service 
> that does not use prototype service scope cannot be used as a bound service 
> for a reference with prototype required reference scope since the service 
> cannot provide a distinct service object for each component instance".
> However in SCR 2.0.14, the consumer component is in fact bound to the service 
> as shown below.
> I have used factory config to create three instances of the consumer 
> component. All three are satisfied and active:
> {noformat}
>  [   7]   com.effectiveosgi.ConsumerComponent  enabled
>     [   5] [active      ] 
> com.effectiveosgi.ConsumerComponent.f89094ca-85d6-4f22-ae73-198e6977ba8e 
> (com.effectiveosgi.ConsumerComponent )
>     [   6] [active      ] 
> com.effectiveosgi.ConsumerComponent.e2cb08d0-4b4d-48c8-b6cc-248bc1bfdc92 
> (com.effectiveosgi.ConsumerComponent )
>     [   7] [active      ] 
> com.effectiveosgi.ConsumerComponent.9b7e9c7e-be11-442e-b9c7-2c6e9ea70544 
> (com.effectiveosgi.ConsumerComponent )
> {noformat}
> The scr:info command shows that all three component instances are bound to 
> the same service, and that is is bundle scope:
> {noformat}
> g! scr:info com.effectiveosgi.ConsumerComponent
> *** Bundle: example (7)
> Component Description:
>   Name: com.effectiveosgi.ConsumerComponent
>   Implementation Class: com.effectiveosgi.ConsumerComponent
>   Default State: enabled
>   Activation: immediate
>   Configuration Policy: optional
>   Activate Method: activate
>   Deactivate Method: deactivate
>   Modified Method: -
>   Configuration Pid: [com.effectiveosgi.ConsumerComponent]
>   Reference: runnable
>     Interface Name: java.lang.Runnable
>     Cardinality: 1..1
>     Policy: static
>     Policy option: reluctant
>     Reference Scope: prototype_required
>   Component Description Properties:
>   Component Configuration:
>     ComponentId: 5
>     State: active      
>     SatisfiedReference: runnable
>       Target: null
>       Bound to:        35
>       Reference Properties:
>           component.id = 8
>           component.name = com.effectiveosgi.ProviderComponent
>           objectClass = [java.lang.Runnable]
>           service.bundleid = 7
>           service.id = 35
>           service.scope = bundle
>     Component Configuration Properties:
>         _com.effectiveosgi.rt.config.filePath = 
> /Users/neil.bartlett/Projects/eosgi-runtime/_assembly/load/http-config.yaml
>         _com.effectiveosgi.rt.config.identity = tertiary
>         component.id = 5
>         component.name = com.effectiveosgi.ConsumerComponent
>         org.osgi.service.http.port = 8081
>         service.factoryPid = com.effectiveosgi.ConsumerComponent
>         service.pid = 
> com.effectiveosgi.ConsumerComponent.f89094ca-85d6-4f22-ae73-198e6977ba8e
>   Component Configuration:
>     ComponentId: 6
>     State: active      
>     SatisfiedReference: runnable
>       Target: null
>       Bound to:        35
>       Reference Properties:
>           component.id = 8
>           component.name = com.effectiveosgi.ProviderComponent
>           objectClass = [java.lang.Runnable]
>           service.bundleid = 7
>           service.id = 35
>           service.scope = bundle
>     Component Configuration Properties:
>         _com.effectiveosgi.rt.config.filePath = 
> /Users/neil.bartlett/Projects/eosgi-runtime/_assembly/load/http-config.yaml
>         _com.effectiveosgi.rt.config.identity = secondary
>         component.id = 6
>         component.name = com.effectiveosgi.ConsumerComponent
>         org.osgi.service.http.port = 8081
>         service.factoryPid = com.effectiveosgi.ConsumerComponent
>         service.pid = 
> com.effectiveosgi.ConsumerComponent.e2cb08d0-4b4d-48c8-b6cc-248bc1bfdc92
>   Component Configuration:
>     ComponentId: 7
>     State: active      
>     SatisfiedReference: runnable
>       Target: null
>       Bound to:        35
>       Reference Properties:
>           component.id = 8
>           component.name = com.effectiveosgi.ProviderComponent
>           objectClass = [java.lang.Runnable]
>           service.bundleid = 7
>           service.id = 35
>           service.scope = bundle
>     Component Configuration Properties:
>         _com.effectiveosgi.rt.config.filePath = 
> /Users/neil.bartlett/Projects/eosgi-runtime/_assembly/load/http-config.yaml
>         _com.effectiveosgi.rt.config.identity = primary
>         component.id = 7
>         component.name = com.effectiveosgi.ConsumerComponent
>         org.osgi.service.http.port = 8080
>         service.factoryPid = com.effectiveosgi.ConsumerComponent
>         service.pid = 
> com.effectiveosgi.ConsumerComponent.9b7e9c7e-be11-442e-b9c7-2c6e9ea70544
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to