-
Notifications
You must be signed in to change notification settings - Fork 55
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
Service loader updates #65
Conversation
Abstract out the lookup into a utility.
…oSpecTransformerService.
(Previous in the sense of prior to the FrameworkLookup change.)
I haven't tested it, but it looks like it would work. One comment though: when calling One thought is to cache the services obtained by I haven't tried this yet, but I'm looking at using Aries proxies [2] for the same reason in another project. However, I'm leaning towards injecting needed services in a registry of proxies that avoids the need to call [1] https://osgi.org/javadoc/r4v43/core/org/osgi/framework/BundleContext.html#getService%28org.osgi.framework.ServiceReference%29 |
Thanks for this good point @CMoH. I think in this case, where we are using the |
Forgot to mention the use of |
My thought was that, while ServiceTracker in general may be preferred to ServiceReference, it is actually not best suited in this use case, where in fact I don't want to track the service (just as one wouldn't track the result of a ServiceLoader.load()). If we were to use ServiceTracker then we would have to take care of the open/close of the tracker, which would mean maintaining that state, which would mean not using these static methods but perhaps making the FrameworkLookup be a service in its own right, which would have to be obtained from OSGI (and maybe tracked itself!). The client code in this use case isn't expecting this sort of behaviour. What do you think? |
Well, my comment on |
* @param <T> The type for the class. | ||
* @return A maybe of the instance found in the framework. | ||
*/ | ||
public static <T> Maybe<T> lookup (Class<T> clazz, ClassLoader loader) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personal preference, could cut this file in half if supporting only the lookupAll
case with users getting the first entry where needed.
Minor comments only, good to merge. If we have chosen to use factories for the services instead of exporting them directly, then the reference counting issue wouldn't be a problem (they would be freed immediately). Could be changed in future when need arises. |
Necessary to avoid NPE at line 135 and 160 if the class being looked up is in a bundle that hasn't started yet. We don't really need to get the bundle context from that class, any suitable one will do, and we know that the bundle we live in has started!
Just came by how jclouds approaches the same problem. Here it is just FYI. |
This PR contains a number of changes that are a contribution to getting Brooklyn running on Karaf.
The Brooklyn code uses a ServiceLoader in a small number of places to look up a variety of classes. In OSGI this doesn't work as not everything is in the same classloader. These changes move the lookups into a utility that will first check OSGI service registry for the lookup, and, if the OSGI environment is unavailable, will fall back to the previous behaviour of using the ServiceLoader, for backward compatibility.