Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » Race problem in Java App and OSGI bundles start.
Race problem in Java App and OSGI bundles start. [message #90207] Mon, 11 June 2007 23:52 Go to next message
Cathy Sun is currently offline Cathy SunFriend
Messages: 7
Registered: July 2009
Junior Member
Hi,

I am using EclipseStarter.startup to start platform and programming to
load and start bundles/properties file in a certain folder of file system.
Then in my app I start to use the started services. But it turned out
that OSGI daemon thread SRC Work Queue is starting the bundles/
properties, and main thread start to use before SRC thread finished
service registration. If I put Thread.sleep() in main, It works. Is there
method to know all the bundles and properties file is processed and ready
for use?
I know there is bundle.state = active; how about properties file?

Cathy
Re: Race problem in Java App and OSGI bundles start. [message #90254 is a reply to message #90207] Tue, 12 June 2007 08:00 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: alex_blewitt.yahoo.com

The thing with dynamic systems is that you need to expect them to be dynamic :-)

If you have two bundles A and B, and it's important that A starts before B starts, you've got two possibilities:

1) Communicate via the service registry, so that A registers a service and B looks out for a service via a ServiceTracker/registry event listener. That way, A can come and go and B will still notice.

2) Set up the osgi.bundles property to start B at a higher start level than A, so something like:

osgi.bundles=A@2:start,B@3:start


That will ensure that A is started at level 2, and B is started at level 3. IIRC Eclipse usually goes up to level 5 or 6 when it starts, but there's no reason this number couldn't be bigger, and there's probably a system property that configures it (though I don't know what that is off the top of my head).

