You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by "Gay David (Annecy)" <dg...@axway.com> on 2011/06/07 18:33:41 UTC

iPojo and @ServiceController

Hi all,

I'm trying to play with iPojo @ServiceController and I have some problems.
Maybe what I'm doing is not good, but I can't find out what could be my error.

I attach a simple test case that reproduce the error.

Basically I have 2 component : one that provide a service [ControlServiceImpl] and one that look up for all this service.
I made a simple OSGi command to play with it.

The [ControlServiceImpl] is using a ServiceController to expose the service to the OSGi registry.
The exposition is computed from a service property : enabled.

When I create a [ControlServiceImpl] with enabled = false it ok : the service is not see by the other service [ControlServiceConsumer]

But when I create a [ControlServiceImpl] with enabled = true, the service is bind, then unbind, then rebind

See the felix shell console :

-> ps
START LEVEL 1
   ID   State         Level  Name
[   0] [Active     ] [    0] System Bundle (3.2.2)
[   1] [Active     ] [    1] Unnamed - rank.test:ipojo:bundle:0.0.1-SNAPSHOT (0.0.1.SNAPSHOT)
[   2] [Active     ] [    1] Apache Felix Bundle Repository (1.6.2)
[   3] [Active     ] [    1] Apache Felix iPOJO (1.8.0)
[   4] [Active     ] [    1] Apache Felix iPOJO Arch Command (1.6.0)
[   5] [Active     ] [    1] Apache Felix Shell Service (1.4.2)
[   6] [Active     ] [    1] Apache Felix Shell TUI (1.4.1)

* Create a disabled [ControlServiceImpl]

-> control-create false
ControlServiceImpl - init()
ControlServiceImpl - updated, set service exposition to false
ControlServiceImpl - validate and set to :false

* It's ok, now create a enabled one :

-> control-create true
ControlServiceImpl - init()
ControlServiceImpl - updated, set service exposition to true
ControlServiceImpl - validate and set to :true
Bind control service : service.controller.ipojo.ControlServiceImpl@1922221
UnBind control service : service.controller.ipojo.ControlServiceImpl@1922221
Bind control service : service.controller.ipojo.ControlServiceImpl@1922221<ma...@1922221>

See how the create service is binded, then unbind, then bind again.


Is it a problem with iPojo ? Where is my mistake ?

BTW : another strange behavior, if you modify the class ControlServiceImpl like that (no @validate @invalidate) nothing works :

@Component( name="ControlServiceImpl" )
@Provides
public class ControlServiceImpl implements ControlService
{
    @ServiceController( false )
    private boolean active;

    @Property(mandatory=true)
    private boolean     enabled;



    public ControlServiceImpl()
    {
        System.out.println( "ControlServiceImpl - init()" );
    }

    @Override
    public String doIt()
    {
        return "I do it now !";
    }

    @Updated
    private void updated( Dictionary config )
    {
active = enabled;
        System.out.println( "ControlServiceImpl - updated, set service exposition to "+enabled );
    }

}

PS : I use iPojo 1.8.0 ... (also tested with 1.6.4)

Thanks for any help

Regards
David



Re: iPojo and @ServiceController

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

It was related to https://issues.apache.org/jira/browse/FELIX-2989 that I
just fixed. Thanks for your use case !
So you can use the version from trunk which contains the fix.

Regards,

Clement

From:  "Gay David (Annecy)" <dg...@axway.com>
Reply-To:  Apache Felix - Users Mailing List <us...@felix.apache.org>
Date:  Tue, 7 Jun 2011 16:33:41 +0000
To:  Apache Felix - Users Mailing List <us...@felix.apache.org>
Subject:  iPojo and @ServiceController

> Hi all,
>  
> I¹m trying to play with iPojo @ServiceController and I have some problems.
> Maybe what I¹m doing is not good, but I can¹t find out what could be my error.
>  
> I attach a simple test case that reproduce the error.
>  
> Basically I have 2 component : one that provide a service [ControlServiceImpl]
> and one that look up for all this service.
> I made a simple OSGi command to play with it.
>  
> The [ControlServiceImpl] is using a ServiceController to expose the service to
> the OSGi registry.
> The exposition is computed from a service property : enabled.
>  
> When I create a [ControlServiceImpl] with enabled = false it ok : the service
> is not see by the other service [ControlServiceConsumer]
>  
> But when I create a [ControlServiceImpl] with enabled = true, the service is
> bind, then unbind, then rebind
>  
> See the felix shell console :
>  
> -> ps
> START LEVEL 1
>    ID   State         Level  Name
> [   0] [Active     ] [    0] System Bundle (3.2.2)
> [   1] [Active     ] [    1] Unnamed - rank.test:ipojo:bundle:0.0.1-SNAPSHOT
> (0.0.1.SNAPSHOT)
> [   2] [Active     ] [    1] Apache Felix Bundle Repository (1.6.2)
> [   3] [Active     ] [    1] Apache Felix iPOJO (1.8.0)
> [   4] [Active     ] [    1] Apache Felix iPOJO Arch Command (1.6.0)
> [   5] [Active     ] [    1] Apache Felix Shell Service (1.4.2)
> [   6] [Active     ] [    1] Apache Felix Shell TUI (1.4.1)
>  
> * Create a disabled [ControlServiceImpl]
>  
> -> control-create false
> ControlServiceImpl - init()
> ControlServiceImpl - updated, set service exposition to false
> ControlServiceImpl - validate and set to :false
>  
> * It¹s ok, now create a enabled one :
>  
> -> control-create true
> ControlServiceImpl - init()
> ControlServiceImpl - updated, set service exposition to true
> ControlServiceImpl - validate and set to :true
> Bind control service : service.controller.ipojo.ControlServiceImpl@1922221
> UnBind control service : service.controller.ipojo.ControlServiceImpl@1922221
> Bind control service : service.controller.ipojo.ControlServiceImpl@1922221
>  
> See how the create service is binded, then unbind, then bind again.
>  
>  
> Is it a problem with iPojo ? Where is my mistake ?
>  
> BTW : another strange behavior, if you modify the class ControlServiceImpl
> like that (no @validate @invalidate) nothing works :
>  
> @Component( name="ControlServiceImpl" )
> @Provides
> public class ControlServiceImpl implements ControlService
> {
>     @ServiceController( false )
>     private boolean active;
>  
>     @Property(mandatory=true)
>     private boolean     enabled;
>    
>     
>     
>     public ControlServiceImpl()
>     {
>         System.out.println( "ControlServiceImpl - init()" );
>     }
>  
>     @Override
>     public String doIt()
>     {
>         return "I do it now !";
>     }
>  
>     @Updated
>     private void updated( Dictionary config )
>     {
> active = enabled;
>         System.out.println( "ControlServiceImpl - updated, set service
> exposition to "+enabled );
>     }
>  
> }
>  
> PS : I use iPojo 1.8.0 Š (also tested with 1.6.4)
>  
> Thanks for any help
>  
> Regards
> David
>  
>  
> --------------------------------------------------------------------- To
> unsubscribe, e-mail: users-unsubscribe@felix.apache.org For additional
> commands, e-mail: users-help@felix.apache.org