You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Nicolas Delsaux <ni...@gmail.com> on 2010/04/27 16:02:45 UTC

[iPojo] conditionnal service activation

hi all,
as an exercise, i try to create a small Swing program relying upon
OSGi and, specifically, upon Felix and iPojo. In a few words, I try to
copy the features of Quicksilver/Launchy/Gnome DO.
So, for that, I have some services, implementing the UIStarter
interface, that have registered listeners, implementing the
HotKeyListener interface. To aggregate the whole, I also use a Control
service, which implements the HotKeyListener interface and tries to
get all the UIStarter services.
As a consequence, my Control service has the following code fragment

@Requires
private UIStarter[] starters;

@valdiate
public void initialize() {
}


What I planned tyo do was creating a WindowsUIStarter, using a
windows-specific java library (in my case, JIntelliType) to register
windows hotkeys, and other system-specific libraries for mac, linux,
and so on ...
Unfortunatly, JIntelliType fails to load (this is not the subject of
my question, but rather its trigger). As a consequence, my
WindowsUIStarter instance fails to validate. From my guesses, this, in
turns, prevents the Control#initialize method to be called, making all
of my code inactive.

Now, here comme my question : how is it possible, using pure
osgi/scr/ipojo, to define "optionnel" services, that's to say services
which non loading won't prevent my Control service to load. I
understand it is perfectly possible using pure OSGi and
ServcieListener interface (like in Felix tutorial
http://felix.apache.org/site/apache-felix-tutorial-example-1.html).
But, is there any way to do that in a more IoC-like fashion ?
Or, in an other fashion, prior to the call of @Validate, is my
starters array already filled with service (maybe invalid ones) ?

Thanks

-- 
Nicolas Delsaux

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


Re: [iPojo] conditionnal service activation

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

On 27.04.2010, at 17:17, Nicolas Delsaux wrote:

> On Tue, Apr 27, 2010 at 4:55 PM, Richard S. Hall <he...@ungoverned.org> wrote:
>> 
>> I assume it is not this easy, but are you looking for:
>> 
>>    @Requires(optional=true)
>>    private UIStarter[] starters;
>> 
>> ?
>> 
> Well, the question is .... how does it behaves when one of the
> required UIStarter services is not validated ? Is this service in the
> array ?

What do you called not validated ?
If the @Validate method throws an exception, the service will not be exposed, so not be in the array.
Moreover, a component implementation class can impacts the service registration with @ServiceController (freshly released in the 1.6.0).

Clement

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


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


Re: [iPojo] conditionnal service activation

Posted by "Richard S. Hall" <he...@ungoverned.org>.
On 4/27/10 11:17, Nicolas Delsaux wrote:
> On Tue, Apr 27, 2010 at 4:55 PM, Richard S. Hall<he...@ungoverned.org>  wrote:
>    
>> I assume it is not this easy, but are you looking for:
>>
>>     @Requires(optional=true)
>>     private UIStarter[] starters;
>>
>> ?
>>
>>      
> Well, the question is .... how does it behaves when one of the
> required UIStarter services is not validated ? Is this service in the
> array ?
>    

As Clement says, there really isn't such thing as a service that isn't 
valid. If its component isn't valid, then the service isn't published. 
Period. Therefore, your component will only see valid services, by 
definition (except normal OSGi race conditions).

-> richard

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


Re: [iPojo] conditionnal service activation

Posted by Nicolas Delsaux <ni...@gmail.com>.
On Tue, Apr 27, 2010 at 4:55 PM, Richard S. Hall <he...@ungoverned.org> wrote:
>
> I assume it is not this easy, but are you looking for:
>
>    @Requires(optional=true)
>    private UIStarter[] starters;
>
> ?
>
Well, the question is .... how does it behaves when one of the
required UIStarter services is not validated ? Is this service in the
array ?

-- 
Nicolas Delsaux

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


Re: [iPojo] conditionnal service activation

Posted by "Richard S. Hall" <he...@ungoverned.org>.
On 4/27/10 10:02, Nicolas Delsaux wrote:
> hi all,
> as an exercise, i try to create a small Swing program relying upon
> OSGi and, specifically, upon Felix and iPojo. In a few words, I try to
> copy the features of Quicksilver/Launchy/Gnome DO.
> So, for that, I have some services, implementing the UIStarter
> interface, that have registered listeners, implementing the
> HotKeyListener interface. To aggregate the whole, I also use a Control
> service, which implements the HotKeyListener interface and tries to
> get all the UIStarter services.
> As a consequence, my Control service has the following code fragment
>
> @Requires
> private UIStarter[] starters;
>
> @valdiate
> public void initialize() {
> }
>
>
> What I planned tyo do was creating a WindowsUIStarter, using a
> windows-specific java library (in my case, JIntelliType) to register
> windows hotkeys, and other system-specific libraries for mac, linux,
> and so on ...
> Unfortunatly, JIntelliType fails to load (this is not the subject of
> my question, but rather its trigger). As a consequence, my
> WindowsUIStarter instance fails to validate. From my guesses, this, in
> turns, prevents the Control#initialize method to be called, making all
> of my code inactive.
>
> Now, here comme my question : how is it possible, using pure
> osgi/scr/ipojo, to define "optionnel" services, that's to say services
> which non loading won't prevent my Control service to load. I
> understand it is perfectly possible using pure OSGi and
> ServcieListener interface (like in Felix tutorial
> http://felix.apache.org/site/apache-felix-tutorial-example-1.html).
> But, is there any way to do that in a more IoC-like fashion ?
> Or, in an other fashion, prior to the call of @Validate, is my
> starters array already filled with service (maybe invalid ones) ?
>    

I assume it is not this easy, but are you looking for:

     @Requires(optional=true)
     private UIStarter[] starters;

?

-> richard

> Thanks
>
>    

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