Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 342113 - Accessing imported endpoints of the RSA doesn't return the recently imported ones
Summary: Accessing imported endpoints of the RSA doesn't return the recently imported ...
Status: CLOSED INVALID
Alias: None
Product: ECF
Classification: RT
Component: ecf.remoteservices (show other bugs)
Version: unspecified   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: ecf.core-inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-07 04:19 EDT by Missing name CLA
Modified: 2011-04-07 17:47 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Missing name CLA 2011-04-07 04:19:45 EDT
Build Identifier: 20110218-0911

After the RSA imported a service successfully from an endpoint, the OSGi EventHooks are notified that a new service has been registered.

If the imported endpoints are accessed via getImportedEndpoints() from inside the EventHook, then the recently imported endpoint is not present yet.

The endpoint does get added later, though.

Reproducible: Always

Steps to Reproduce:
1. Have a class implement and register an EventHook
2. Let a remote service be imported into the framework
3. Listen to the ServiceEvent.REGISTERED event type and call getImportedEndpoints() on the RSA.
Comment 1 Markus Kuppe CLA 2011-04-07 04:31:08 EDT
Why are you using an EventHook anyway? An EH is triggered in between the RSA lifecycle and thus you see what you are describing.
Comment 2 Scott Lewis CLA 2011-04-07 10:13:23 EDT
(In reply to comment #1)
> Why are you using an EventHook anyway? An EH is triggered in between the RSA
> lifecycle and thus you see what you are describing.

Just to detail a little bit...the RSA impl registers a proxy *prior* to the notification, so if you are using an EventHook to synchronously detect a proxy registration, code inside that eventhook that accesses the RSA.getImportedEndpoints() will *not* find the registration...because it hasn't yet been created and added to the set of available registrations (the proxy service registration has to happen first).

In the RemoteServiceAdmin.importService impl the ordering is:

a) create and register proxy with local OSGi service registry (inside method importService(EndpointDescription,IRemoteServiceContainer)...line 295

b) add the resulting registration to the known set of import endpoints...making it available to be returned from a subsequent call to RSA.getImportedEndpoints()...line 298

c) publish import event to RemoteServiceAdminListeners (synchronously) and EventAdmin (asynchronously).  Line 302.

So if you want to be notified of successful imports...and then get the import endpoint from the RSA, probably the best way to do so is to register a org.osgi.service.remoteserviceadmin.RemoteServiceAdminListener and be notified synchronously (and call RSA.getImportedEndpoints if you wish), or an EventHandler and be notified asynchronously.  If you end up doing this, and it works out for your use case, I would appreciate helping out with documenting the RemoteServiceAdminListener/EventAdmin RSA notification...with a wiki page...perhaps with code examples...to show how this is done.

If I'm off-base with any of the above, please let all know.  And also please let all know if you are seeing what still seems like a bug in the RSA.getImportedEndpoints.  At this point, through code inspection and testing, the above described ordering of things seems ok to me.
Comment 3 Missing name CLA 2011-04-07 17:32:19 EDT
(In reply to comment #1)
> Why are you using an EventHook anyway? An EH is triggered in between the RSA
> lifecycle and thus you see what you are describing.

I honestly didn't expected it to matter. I thought that if a service was successfully imported by the RSA, then the endpoint should be present.

If that's just not how things work when using an EventHook, then it's fine.

(In reply to comment #2)
> So if you want to be notified of successful imports...and then get the import
> endpoint from the RSA, probably the best way to do so is to register a
> org.osgi.service.remoteserviceadmin.RemoteServiceAdminListener and be notified
> synchronously (and call RSA.getImportedEndpoints if you wish), or an
> EventHandler and be notified asynchronously.  If you end up doing this, and it
> works out for your use case, I would appreciate helping out with documenting
> the RemoteServiceAdminListener/EventAdmin RSA notification...with a wiki
> page...perhaps with code examples...to show how this is done.

That sounds like a solution to my problem that could be implemented without too much hassle. I will contribute a wiki page for sure, if it works out.

> If I'm off-base with any of the above, please let all know.  And also please
> let all know if you are seeing what still seems like a bug in the
> RSA.getImportedEndpoints.  At this point, through code inspection and testing,
> the above described ordering of things seems ok to me.

I'm sure it's not a bug in RSA.getImportedEndpoints, because I stepped through the code a number of times. The endpoint does get added and is returned correctly outside of the EventHook.

I guess the bug report can be closed then?
Comment 4 Scott Lewis CLA 2011-04-07 17:47:21 EDT
(In reply to comment #3)
> (In reply to comment #1)
> > Why are you using an EventHook anyway? An EH is triggered in between the RSA
> > lifecycle and thus you see what you are describing.
> 
> I honestly didn't expected it to matter. I thought that if a service was
> successfully imported by the RSA, then the endpoint should be present.
> 
> If that's just not how things work when using an EventHook, then it's fine.

The way the EventHook is specified is that it gets called *during* the call to bundleContext.registerService.  Part of the importService calls registerService to register the proxy...and the registerService call has to return before the ImportEndpoint can even be created...so if your EventHook is being called during the proxy's registerService call, the ImportEndpoint isn't yet available.


> 
> (In reply to comment #2)
> > So if you want to be notified of successful imports...and then get the import
> > endpoint from the RSA, probably the best way to do so is to register a
> > org.osgi.service.remoteserviceadmin.RemoteServiceAdminListener and be notified
> > synchronously (and call RSA.getImportedEndpoints if you wish), or an
> > EventHandler and be notified asynchronously.  If you end up doing this, and it
> > works out for your use case, I would appreciate helping out with documenting
> > the RemoteServiceAdminListener/EventAdmin RSA notification...with a wiki
> > page...perhaps with code examples...to show how this is done.
> 
> That sounds like a solution to my problem that could be implemented without too
> much hassle. I will contribute a wiki page for sure, if it works out.

That would be very kind of you...thank you in advance.  Please let's coordinate about the documentation/example contribution on the ECF documentation project bug 329124.


> 
> > If I'm off-base with any of the above, please let all know.  And also please
> > let all know if you are seeing what still seems like a bug in the
> > RSA.getImportedEndpoints.  At this point, through code inspection and testing,
> > the above described ordering of things seems ok to me.
> 
> I'm sure it's not a bug in RSA.getImportedEndpoints, because I stepped through
> the code a number of times. The endpoint does get added and is returned
> correctly outside of the EventHook.
> 
> I guess the bug report can be closed then?

Yes, I will close as invalid.