Can I run this outside of an activator? Is it safe to hold an internal reference to BundleContext after component activation?
On Fri, May 21, 2010 at 9:53 AM, Carl Hall <[email protected]> wrote: > That looks perfect. What if the service being looked up ("tracked") isn't > available when this chunk of code runs? > > > On Fri, May 21, 2010 at 9:51 AM, Larry Touve <[email protected]>wrote: > >> Have you tried using a ServiceTracker with a filter? >> >> private <T> T getService(Class<T> type, String key, String value) >> { >> String filterString = "(&(objectclass="+type.getName()+") >> ("+key+"="+value+"))"; >> logger.info("Looking up services: " + filterString); >> Filter filter = bundleContext.createFilter(filterString); >> ServiceTracker tracker = new ServiceTracker(context, filter, null); >> tracker.open(); >> T service = type.cast(tracker.getService()); >> tracker.close(); >> >> return service; >> } >> >> You can filter on any properties that the service is created with. >> >> Larry >> >> > >> > I'm familiar with: >> > >> > @Reference(referenceInterface = MySweetInterface.class, target = >> > "(specialProp=certainThingIWant)") >> > >> > but am wondering if I can do something like that during the activation a >> > component. >> > >> > My scenario is this. I have a component that uses factory >> > configurations >> > (ldap connection pools) and a component that needs one of the components >> > created by the factory configuration (ldap authn). In this second >> > component, since it needs the /right/ ldap pool to use if there are >> > multiple >> > available, I was thinking of passing a property in the configuration >> > that >> > could be used to lookup a service like the "target" bit above. Is this >> > doable or should I approach the problem differently? >> > >> > No virus found in this incoming message. >> > Checked by AVG - www.avg.com >> > Version: 9.0.819 / Virus Database: 271.1.1/2883 - Release Date: 05/20/10 >> > 02:26:00 >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [email protected] >> For additional commands, e-mail: [email protected] >> >> >

