Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comments on "Tracking a Service" #11

Open
mnlipp opened this issue Jan 5, 2018 · 2 comments
Open

Comments on "Tracking a Service" #11

mnlipp opened this issue Jan 5, 2018 · 2 comments

Comments

@mnlipp
Copy link
Owner

mnlipp commented Jan 5, 2018

Please append any comments to this issue.

@alexei-tovarisch
Copy link

Could you provide some clarification on this sentence:

...But we cannot use getService() here because the new
// service hasn't been added to the tracked services yet (we're in
// the process of adding). We have to decide on our own.

Why do you say that in the addingService() method the service is not tracked and we cannot use getService().

In this book I find the opposite (chapter 4.8 page 93)

@mnlipp
Copy link
Owner Author

mnlipp commented Jan 31, 2022

You have to read this with the argument list in mind:

... we cannot use ServiceTracker.getService() here ....

Neil Bartlett in his book uses context.getService(ref), a completely different method.

Now you might ask, why shouldn't I simply use the service that I can get from the service reference passed to addingService(ServiceReference ref) as shown in the book? Well, because in general, you can have several instances of the same service at the same time and you don't know if the one being added is the preferred one. ServiceTracker.getService() would return the preferred one, if we could call it. But as we are in an "adding" callback (and not in an "added" callback, which doesn't exist), the service being added is not taken into account by ServiceTracker.getService() yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants