You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by jaredmac <jm...@mathworks.com> on 2008/06/09 22:55:54 UTC

Wait for services to be fully registered?

Hello,

I'm using Felix/SCR for a GUI application. GUI clients want to know what
services have registered with a certain interface. However, I get
non-deterministic behavior when GUI clients make this query (which occurs
right after bundles have been started): i.e., sometimes, there will be 2
services registered, other times 3 or 4. With some debugging, I can see that
ServiceEvents are being fired asynchronously as these services are
registered, and that occurs at the same time that the clients make their
query on a separate thread, leading to the non-determinism.

I get the impression reading the forum that my GUI clients should instead be
coded to react to/listen for new services coming on-line, rather than making
a query up-front... but I was hoping to insulate my GUI code from this,
because the GUI, as it currently stands, should be static once everything is
initialized.

So what I'd like is the following:

1. Bundles installed, started
2. Services registered
3. Clients ask for list of services, get deterministic answer

Is this possible, even if not recommended?

Thanks,
Jared
-- 
View this message in context: http://www.nabble.com/Wait-for-services-to-be-fully-registered--tp17741822p17741822.html
Sent from the Apache Felix - Users mailing list archive at Nabble.com.


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


Re: Wait for services to be fully registered?

Posted by Stuart McCulloch <st...@jayway.net>.
2008/6/10 Felix Meschberger <fm...@gmail.com>:

> Hi,
>
> Am Montag, den 09.06.2008, 13:55 -0700 schrieb jaredmac:
> > I'm using Felix/SCR for a GUI application. GUI clients want to know what
> > services have registered with a certain interface. However, I get
> > non-deterministic behavior when GUI clients make this query (which occurs
> > right after bundles have been started): i.e., sometimes, there will be 2
> > services registered, other times 3 or 4. With some debugging, I can see
> that
> > ServiceEvents are being fired asynchronously as these services are
> > registered, and that occurs at the same time that the clients make their
> > query on a separate thread, leading to the non-determinism.
>
> Well, this non-determinstism is by design. OSGi frameworks are dynamic
> where everything can come and go virtually at any time. This is very
> important and powerful. The drawback - if you will - of this is, that
> you have to be aware of this situation, which may be very uncommon at
> first sight. If you get used to it, it is like heaven ;-)
>
> Now, for your situation, the problem is, that as a service consumer you
> cannot tell, at which time "all" services are registered, because there
> is no notion of "all" services.
>
> >
> > I get the impression reading the forum that my GUI clients should instead
> be
> > coded to react to/listen for new services coming on-line, rather than
> making
> > a query up-front...
>
> Yes. This is a good thing and probably the only thing you can do.
>

