Hi Clement,

Thanks for the prompt answer. I use iPOJO 1.2.0 and create the bundle by
using the ant script copied (and slightly modified) from the 'iPOJO in
10mins' tutorial. 

1) After modifying filters in @Request annotations to (instance.name=...),
the bundle gets activated, but it does not print testing messages, so the
test component (consumer) is not started.
2) After adding attributes name="helloService1" and name="helloService2" to
appropriate 'instance' elements in the metadata.xml file, and replacing
filters in @Request annotations with from=..., the bundle gets activated,
but it does not print anything at all, even the 'start' messages from
services.
3) I also tried adding properties (as you suggested) to the instance
specification of my consumer component (tester). This had the same effect as
in p.p.2.

Any ideas of what can be wrong in my configuration?

I have attached zip file containing my project.

http://www.nabble.com/file/p24440689/lk.ipojo.samples.zip
lk.ipojo.samples.zip 

Thanks,
-- Lev


clement escoffier wrote:
> 
> Hi,
> 
> Which version of iPOJO are you using? Because "component.name"  
> disappeared in the 1.2.0 to become "instance.name", moreover a "from"  
> attribute allows you to select the provider.
> 
> So, imagine that you have a component type providing the service  
> HelloWorld, and an instance created as follows:
> <instance component="MyComponentType" name="MyProvider"/>
> 
> Then, you can write a service dependencies targeting only this provider:
> @Requires(from="MyProvider")
> private HelloWorld hello;
> 
> You can also configure the "from" attribute in the instance  
> configuration such as:
> <instance name="MYConsumer" component="MyConsumerType">
>       <property name="requires.from">
>               <property name="helloService1" value="MyProvider"/>
>       </property>
> </instance>
> With the following dependency:
> @Requires(id="helloService1")
> private HelloWorld hello;
> 
> Regards,
> 
> Clement
> 
> 
> 
> On 11.07.2009, at 14:36, levko wrote:
> 
>>
>> I have 2 components/services providing the same interface. When both  
>> services
>> are imported by using field injection (@Request annotations), I need  
>> to
>> select appropriate service. For this purpose I use LDAP filters
>> (component.name=...) in the @Request annotations. When I start my  
>> bundle in
>> the Apache Felix OSGi, the bundle is activated, but the service  
>> calls fail.
>> If I remove the LDAP filters from the @Request annotations, only one
>> imported service is bound to both fields, and only one service is  
>> actually
>> called.
>>
>> Can somebody help me with the problem of selecting appropriate  
>> imported
>> service from several services providing the same interface?
>>
>> Here is my iPOJO test code:
>>
>> a) service interface:
>>    public interface HelloWorld {
>>        void sayHello();
>>    }
>>
>> b) 2 different components/services providing this interface:
>>    // component helloService1
>>    @Component(name="helloService1")
>>    @Provides(specifications=HelloWorld.class)
>>    public class HelloWorldService1 implements HelloWorld {
>>        @Override
>>        public void sayHello() { System.out.println("HelloService1:  
>> Hello,
>> World!"); }
>>        @Validate public void startService() { System.out.println(
>> "[HelloWorldService1]: started" ); }
>>        @Invalidate public void stopService() { System.out.println(
>> "[HelloWorldService1]: stopped" );}
>>    }
>>    // component helloService2
>>    @Component(name="helloService2")
>>    @Provides(specifications=HelloWorld.class)
>>    public class HelloWorldService2 implements HelloWorld {
>>        @Override public void sayHello() {
>> System.out.println("HelloService2: Hello, World!"); }
>>        @Validate public void startService() { System.out.println(
>> "[HelloWorldService2]: started" ); }
>>        @Invalidate public void stopService() { System.out.println(
>> "[HelloWorldService2]: stopped" ); }
>>    }
>>
>> c) the test needs to import and use both services:
>>    @Component(name="helloTest")
>>    public class HelloWorldTest {
>>        @Requires(id="helloService1",
>> filter="(component.name=helloService1)")
>>        private HelloWorld _helloService1;
>>        @Requires(id="helloService2",
>> filter="(component.name=helloService2)")
>>        private HelloWorld _helloService2;
>>        @Validate public void start() {
>> System.out.println("[HelloWorldTest]: started");
>>            _helloService1.sayHello(); _helloService2.sayHello();
>>        }
>>        @Invalidate public void stop() {
>> System.out.println("[HelloWorldTest]: stopped"); }
>>    }
>>
>> Any ideas?
>>
>> Thanks,
>> -- Lev
>> -- 
>> View this message in context:
>> http://www.nabble.com/How-to-select-imported-service-in-iPOJO--tp24439983p24439983.html
>> Sent from the Apache Felix - Users mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [email protected]
>> For additional commands, e-mail: [email protected]
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/How-to-select-imported-service-in-iPOJO--tp24439983p24440689.html
Sent from the Apache Felix - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to