Reputation: 6043
In several books they say that it is a good practice to unget all getted services, but in every example I see of the servicetracker implementation has this method defined like this:
@Override
public Object addingService(ServiceReference reference) {
IQuoteService service = (IQuoteService) context.getService(reference);
/* some stuff */
return service;
}
And they return the service instance... How do I know/guarantee that the instance returned by this method will ever be ungetted?
Upvotes: 0
Views: 63
Reputation: 6046
See the source and javadoc of ServiceTracker and ServiceTrackerCustomizer. The default implementation calls unget in the removedService(...) function:
You should implement that funciton in the same way in your ServiceTrackerCustomizer (or an inherited ServiceTracker).
However, ServiceTracker is low-level API. You need it only if your use-case cannot be solved with Felix SCR or any of its alternatives.
Upvotes: 3