Hi,

I've encountered a problem and don't see what the correct solution is, if
there is any.

Some clients are requesting a service implemented as a ServiceFactory.  The
getService() method returns a proxy, and the ungetService() method disposes
of the resources used by the proxy (connections, files, etc).  The proxy is
therefore associated with the client bundle.  This works fine for clients
that get a reference and an instance in their BundleActivator's start()
method and release it in the stop() method.

However, some clients don't necessarily retain the reference, they get the
instance for a specific operation, then release it immediately (in nice
try...finally blocks).  When they release it, the usage count goes to zero,
and ungetService() is called on the ServiceFactory, which duly performs
cleanup.  This is where the trouble starts, because then the client
requests it again at some later point, and as per the JavaDocs for
ServiceFactory, it's the original cached proxy instance (the one that's
already been cleaned up) that gets returned, without the ServiceFactory's
getService() method being called.

So I can't reactivate it, I can't provide a new proxy, and the client gets
an obsolete instance.

What should I do?  I did try doing stuff like calling unregister() on the
ServiceRegistration passed to ungetService() but that didn't seem to help.

Thanks in advance,
Christopher Brown

Reply via email to