[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[ecf-dev] Mapping ServiceReferences to FrameworkUUIDs (probable race condition in RSA?)

Hello ECF Team,

I'm working on a software that has to know where exactly services are and what osgi framework exported them. As it's not possible to find out what framework a ServiceReference points to, the IProxyDistributionListener and the IHostDiscoveryListener were used in the past to map ServiceReferences to URLs and the URLs to a framework.
That's no longer possible in ECF 3.5, because the listeners were removed for being obsolete. I understand, that the RSA is the new way to go.

The first thing I tried was using the new EndPointListener. It failed, because there's no way to get the corresponding ServiceReference as long as the service was not imported.
So my new approach is the following using an EventHook:

@Override
public void event(final ServiceEvent pEvent, final Collection pContexts) {

    // If a service was registered
    if (pEvent.getType() == ServiceEvent.REGISTERED) {
        final ServiceReference reference = pEvent.getServiceReference();

        // If the service was imported into the framework
        if (reference.getProperty("service.imported") != null) {

            final RemoteServiceAdmin rsa = getRemoteServiceAdmin();
            for (final ImportReference importReference : rsa.getImportedEndpoints()) {
                    if (importReference.getImportedService().equals(reference)) {

                        resolved(reference, importReference.getImportedEndpoint().getFrameworkUUID());
                    }
                }
            }
        }
    }
}

The idea is to wait for the service to be actually imported into the framework, then ask the RSA for the endpoint so I get both the endpoint and the ServiceReference. It doesn't work, becacuse rsa.getImportedEndpoints() is always empty. I used the debugger to step through the code and it seems that the imported endpoint does get added, but too late to catch it inside the EventHook. This was not what I expected. Shouldn't the RSA reflect the imported services as seen by the framework?

If that's how it's supposed to work, do you suggest any other strategies to map a ServiceReference to the framework that exported it?

Thanks in advance,
Patrick Deuster

usoPreviewPopup