Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [ecf-dev] Discovery race condition?

Hi Scott,

On Jun 9, 2009, at 11:56 AM, Scott Lewis wrote:

Hi Bryan,

Bryan Hunt wrote:

On Jun 9, 2009, at 11:07 AM, Scott Lewis wrote:

Hi Bryan,

The listener is registered in the Activator of the org.eclipse.ecf.osgi.services.discovery bundle, which is started when the org.eclipse.ecf.osgi.services.distribution bundle is started.

So the key thing is that the org.eclipse.ecf.osgi.services.distribution bundle must be started in order to get everything going in a lazy start environment (like Eclipse)...or a class in o.e.e.osgi.services.distribution accessed, of course (as this will also start o.e.e.osgi.services.distribution and discovery).

If the osgi distribution (and discovery) bundles are not started, then yes...they will miss discovered services (assuming the ecf discovery *has* been started).  This constraint isn't unique to ECF...as there was nothing in the spec (in my most recent reading of RFC 119) that discusses starting/start order in various environments.


Even if they are started prior to the discovery provider, I assert there is still a race condition.  The listener is added asynchronously to the provider which could have already discovered it's services,

Not sure if I understand what you mean 'listener is added asynchronously to the provider'.  The listener is added in the start method of the org.eclipse.ecf.osgi.discovery bundle.  If this is what you mean by asynchronous, then do you mean asynchronous to the discovery provider being started?

If so, then yes...this starting of the osgi.discovery bundle can happen asynchronous to the starting of the discovery provider.

could be in the process of discovering services, or may not discover any services for several hours.  

Sure.  This is why, in general, it makes sense to start the osgi distribution/discovery code as early as possible.  But we cannot require/guarantee when any of our bundles get started (or even if they get started)...in fact, for distribution with Eclipse we explicitly *can't* start them (since Eclipse uses lazy start).

Isn't this the exact same problem as listening to regular OSGi services and why the ServiceTracker was created?

We do use a service tracker to track the IDiscoveryLocator, it's on line 82 in org.eclipse.ecf.internal.osgi.services.discovery.Activator.  The call to locatorTracker.open() on line 85 will end up calling LocatorTrackerCustomizer.addingService(servicePublicationHandler), which adds a service listener to the discovered IDiscoveryLocator.

I think I recognize what you are trying to say (correct me if I'm wrong):  isn't it possible that an ECF discovery provider (e.g. zeroconf/slp) could discover services all day long, and the osgi discovery would never be triggered...because it was never started, and therefore no listener was registered, therefore no notifications.  Yes, that is certainly true.  But it's not obvious (to me) what we can do about this given the OSGi lazy starting (other than what we have done...which is to start osgi discovery as part of osgi distribution being started)...and no spec-based guidance on start order.


You are on the right track here, but consider the following:

  1. The org.eclipse.ecf.osgi.services.discovery bundle is started
  2. The org.eclipse.ecf.discovery bundle is started
  3. A bundle containing a discovery provider is started
  4. CompositeDiscoveryContainer.addContainer() is called
  5. The discovery provider connect() is called and services are discovered
  6. The org.eclipse.ecf.osgi.serives.discovery service tracker is called and the listener is added

The services discovered in step 5 will not be seen in step 6.  This same problem happens when you do:

bundleContext.addServiceListener() ... you don't get the previously added services.  I think the solution is to call:

IDiscoveryLocator.getServiceTypes() and getServices() after adding the listener.  This should also solve the bundle start order problem as well.

I think the workaround for me is to override AbstractDiscoveryContainerAdapter.addServiceListener() and call the listener for any existing discovered services.



Scott

_______________________________________________
ecf-dev mailing list
ecf-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/ecf-dev


Back to the top