Alex.
Re: Race problem in Java App and OSGI bundles start. [message #90345 is a reply to message #90254] Tue, 12 June 2007 17:01 Go to previous messageGo to next message
Cathy Sun is currently offline Cathy SunFriend
Messages: 7
Registered: July 2009
Junior Member
If I have a bunch of bundles like more than 40, it takes time for [SRC
Work Queue] thread to start all of them, while the main thread happen to
start to use the one at the tail of Work Queue, how do I solve the race?


Even if I add start level to the bundles, the Main thread don’t actually
know if it is ready for use, especially in the configure properties file
let OSGI provide multiple service instance (use ManagedServiceFactory)


Main Thread --> EclipseStarter.startup --> start user service

SRC Work Queue Thread --> install/resolve/start bundle / property change
of service

Cathy
Re: Race problem in Java App and OSGI bundles start. [message #90464 is a reply to message #90345] Wed, 13 June 2007 18:05 Go to previous messageGo to next message
Thomas Watson is currently offline Thomas WatsonFriend
Messages: 503
Registered: July 2009
Senior Member
I assume your application is running on the main thread and is using a
service which is registered by the SCR (declarative services). In this
case you do not want your app on the main thread to continue until it
has detected that a particular service is registered from SCR. You
should user a ServiceTracker (from org.osgi.util.tracker package). Your
main thread should wait and be notified by by your ServiceTracker when
it detects that your required service are available.

something like this can be done in your application code:

ServiceTracker tracker =
new ServiceTracker(context, "foo.BarService", null);
tracker.open();
tracker.waitForService(10000);

If you need to wait for more than one service then you could use a
ServiceTracker with a Filter and a ServiceTrackerCustomizer to notify
your main thread but that is more complicated work. You could also use
a separate ServiceTracker for each service but that can get costly.

Another option is to make a service component for your application which
is uses immediate activation (may be using the wrong term here but I'm
sure there is a way to make a service component activate immediately
once all of its dependencies are met). This component would have to
notify your main thread to continue also so I'm not sure this is a more
simple option.

HTH

Tom.
Re: Race problem in Java App and OSGI bundles start. [message #91263 is a reply to message #90464] Wed, 27 June 2007 17:44 Go to previous messageGo to next message
Cathy Sun is currently offline Cathy SunFriend
Messages: 7
Registered: July 2009
Junior Member
Hi


It works using ServiceTracker. Thanks.


I have another problem, when I use EclipseStarter.shutdown() to shut down
framework, sometimes quite a few [ java.lang.IllegalStateException:
BundleContext is no longer valid ] pop out, it looks to me during shutdown
time, trying to register service but failed. ( It is same using
declarative services to register a service). Could you tell me how to
solve the problem, and why it happens?


Thanks

Cathy
Re: Race problem in Java App and OSGI bundles start. [message #91321 is a reply to message #91263] Thu, 28 June 2007 18:50 Go to previous messageGo to next message
Cathy Sun is currently offline Cathy SunFriend
Messages: 7
Registered: July 2009
Junior Member
Hi,

The following is the error trice, hope it will help to figure out.

EventAdmin: Exception thrown while dispatching an event, event =
org.osgi.service.event.Event [topic=org/osgi/service/log/LogEntry]
EventAdmin: exception = java.lang.IllegalStateException: BundleContext is
no longer valid
java.lang.IllegalStateException: BundleContext is no longer valid
at
org.eclipse.osgi.framework.internal.core.BundleContextImpl.c heckValid(BundleContextImpl.java:1305)
at
org.eclipse.osgi.framework.internal.core.BundleContextImpl.g etServiceReferences(BundleContextImpl.java:714)
at
org.eclipse.equinox.event.EventAdminImpl.getAllEventHandlers (EventAdminImpl.java:346)
at
org.eclipse.equinox.event.EventAdminImpl.dispatchEvent(Event AdminImpl.java:136)
at
org.eclipse.equinox.event.EventAdminImpl.postEvent(EventAdmi nImpl.java:101)
at
org.eclipsei.equinox.event.mapper.EventAdapter.redeliverInte rnal(EventAdapter.java:51)
at
org.eclipsei.equinox.event.mapper.EventAdapter.redeliver(Eve ntAdapter.java:42)
at
org.eclipsei.equinox.event.mapper.EventRedeliverer.logged(Ev entRedeliverer.java:209)
at
org.eclipse.equinox.log.LogReaderService.dispatchEvent(LogRe aderService.java:55)
at
org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEve nt(EventManager.java:189)
at
org.eclipse.osgi.framework.eventmgr.EventManager$EventThread .run(EventManager.java:291)
Re: Race problem in Java App and OSGI bundles start. [message #93189 is a reply to message #90207] Fri, 27 July 2007 13:31 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: diemarmeladenesserin.yahoo.de

Dear Cathy,

it seems that you know how to use EclipseStarter. Perhaps can you help me? I try to use an Eclipse RCP Project, but I cannot invoke it with the Launcher, but I need to invoke it from another Java-Class. I tried to test it with "EclipseStarter.startup(a, null);" but I don't know which Arguments I should use. I defined "String[] a = {"-application <application>", "-product nameOfTheProject.product -data"}" but when I start, nothing happens, even no error. I look forward to your answer.

(Sorry for my bad english, I'm not from USA or England)

Greetings,

R.K.
Re: Race problem in Java App and OSGI bundles start. [message #93204 is a reply to message #91321] Fri, 27 July 2007 19:51 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: alex_blewitt.yahoo.com

I think you can safely ignore these errors.

Alex.
Re: Race problem in Java App and OSGI bundles start. [message #93432 is a reply to message #91321] Tue, 31 July 2007 18:45 Go to previous messageGo to next message
Thomas Watson is currently offline Thomas WatsonFriend
Messages: 503
Registered: July 2009
Senior Member
Can you open a bug against Equinox->Bundles for this. It seems the
EventAdmin bundle is trying to use its BundleContext after it has been
stopped to find handlers to deliver events to. Thanks.

Tom
Re: Race problem in Java App and OSGI bundles start. [message #94460 is a reply to message #93189] Tue, 07 August 2007 15:54 Go to previous messageGo to next message
Cathy Sun is currently offline Cathy SunFriend
Messages: 7
Registered: July 2009
Junior Member
Hi,

I am using EclipseStarter.startup(new String[] {}, null); Before
startup(), you also need to set a few properties like
"osgi.install.area","osgi.configuration.area", "osgi.instance.area", you
could find the explanation on eclipse SDK help.

HTH

Cathy.
Re: Race problem in Java App and OSGI bundles start. [message #94719 is a reply to message #94460] Fri, 10 August 2007 10:42 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: diemarmeladenesserin.yahoo.de

Hallo Cathy

thank you for your answer.

Greetings,

R.K.
Synchronizing with OSGi SCR Work Queue Thread [message #97603 is a reply to message #94719] Wed, 19 September 2007 09:18 Go to previous message
Missing name Mising name is currently offline Missing name Mising nameFriend
Messages: 18
Registered: July 2009
Junior Member
Hi,

i have an RCP application that has a service component using Declarative Services. The service component of the RCP app references a service, say X. On clicking a particular button, i would like to invoke service X. Currently, on clicking the button, the binding/activation done by the SCR Work Queue is happening in a separate thread. Thus, my application goes on and tries to use the service X before the app service component has finished binding to X.
My question is: Is there any way declaratively to synchronize or wait for the binding to complete before proceeding with using the thread. Code mechanisms like sleep() definitely work, but i was wondering if there is some way of achieving this without writing code. Alternatively, what is the "blessed" or prescribed method of achieving it? i have gone through the discussion at the following thread:

http://www.eclipsezone.com/eclipse/forums/m92165828.html#921 65828

however, i could not gather much on whether this situation can be resolved without explicitly writing some sort of synch code. i would not like to start X at start-up, since there will be many such "Xs" in future, thus impacting memory footprint. Lazy loading is preferred as far as possible.

Any pointers will be greatly appreciated.
TIA,
Kind Regards,
-abhi
Previous Topic:OSGi Plugin Deployment
Next Topic:Synchronizing with OSGi SCR Work Queue Thread
Goto Forum:
  


Current Time: Fri Apr 26 05:34:41 GMT 2024

Powered by FUDForum. Page generated in 0.04279 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top