Github user CMoH commented on the pull request:

    https://github.com/apache/brooklyn-server/pull/65#issuecomment-197356327
  
    I haven't tested it, but it looks like it would work.
    
    One comment though: when calling `BundleContext.getService()` the reference 
count for the service in question is increased, and without any calls to 
`BundleContext.ungetService()` the only moment it will drop to zero is when the 
client bundle (which is `brooklyn-api` here) is unloaded [1]. I don't think it 
will be a problem for now, but we may hit some problems in the future.
    
    One thought is to cache the services obtained by 
`BundleContext.getService()` inside `FrameworkLookup` so that the count does 
not up for every lookup.  Or maybe these lookups are rare enough for this not 
to matter?
    
    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 
`ungetService`, and leaving clients in blocked calls if the provider service 
gets unregistered while in use (i.e in the grace period). In my case, however, 
all services expose the same interface, which makes the code easy. But I'm 
still throwing the idea on the table - maybe it spawns ideas in others.
    
    [1] 
https://osgi.org/javadoc/r4v43/core/org/osgi/framework/BundleContext.html#getService%28org.osgi.framework.ServiceReference%29
    [2] 
https://github.com/apache/aries/blob/trunk/proxy/proxy-api/src/main/java/org/apache/aries/proxy/ProxyManager.java


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to