[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [equinox-dev] ServiceListener ignored after Service Replacement

It may be that bundle B* uses a different service interface class object 
for the service. Bundle A may only have class visibility to the service 
interface class for bundle B's service.

The framework is required to filter service events based upon class 
visibility of the receiver. So your bundle A may not receive the event 
because bundle A does not have class visibility to the service registered 
by B*.

To test this, change bundle A to use an AllServiceListener. If you get the 
ServiceEvent for bundle B* but get a ClassCastException when trying to 
cast the Object to service interface type, then we have confirmed the 

To solve this, both bundle B and B* need to use the same package which 
defines the service interface class. This can be done in several ways. One 
is to put that package in a 3rd bundle, C. Then A, B and B* import that 
package. Another way is for B and B* to contain the package and have B and 
B* both export AND import that package. Then A will import from B. When B 
is uninstalled and B* installed, B* will import the package from the old B 
(without a package refresh, B will remain in the system to satisfy class 
loads from its exported packages - this is a gross simplification, read 
the spec for more details). I recommend the first choice, bundle C.

BJ Hargrave
Senior Technical Staff Member, IBM
OSGi Fellow and CTO of the OSGi Alliance

office: +1 386 848 1781
mobile: +1 386 848 3788

"Thomas Fischer" <fischer@xxxxxxxxxxxxxxxxxxx> 
Sent by: equinox-dev-bounces@xxxxxxxxxxx
2007-04-12 08:37
Please respond to
Equinox development mailing list <equinox-dev@xxxxxxxxxxx>


[equinox-dev] ServiceListener ignored after Service Replacement

maybe this is just a stupid simple question, and I just donât see the 
solution, if thatâs the matter sorry for bothering you.
But here the scenario:
I have 2 bundles A and B, A is using a service exported and registered by 
B.  The Service object used in A is wrapped by a dynamic proxy for 
managing the service object and some synchronization issues. This proxy 
registers a Service listener, using the Context of Bundle A, to react on 
Service changes in B and there is the problem:
If bundle B gets uninstalled everything works fine, the Listener gets 
called on the UNREGISTERING Event, the service object in the proxy is 
freed, but if a new bundle B*, implementing and exporting the service 
exported by former B, is installed, the Listener doesnât get called on the 
REGISTERED Event and so the Proxy cannot do its work and react to the 
again available Service. What do I miss? Is there any special filtering 
done in the equinox implementation?
Thomas Fischer
equinox-dev mailing list