On 3/3/10 21:10, Serge Merzliakov wrote:
Hi,
    I hvae noticed that BundleContext.getService (I have not tried
ServiceTracker yet) always returns same object when used like this:

         ServiceReference ref =
bundleContext.getServiceReference(MyInterface.getClass().getName());
         MyInterface impl1 = (MyInterface)bundleContext().getService(ref);
         MyInterface impl2 = (MyInterface)bundleContext().getService(ref);

         // impl1 == impl2


Is there a way to create new instances of the service every time instead ?
If not, the simplest alternative appears to return a factory object of some
kind, and use that to create instances.

No, that's spec'ed behavior. The best you can do with the core spec is a ServiceFactory which can return a different object per bundle. Otherwise, you can use something like Declarative Service's component factories or iPOJO to get factories like you want...or just define your own factory service interface.

-> richard


Regards,
Serge




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@felix.apache.org
For additional commands, e-mail: users-h...@felix.apache.org

Reply via email to