use of org.apache.karaf.service.interceptor.impl.runtime.hook.InterceptedInstancesHooks in project karaf by apache.
the class InterceptorActivator method start.
@Override
public void start(final BundleContext context) throws InvalidSyntaxException {
final PropertiesManager propertiesManager = new PropertiesManager();
// todo: decouple these three services with a bus? here we use the activator to keep it simple
interceptedServiceRegistry = new InterceptedServiceRegistry(this::onServiceAddition, this::onServiceRemoval, propertiesManager);
interceptorRegistry = new InterceptorRegistry(this::onInterceptorAddition, this::onInterceptorRemoval, propertiesManager);
proxiesManager = new ProxiesManager(interceptorRegistry, interceptedServiceRegistry, new ProxyFactory(), propertiesManager);
// listen for interceptors and intercepted instances to be able to react on (un)registrations
context.addServiceListener(interceptedServiceRegistry, "(" + INTERCEPTORS_PROPERTY + "=true)");
context.addServiceListener(interceptorRegistry, "(" + INTERCEPTOR_PROPERTY + "=true)");
// register existing services/interceptors
ofNullable(context.getAllServiceReferences(null, "(" + INTERCEPTORS_PROPERTY + "=true)")).ifPresent(refs -> Stream.of(refs).forEach(ref -> interceptedServiceRegistry.serviceChanged(new ServiceEvent(ServiceEvent.REGISTERED, ref))));
ofNullable(context.getAllServiceReferences(null, "(" + INTERCEPTOR_PROPERTY + "=true)")).ifPresent(refs -> Stream.of(refs).forEach(ref -> interceptorRegistry.serviceChanged(new ServiceEvent(ServiceEvent.REGISTERED, ref))));
// ensure we filter out the proxied services to only return proxies
hooksRegistration = context.registerService(new String[] { FindHook.class.getName(), EventListenerHook.class.getName() }, new InterceptedInstancesHooks(context.getBundle().getBundleId()), new Hashtable<>());
}
Aggregations