You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Luis Neto <lc...@gmail.com> on 2014/06/05 18:34:14 UTC

Extender Pattern Filter

Hi all, sorry if this question is to naive but i am struggling to
understand how
iPOJO indentifies the extender matching bundles.

I have a super class and a concrete class that i want to perform some
logic, first i have
thought that iPOJO automatically by declaring the property:

> <provides specifications="Algorithm"/>
>
on the concrete class.

Then i've done some more reading and i have seen the PAX-WEB example and i
tried to declare
the property <Algorithm> in the concrete class bundle manifest header.

So my question is how to declare the property so the extender service can
identify the bundle?

I've declared and implemented my extender service as follows:


    <component
>         classname="com.MyExtender"
>         name = "MyExtender" public="false">
>         <extender:extender
>             extension="Algorithm" onArrival="onBundleArrival"
> onDeparture="onBundleDeparture" />
>         <callback transition="invalidate" method="stop" />
>         <callback transition="validate" method="start" />
>     </component>
>     <instance
>         name="algorithm.extender"
>         component="MyExtender">
>     </instance>
>

The superclass:

public abstract class Algorithm{
>
> String name;
> String version;
>
> public Algorithm(String name, String version){
>     this.name = name;
>     this.version = version;
> }
>
> public String getName(){
>     return name;
> }
> ...
>
> abstract public void computeSomething(Map<a,b> data);
>

And concrete subclasses as follows:

public class ConcreteAlgorithm extends Algorithm{
>
> Map<a,b> data;
>
> public ConcreteAlgorithm(String name, Map<a,b> data){
>     super(name);
>     data = data;
> }
>
> public void computeSomething(Map<a,b> data){
>     //compute data
> }


Best regards,
Luis

Re: Extender Pattern Filter

Posted by Clement Escoffier <cl...@gmail.com>.
Hi,

It looks like what you are trying to achieve can simply be made using a regular @Requires injection (or with the @Bind/@Unbind annotations, if you want to be notified when an algorithm arrives or leaves).

Your Algorithm class is the service specification. You concrete class should be a component registering the Algorithm service:

@Component
@Provides
@Instantiate
public ConcreteClass implements Algorithm {
   //...
}

Notice that because it’s a component, the concrete class constructor must be either without parameter or use @Property to inject values.

Finally, your ‘extender’ is just:

@Component(immediate=true
@Provides
@Instantiate
public Host {

    @Requires
     Algorithm[] algorithms;

}

To answer your initial question, the extender is looking for bundle’s manifest entry, which does not seem adequate in your context. 

Regards,

Clement


On 5 juin 2014, at 18:34, Luis Neto <lc...@gmail.com> wrote:

> Hi all, sorry if this question is to naive but i am struggling to
> understand how
> iPOJO indentifies the extender matching bundles.
> 
> I have a super class and a concrete class that i want to perform some
> logic, first i have
> thought that iPOJO automatically by declaring the property:
> 
>> <provides specifications="Algorithm"/>
>> 
> on the concrete class.
> 
> Then i've done some more reading and i have seen the PAX-WEB example and i
> tried to declare
> the property <Algorithm> in the concrete class bundle manifest header.
> 
> So my question is how to declare the property so the extender service can
> identify the bundle?
> 
> I've declared and implemented my extender service as follows:
> 
> 
>    <component
>>        classname="com.MyExtender"
>>        name = "MyExtender" public="false">
>>        <extender:extender
>>            extension="Algorithm" onArrival="onBundleArrival"
>> onDeparture="onBundleDeparture" />
>>        <callback transition="invalidate" method="stop" />
>>        <callback transition="validate" method="start" />
>>    </component>
>>    <instance
>>        name="algorithm.extender"
>>        component="MyExtender">
>>    </instance>
>> 
> 
> The superclass:
> 
> public abstract class Algorithm{
>> 
>> String name;
>> String version;
>> 
>> public Algorithm(String name, String version){
>>    this.name = name;
>>    this.version = version;
>> }
>> 
>> public String getName(){
>>    return name;
>> }
>> ...
>> 
>> abstract public void computeSomething(Map<a,b> data);
>> 
> 
> And concrete subclasses as follows:
> 
> public class ConcreteAlgorithm extends Algorithm{
>> 
>> Map<a,b> data;
>> 
>> public ConcreteAlgorithm(String name, Map<a,b> data){
>>    super(name);
>>    data = data;
>> }
>> 
>> public void computeSomething(Map<a,b> data){
>>    //compute data
>> }
> 
> 
> Best regards,
> Luis


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org