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

Neil Bartlett commented on FELIX-5769:
--------------------------------------

Thanks Carsten. I've tested the 2.0.x version and it works correctly, i.e. the 
references remain unbound and I see this in the log:

{noformat}
2018.01.09 10:36:04 DEBUG - Bundle: example - 
[com.effectiveosgi.ConsumerComponent(3)] New service tracker for runnable, 
initial active: false, previous references: {}, classFilter: 
(objectClass=java.lang.Runnable), eventFilter (service.scope=prototype), 
initialReferenceFilter 
(&(objectClass=java.lang.Runnable)(service.scope=prototype))
{noformat}



> 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
>            Assignee: Carsten Ziegeler
>             Fix For: scr-2.0.16, scr-2.1.0
>
>         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