karaf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jean-Baptiste Onofré (Jira) <j...@apache.org>
Subject [jira] [Assigned] (KARAF-6790) Filter attribute in @Reference is not honored.
Date Fri, 17 Jul 2020 05:24:00 GMT

     [ https://issues.apache.org/jira/browse/KARAF-6790?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Jean-Baptiste Onofré reassigned KARAF-6790:
-------------------------------------------

    Assignee: Jean-Baptiste Onofré

> Filter attribute in @Reference is not honored.
> ----------------------------------------------
>
>                 Key: KARAF-6790
>                 URL: https://issues.apache.org/jira/browse/KARAF-6790
>             Project: Karaf
>          Issue Type: New Feature
>          Components: karaf
>    Affects Versions: 4.2.0
>         Environment: Karaf version               4.2.9
> Karaf home                  /Users/paul/Documents/apms-ewm/git_intekon/apache-karaf-4.2.9
> Karaf base                   /Users/paul/Documents/apms-ewm/git_intekon/apache-karaf-4.2.9
> OSGi Framework         org.apache.felix.framework-5.6.12
> Java Virtual Machine  Java HotSpot(TM) 64-Bit Server VM version 25.172-b11
> Version                        1.8.0_172
> Vendor                        Oracle Corporation
> Name                          Mac OS X version 10.14.6
> Architecture              x86_64
>  
>  
>            Reporter: Paul Spencer
>            Assignee: Jean-Baptiste Onofré
>            Priority: Major
>
> The filter attribute in the @Reference, org.apache.karaf.shell.api.action.lifecycle.Reference,
for the @Command does not appear the be applied, this the wrong service was returned.
> [Mailing List Thread|http://karaf.922171.n3.nabble.com/Question-about-Reference-Karaf-Command-annotation-td4057824.html]
> From command that uses the RedColor service
>    The command did not return the correct ColorService. 
> {code:java}
> import org.apache.karaf.shell.api.action.Action; 
> import org.apache.karaf.shell.api.action.Command; 
> import org.apache.karaf.shell.api.action.lifecycle.Reference; 
> import org.apache.karaf.shell.api.action.lifecycle.Service; 
> import com.example.service.ColorService; 
> @Service 
> @Command(scope = "color", name = "get-red", description = "Get Red Service") 
> public class DisplayRedServiceCommand implements Action { 
>         @Reference(filter = "(color=red)") 
>         private ColorService colorService; 
> {code}
>  
> Output from Command that get a RedColor service 
> {code:java}
> karaf@root()> color:get-red 
> Color = BLUE 
> {code}
> Component the defines the RedColor service
> {code:java}
> import org.osgi.service.component.annotations.Activate; 
> import org.osgi.service.component.annotations.Component; 
> import org.osgi.service.component.annotations.Deactivate; 
> import org.osgi.service.component.annotations.Modified; 
> import org.slf4j.Logger; 
> import org.slf4j.LoggerFactory; 
> import com.example.service.ColorService; 
> @Component(immediate = true, property = "color=red") 
> public class RedColorService implements ColorService { 
>         private final Logger log = LoggerFactory.getLogger(getClass()); 
> {code}
>  
>  Component that uses the RedColor Service
> {code:java}
> import org.osgi.service.component.annotations.Activate; 
> import org.osgi.service.component.annotations.Component; 
> import org.osgi.service.component.annotations.Deactivate; 
> import org.osgi.service.component.annotations.Modified; 
> import org.osgi.service.component.annotations.Reference; 
> import org.slf4j.Logger; 
> import org.slf4j.LoggerFactory; 
> import com.example.service.ColorService; 
> import com.example.service.GenericColorService; 
> @Component(immediate = true, property = "color=all") 
> public class AllColorService implements GenericColorService { 
>         private final Logger log = LoggerFactory.getLogger(getClass()); 
>         @Reference(target = "(color=red)") 
>         private ColorService redColorService; 
>         @Reference(target = "(color=green)") 
>         private ColorService greenColorService; 
>         @Reference(target = "(color=blue)") 
>         private ColorService blueColorService; 
>         @Override 
>         public String getColor() { 
>                 StringBuffer colors = new StringBuffer(); 
>                 colors.append(redColorService.getColor()); 
>                 colors.append(", "); 
>                 colors.append(greenColorService.getColor()); 
>                 colors.append(", "); 
>                 colors.append(blueColorService.getColor()); 
>                 return colors.toString(); 
>         } 
> {code}
>  
> Command that get a two color service
> {code:java}
> import org.apache.karaf.shell.api.action.Action; 
> import org.apache.karaf.shell.api.action.Command; 
> import org.apache.karaf.shell.api.action.lifecycle.Reference; 
> import org.apache.karaf.shell.api.action.lifecycle.Service; 
> import com.example.secondService.TwoColorService; 
> @Service 
> @Command(scope = "yellow", name = "yellow", description = "Get Yellow Service") 
> public class DisplayYellowServiceCommand implements Action { 
>         @Reference 
>         private TwoColorService colorService; 
>         @Override 
>         public Object execute() throws Exception { 
>                 System.out.println("Color = " + colorService.getColor()); 
>                 return null; 
>         } 
> {code}
> Output from Command that get a two color service
> {code:java}
> karaf@root()> yellow:yellow 
> Color = RED, GREEN 
> {code}
> Component that produces a two color service
> {code:java}
> import org.osgi.service.component.annotations.Activate; 
> import org.osgi.service.component.annotations.Component; 
> import org.osgi.service.component.annotations.Deactivate; 
> import org.osgi.service.component.annotations.Modified; 
> import org.osgi.service.component.annotations.Reference; 
> import org.slf4j.Logger; 
> import org.slf4j.LoggerFactory; 
> import com.example.secondService.TwoColorService; 
> import com.example.service.ColorService; 
> @Component(immediate = true, property = "2color=yellow") 
> public class YellowColorService implements TwoColorService { 
>         private final Logger log = LoggerFactory.getLogger(getClass()); 
>         @Reference(target = "(color=red)") 
>         private ColorService redColorService; 
>         @Reference(target = "(color=green)") 
>         private ColorService greenColorService; 
>         @Override 
>         public String getColor() { 
>                 StringBuffer colors = new StringBuffer(); 
>                 colors.append(redColorService.getColor()); 
>                 colors.append(", "); 
>                 colors.append(greenColorService.getColor()); 
>                 return colors.toString(); 
>         } 
> {code}
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Mime
View raw message