while I agree that making your GUI more dynamic is typically a good thing,
it isn't necessarily the only thing you can do - another solution would be
to
use the "extender pattern" (http://www.aqute.biz/Snippets/Extender)

the extender pattern concept is to watch for bundles with special metadata
and act accordingly - because bundles are more coarsely grained you can
avoid some of the asynchronous issues that you see with services.

this is what Eclipse does - bundles (aka plug-ins) contribute extensions to
extension points by using metadata stored inside the bundle (plugin.xml).

the set of installed bundles is scanned at start-up and this metadata is
then
aggregated into what's known as the "Extension Point Registry" - while this
is much less dynamic than services, some feel it is a better fit for GUIs

so you could do something similar - have either a file, or manifest header,
that you watch out for - and arrange for all your service bundles to have
the
relevant metadata. Then you just need to ensure the service bundles start
before the client bundles (perhaps using start-levels or a manager bundle)

such a solution isn't as robust as a dynamic GUI that can handle bundles
appearing and disappearing on the fly - but it can be simpler to develop
and manage, especially if you have full control over the framework.

PS. you might also find this comparison interesting:


http://eclipse.dzone.com/articles/comparison-eclipse-extensions-and-osgi-services

HTH

>  but I was hoping to insulate my GUI code from this,
> > because the GUI, as it currently stands, should be static once everything
> is
> > initialized.
>
> Using SCR you can in fact isolate your clients from OSGi specific code:
> In that you declare a binding method (don't forget the unbind method !)
> the SCR will call the component whenever a new service arives (and goes
> away). So the component -- presumably the client ? -- will always be up
> to date and have the current list of services available.
>
> >
> > So what I'd like is the following:
> >
> > 1. Bundles installed, started
> > 2. Services registered
> > 3. Clients ask for list of services, get deterministic answer
>
> Clients always get a deterministic answer: The services registered at
> the time of the call. The non-determinism comes from the fact, that the
> services are registered asynchronously, which is by design and good.
>
> Hope this helps.
>
> Regards
> Felix
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
>


-- 
Cheers, Stuart

Re: EventAdmin hangs when starting felix

Posted by pa...@theokorigroup.com.
I'm using Felix 1.0.4 on a 64 bit Linux machine running Ubuntu 8.04. I'm having trouble generating a thread dump. When I hit Ctrl-\, the process simply exists without a stack trace. Same when I kill it from another terminal window. I have likewise had no luck using jstacktrace. Looking around on the web, it seems this may be Ubuntu issue. I'll keep trying.

--
Parker Abercrombie <FI...@gmail.com>


On Wed, 23 Jul 2008 09:50:37 +0200, "Karl Pauls" <ka...@gmail.com> wrote:
> Can you provide me with a little bit more information and a thread
> dump please? What version of Felix are you using and what OS are you
> running? You can create a thread dump as described at
> http://java.sun.com/developer/technicalArticles/Programming/Stacktrace/
> 
> regards,
> 
> Karl
> 
> On Wed, Jul 23, 2008 at 3:24 AM,  <pa...@theokorigroup.com>
> wrote:
>> When I start Felix, sometimes the process hangs. It doesn't happen every
> time. Maybe a race condition somewhere?
>>
>> This is my output, up to where things lock up:
>>
>> Welcome to Felix.
>> =================
>>
>> DEBUG: WIRE: 41.0 -> org.osgi.service.packageadmin -> 0
>> DEBUG: WIRE: 41.0 -> org.ungoverned.osgi.service.shell -> 41.0
>> DEBUG: WIRE: 41.0 -> org.osgi.service.startlevel -> 0
>> DEBUG: WIRE: 41.0 -> org.osgi.framework -> 0
>> DEBUG: WIRE: 41.0 -> org.apache.felix.shell -> 41.0
>> DEBUG: WIRE: 42.0 -> org.osgi.framework -> 0
>> DEBUG: WIRE: 42.0 -> org.apache.felix.shell -> 41.0
>> -> DEBUG: WIRE: 43.0 -> org.osgi.service.obr -> 43.0
>> DEBUG: WIRE: 43.0 -> org.osgi.framework -> 0
>> DEBUG: WIRE: 43.0 -> org.apache.felix.shell -> 41.0
>> DEBUG: WIRE: 44.0 -> org.osgi.framework -> 0
>> DEBUG: WIRE: 44.0 -> org.osgi.service.cm -> 44.0
>> DEBUG: WIRE: 44.0 -> org.apache.felix.shell -> 41.0
>> DEBUG: WIRE: 44.0 -> org.apache.felix.scr -> 44.0
>> DEBUG: WIRE: 44.0 -> org.osgi.service.component -> 44.0
>> DEBUG: WIRE: 45.0 -> org.osgi.service.event -> 45.0
>> DEBUG: WIRE: 45.0 -> org.osgi.framework -> 0
>> DEBUG: EventAdmin: org.apache.felix.eventadmin.CacheSize=30
>> DEBUG: EventAdmin: org.apache.felix.eventadmin.ThreadPoolSize=10
>> DEBUG: EventAdmin: org.apache.felix.eventadmin.Timeout=5000
>> DEBUG: EventAdmin: org.apache.felix.eventadmin.RequireTopic=true
>>
>>
>> Any ideas?
>>
>> --
>> Parker Abercrombie <FI...@gmail.com>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>> For additional commands, e-mail: users-help@felix.apache.org
>>
>>
> 
> 
> 
> --
> Karl Pauls
> karlpauls@gmail.com
> 
> ---------------------------------------------------------------------
> 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: EventAdmin hangs when starting felix

Posted by Karl Pauls <ka...@gmail.com>.
Can you provide me with a little bit more information and a thread
dump please? What version of Felix are you using and what OS are you
running? You can create a thread dump as described at
http://java.sun.com/developer/technicalArticles/Programming/Stacktrace/

regards,

Karl

On Wed, Jul 23, 2008 at 3:24 AM,  <pa...@theokorigroup.com> wrote:
> When I start Felix, sometimes the process hangs. It doesn't happen every time. Maybe a race condition somewhere?
>
> This is my output, up to where things lock up:
>
> Welcome to Felix.
> =================
>
> DEBUG: WIRE: 41.0 -> org.osgi.service.packageadmin -> 0
> DEBUG: WIRE: 41.0 -> org.ungoverned.osgi.service.shell -> 41.0
> DEBUG: WIRE: 41.0 -> org.osgi.service.startlevel -> 0
> DEBUG: WIRE: 41.0 -> org.osgi.framework -> 0
> DEBUG: WIRE: 41.0 -> org.apache.felix.shell -> 41.0
> DEBUG: WIRE: 42.0 -> org.osgi.framework -> 0
> DEBUG: WIRE: 42.0 -> org.apache.felix.shell -> 41.0
> -> DEBUG: WIRE: 43.0 -> org.osgi.service.obr -> 43.0
> DEBUG: WIRE: 43.0 -> org.osgi.framework -> 0
> DEBUG: WIRE: 43.0 -> org.apache.felix.shell -> 41.0
> DEBUG: WIRE: 44.0 -> org.osgi.framework -> 0
> DEBUG: WIRE: 44.0 -> org.osgi.service.cm -> 44.0
> DEBUG: WIRE: 44.0 -> org.apache.felix.shell -> 41.0
> DEBUG: WIRE: 44.0 -> org.apache.felix.scr -> 44.0
> DEBUG: WIRE: 44.0 -> org.osgi.service.component -> 44.0
> DEBUG: WIRE: 45.0 -> org.osgi.service.event -> 45.0
> DEBUG: WIRE: 45.0 -> org.osgi.framework -> 0
> DEBUG: EventAdmin: org.apache.felix.eventadmin.CacheSize=30
> DEBUG: EventAdmin: org.apache.felix.eventadmin.ThreadPoolSize=10
> DEBUG: EventAdmin: org.apache.felix.eventadmin.Timeout=5000
> DEBUG: EventAdmin: org.apache.felix.eventadmin.RequireTopic=true
>
>
> Any ideas?
>
> --
> Parker Abercrombie <FI...@gmail.com>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
>



-- 
Karl Pauls
karlpauls@gmail.com

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


EventAdmin hangs when starting felix

Posted by pa...@theokorigroup.com.
When I start Felix, sometimes the process hangs. It doesn't happen every time. Maybe a race condition somewhere?

This is my output, up to where things lock up:

Welcome to Felix.
=================

DEBUG: WIRE: 41.0 -> org.osgi.service.packageadmin -> 0
DEBUG: WIRE: 41.0 -> org.ungoverned.osgi.service.shell -> 41.0
DEBUG: WIRE: 41.0 -> org.osgi.service.startlevel -> 0
DEBUG: WIRE: 41.0 -> org.osgi.framework -> 0
DEBUG: WIRE: 41.0 -> org.apache.felix.shell -> 41.0
DEBUG: WIRE: 42.0 -> org.osgi.framework -> 0
DEBUG: WIRE: 42.0 -> org.apache.felix.shell -> 41.0
-> DEBUG: WIRE: 43.0 -> org.osgi.service.obr -> 43.0
DEBUG: WIRE: 43.0 -> org.osgi.framework -> 0
DEBUG: WIRE: 43.0 -> org.apache.felix.shell -> 41.0
DEBUG: WIRE: 44.0 -> org.osgi.framework -> 0
DEBUG: WIRE: 44.0 -> org.osgi.service.cm -> 44.0
DEBUG: WIRE: 44.0 -> org.apache.felix.shell -> 41.0
DEBUG: WIRE: 44.0 -> org.apache.felix.scr -> 44.0
DEBUG: WIRE: 44.0 -> org.osgi.service.component -> 44.0
DEBUG: WIRE: 45.0 -> org.osgi.service.event -> 45.0
DEBUG: WIRE: 45.0 -> org.osgi.framework -> 0
DEBUG: EventAdmin: org.apache.felix.eventadmin.CacheSize=30
DEBUG: EventAdmin: org.apache.felix.eventadmin.ThreadPoolSize=10
DEBUG: EventAdmin: org.apache.felix.eventadmin.Timeout=5000
DEBUG: EventAdmin: org.apache.felix.eventadmin.RequireTopic=true


Any ideas?

--
Parker Abercrombie <FI...@gmail.com>


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


Re: Wait for services to be fully registered?

Posted by jaredmac <jm...@mathworks.com>.

Marcel Offermans wrote:
> 
> On Aug 22, 2008, at 17:05 , jaredmac wrote:
> 
>> Just to close the loop on this thread, start levels work great to  
>> accomplish
>> what I need. [...] I realize this might not be in Felix's "design  
>> center," but until our GUI is
>> ready for more dynamic, asynchronous contribution, this works  
>> beautifully.
>> Thanks for everyone's help.
> 
> Not to re-open the discussion, but make sure you go down in start  
> level before updating any bundle to avoid breaking stuff on updates.  
> After the updates, go back up.
> 

Right, thanks. We're far away from updating bundles, but I will keep this in
mind! :)
-- 
View this message in context: http://www.nabble.com/Wait-for-services-to-be-fully-registered--tp17741822p19109728.html
Sent from the Apache Felix - Users mailing list archive at Nabble.com.


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


Re: Wait for services to be fully registered?

Posted by Marcel Offermans <ma...@luminis.nl>.
On Aug 22, 2008, at 17:05 , jaredmac wrote:

> Just to close the loop on this thread, start levels work great to  
> accomplish
> what I need. [...] I realize this might not be in Felix's "design  
> center," but until our GUI is
> ready for more dynamic, asynchronous contribution, this works  
> beautifully.
> Thanks for everyone's help.

Not to re-open the discussion, but make sure you go down in start  
level before updating any bundle to avoid breaking stuff on updates.  
After the updates, go back up.

Greetings, Marcel


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


Re: Wait for services to be fully registered?

Posted by jaredmac <jm...@mathworks.com>.

Richard S. Hall wrote:
> 
> Could you send your entire configuration?
> 
> -> richard
> 
> jaredmac wrote:
>> Richard S. Hall wrote:
>>   
>>> No, this is not possible. However, in the config.properties file (or if 
>>> you are embedding a Felix instance, then you pass in the configuration 
>>> properties), you can specify which start level bundles will be installed 
>>> with. Check this document for the configuration properties:
> 

Just to close the loop on this thread, start levels work great to accomplish
what I need. Basically, I did the following:

1. Set the Start Level of the "consumer" GUI client bundle to 10 (arbitrary)
2. Leave the Start Level of the "producer" bundles at 1, their default
3. When Felix is installing bundles, it keeps track of the highest Start
Level it has seen. Then it sets its own Start Level to that value.

I realize this might not be in Felix's "design center," but until our GUI is
ready for more dynamic, asynchronous contribution, this works beautifully.
Thanks for everyone's help.
-- 
View this message in context: http://www.nabble.com/Wait-for-services-to-be-fully-registered--tp17741822p19108780.html
Sent from the Apache Felix - Users mailing list archive at Nabble.com.


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


Re: Wait for services to be fully registered?

Posted by "Richard S. Hall" <he...@ungoverned.org>.
Could you send your entire configuration?

-> richard

jaredmac wrote:
> Richard S. Hall wrote:
>   
>> No, this is not possible. However, in the config.properties file (or if 
>> you are embedding a Felix instance, then you pass in the configuration 
>> properties), you can specify which start level bundles will be installed 
>> with. Check this document for the configuration properties:
>>
>>     
>
> OK, thanks. This is helpful. I have assigned bundles start levels and told
> Felix to employ a start level that is higher than the bundles I've assigned
> -- i.e., the client bundles have start level "2" and Felix has start level
> "5":
>
>         configuration.put(FelixConstants.FRAMEWORK_STARTLEVEL_PROP, "5");
>
> At this point, shouldn't I expect those bundles to be ... automatically
> started? I'm confused by this JavaDoc:
>
> http://www2.osgi.org/javadoc/r4/org/osgi/service/startlevel/StartLevel.html
>
> It says: "When the Framework is launched, the Framework will enter start
> level one and all bundles which are assigned to start level one and whose
> autostart setting indicates the bundle should be started are started as
> described in the Bundle.start method. The Framework will continue to
> increase the start level, starting bundles at each start level, until the
> Framework has reached a beginning start level."
>
> So, I would think that I expect Felix to start at 0, then proceed up by one
> till it reaches 5, starting my bundles that have start level "2" along the
> way. But this doesn't appear to happen - the bundles simply remain in the
> INSTALLED state.
>
> Am I misunderstanding something in the doc, or doing something wrong?
>
> Thanks,
> Jared
>   

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


Re: Wait for services to be fully registered?

Posted by jaredmac <jm...@mathworks.com>.

Richard S. Hall wrote:
> 
> No, this is not possible. However, in the config.properties file (or if 
> you are embedding a Felix instance, then you pass in the configuration 
> properties), you can specify which start level bundles will be installed 
> with. Check this document for the configuration properties:
> 

OK, thanks. This is helpful. I have assigned bundles start levels and told
Felix to employ a start level that is higher than the bundles I've assigned
-- i.e., the client bundles have start level "2" and Felix has start level
"5":

        configuration.put(FelixConstants.FRAMEWORK_STARTLEVEL_PROP, "5");

At this point, shouldn't I expect those bundles to be ... automatically
started? I'm confused by this JavaDoc:

http://www2.osgi.org/javadoc/r4/org/osgi/service/startlevel/StartLevel.html

It says: "When the Framework is launched, the Framework will enter start
level one and all bundles which are assigned to start level one and whose
autostart setting indicates the bundle should be started are started as
described in the Bundle.start method. The Framework will continue to
increase the start level, starting bundles at each start level, until the
Framework has reached a beginning start level."

So, I would think that I expect Felix to start at 0, then proceed up by one
till it reaches 5, starting my bundles that have start level "2" along the
way. But this doesn't appear to happen - the bundles simply remain in the
INSTALLED state.

Am I misunderstanding something in the doc, or doing something wrong?

Thanks,
Jared
-- 
View this message in context: http://www.nabble.com/Wait-for-services-to-be-fully-registered--tp17741822p18517230.html
Sent from the Apache Felix - Users mailing list archive at Nabble.com.


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


Re: Wait for services to be fully registered?

Posted by "Richard S. Hall" <he...@ungoverned.org>.
jaredmac wrote:
> Richard S. Hall wrote:
>   
>> However, if you really want to make sure everything starts before your 
>> GUI, you can put all of your service bundles in a lower start level than 
>> your GUI bundle; thus, by the time the GUI bundle starts, then all your 
>> services will be available.
>>
>>     
>
> Just following up on this. I want to do something like:
>
> Bundle-Name: Blah
> Bundle-SymbolicName: org.blah
> Bundle-Start-Level: 5
>
> in the Manifest. Is that possible? I see the Java API for it but no more
> dynamic approach.
>   

No, this is not possible. However, in the config.properties file (or if 
you are embedding a Felix instance, then you pass in the configuration 
properties), you can specify which start level bundles will be installed 
with. Check this document for the configuration properties:

    
http://cwiki.apache.org/FELIX/apache-felix-usage-documentation.html#ApacheFelixUsageDocumentation-configuringfelix

-> richard

> Thanks!
> Jared
>   

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


Re: Wait for services to be fully registered?

Posted by jaredmac <jm...@mathworks.com>.

Richard S. Hall wrote:
> 
> However, if you really want to make sure everything starts before your 
> GUI, you can put all of your service bundles in a lower start level than 
> your GUI bundle; thus, by the time the GUI bundle starts, then all your 
> services will be available.
> 

Just following up on this. I want to do something like:

Bundle-Name: Blah
Bundle-SymbolicName: org.blah
Bundle-Start-Level: 5

in the Manifest. Is that possible? I see the Java API for it but no more
dynamic approach.

Thanks!
Jared
-- 
View this message in context: http://www.nabble.com/Wait-for-services-to-be-fully-registered--tp17741822p18497267.html
Sent from the Apache Felix - Users mailing list archive at Nabble.com.


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


Re: Wait for services to be fully registered?

Posted by "Richard S. Hall" <he...@ungoverned.org>.
I guess I cannot understand why you would want to keep old test cases 
that are no longer applicable to the new architecture of your 
system...makes more sense to change the test cases to me.

However, if you really want to make sure everything starts before your 
GUI, you can put all of your service bundles in a lower start level than 
your GUI bundle; thus, by the time the GUI bundle starts, then all your 
services will be available.

-> richard

jaredmac wrote:
> Felix Meschberger-2 wrote:
>   
>> Clients always get a deterministic answer: The services registered at
>> the time of the call. The non-determinism comes from the fact, that the
>> services are registered asynchronously, which is by design and good.
>>
>>     
>
> Thanks for the explanation. You mentioned a few times that the
> non-determinism is good. I can see how that would be the true in some cases,
> and not so much in others.
>
> As it is, I have unit tests in which I do not want to introduce regressions,
> and these tests are checking that the program has a certain appearance --
> specifically, it is examining the state of the user interface's menu items.
> I have turned these menu items into bundles, such that each bundle can
> contribute to the UI.
>
> So even if I change my client to respond to bind() and unbind() methods, and
> dynamically register/unregister these menu items, then the UI will work
> correctly (with menu items coming and going, I suppose), but the unit tests
> still fail. I want to avoid that.
>
> As I describe my situation, I get the impression that I should be using
> extensions rather than services... but I have not yet tried using extensions
> with Felix (that would require Equinox?). So far, I was enjoying the
> simplicity of Felix + SCR, because it has gotten me 95% of the way there.
>
> But I will look into these alternate approaches and report back. Thanks for
> the help.
>   

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


Re: Wait for services to be fully registered?

Posted by Bertrand Delacretaz <bd...@apache.org>.
On Wed, Jun 11, 2008 at 3:31 PM, jaredmac <jm...@mathworks.com> wrote:

> ...So even if I change my client to respond to bind() and unbind() methods, and
> dynamically register/unregister these menu items, then the UI will work
> correctly (with menu items coming and going, I suppose), but the unit tests
> still fail. I want to avoid that....

I was confronted with the same problem when writing the integration
tests for Sling [1], and my (pragmatic) solution is, when the
integration tests start, to run some initial tests repeatedly until
the results show a stable state, or a timer expires.

In the case of Sling, those initial tests execute some simple
high-level operations that only work if all services required to run
the integration tests are present. That's a somewhat brute-force way
of finding out about the state of our system, but it is simple to
understand and debug, and works for us. We are planning to integrate
this "system readyness testing" into the platform, see SLING-490.

-Bertrand

[1]  http://svn.eu.apache.org/repos/asf/incubator/sling/trunk/launchpad/webapp

[2] See waitForSlingStartup() method in
http://svn.eu.apache.org/repos/asf/incubator/sling/trunk/commons/testing/src/main/java/org/apache/sling/commons/testing/integration/HttpTestBase.java

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


Re: Wait for services to be fully registered?

Posted by jaredmac <jm...@mathworks.com>.

Felix Meschberger-2 wrote:
> 
> Clients always get a deterministic answer: The services registered at
> the time of the call. The non-determinism comes from the fact, that the
> services are registered asynchronously, which is by design and good.
> 

Thanks for the explanation. You mentioned a few times that the
non-determinism is good. I can see how that would be the true in some cases,
and not so much in others.

As it is, I have unit tests in which I do not want to introduce regressions,
and these tests are checking that the program has a certain appearance --
specifically, it is examining the state of the user interface's menu items.
I have turned these menu items into bundles, such that each bundle can
contribute to the UI.

So even if I change my client to respond to bind() and unbind() methods, and
dynamically register/unregister these menu items, then the UI will work
correctly (with menu items coming and going, I suppose), but the unit tests
still fail. I want to avoid that.

As I describe my situation, I get the impression that I should be using
extensions rather than services... but I have not yet tried using extensions
with Felix (that would require Equinox?). So far, I was enjoying the
simplicity of Felix + SCR, because it has gotten me 95% of the way there.

But I will look into these alternate approaches and report back. Thanks for
the help.
-- 
View this message in context: http://www.nabble.com/Wait-for-services-to-be-fully-registered--tp17741822p17777677.html
Sent from the Apache Felix - Users mailing list archive at Nabble.com.


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


Re: Wait for services to be fully registered?

Posted by Felix Meschberger <fm...@gmail.com>.
Hi,

Am Montag, den 09.06.2008, 13:55 -0700 schrieb jaredmac:
> I'm using Felix/SCR for a GUI application. GUI clients want to know what
> services have registered with a certain interface. However, I get
> non-deterministic behavior when GUI clients make this query (which occurs
> right after bundles have been started): i.e., sometimes, there will be 2
> services registered, other times 3 or 4. With some debugging, I can see that
> ServiceEvents are being fired asynchronously as these services are
> registered, and that occurs at the same time that the clients make their
> query on a separate thread, leading to the non-determinism.

Well, this non-determinstism is by design. OSGi frameworks are dynamic
where everything can come and go virtually at any time. This is very
important and powerful. The drawback - if you will - of this is, that
you have to be aware of this situation, which may be very uncommon at
first sight. If you get used to it, it is like heaven ;-)

Now, for your situation, the problem is, that as a service consumer you
cannot tell, at which time "all" services are registered, because there
is no notion of "all" services.

> 
> I get the impression reading the forum that my GUI clients should instead be
> coded to react to/listen for new services coming on-line, rather than making
> a query up-front...

Yes. This is a good thing and probably the only thing you can do.

>  but I was hoping to insulate my GUI code from this,
> because the GUI, as it currently stands, should be static once everything is
> initialized.

Using SCR you can in fact isolate your clients from OSGi specific code:
In that you declare a binding method (don't forget the unbind method !)
the SCR will call the component whenever a new service arives (and goes
away). So the component -- presumably the client ? -- will always be up
to date and have the current list of services available.

> 
> So what I'd like is the following:
> 
> 1. Bundles installed, started
> 2. Services registered
> 3. Clients ask for list of services, get deterministic answer

Clients always get a deterministic answer: The services registered at
the time of the call. The non-determinism comes from the fact, that the
services are registered asynchronously, which is by design and good.

Hope this helps.

Regards
Felix


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