Search in sources :

Example 1 with ChainsTracker

use of org.apache.stanbol.enhancer.servicesapi.impl.ChainsTracker in project stanbol by apache.

the class ChainsRootResource method activate.

@Activate
public void activate(ComponentContext ctx) {
    final BundleContext bc = ctx.getBundleContext();
    chainTracker = new ChainsTracker(ctx.getBundleContext(), Collections.<String>emptySet(), new ServiceTrackerCustomizer() {

        @Override
        public Object addingService(ServiceReference reference) {
            Object service = bc.getService(reference);
            if (service != null) {
                //rebuild the cache on the next call
                _chainCache = null;
            }
            return service;
        }

        @Override
        public void modifiedService(ServiceReference reference, Object service) {
            //rebuild the cache on the next call
            _chainCache = null;
        }

        @Override
        public void removedService(ServiceReference reference, Object service) {
            if (reference != null) {
                bc.ungetService(reference);
                //rebuild the cache on the next call
                _chainCache = null;
            }
        }
    });
    chainTracker.open();
}
Also used : ChainsTracker(org.apache.stanbol.enhancer.servicesapi.impl.ChainsTracker) ServiceTrackerCustomizer(org.osgi.util.tracker.ServiceTrackerCustomizer) BundleContext(org.osgi.framework.BundleContext) ServiceReference(org.osgi.framework.ServiceReference) Activate(org.apache.felix.scr.annotations.Activate)

Aggregations

Activate (org.apache.felix.scr.annotations.Activate)1 ChainsTracker (org.apache.stanbol.enhancer.servicesapi.impl.ChainsTracker)1 BundleContext (org.osgi.framework.BundleContext)1 ServiceReference (org.osgi.framework.ServiceReference)1 ServiceTrackerCustomizer (org.osgi.util.tracker.ServiceTrackerCustomizer)1