Search in sources :

Example 1 with INTERCEPTOR_PROPERTY

use of org.apache.karaf.service.interceptor.impl.runtime.ComponentProperties.INTERCEPTOR_PROPERTY 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<>());
}
Also used : InterceptedInstancesHooks(org.apache.karaf.service.interceptor.impl.runtime.hook.InterceptedInstancesHooks) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) BundleActivator(org.osgi.framework.BundleActivator) Optional.ofNullable(java.util.Optional.ofNullable) InterceptorRegistry(org.apache.karaf.service.interceptor.impl.runtime.registry.InterceptorRegistry) EventListenerHook(org.osgi.framework.hooks.service.EventListenerHook) ServiceEvent(org.osgi.framework.ServiceEvent) ProxiesManager(org.apache.karaf.service.interceptor.impl.runtime.ProxiesManager) InterceptedServiceRegistry(org.apache.karaf.service.interceptor.impl.runtime.registry.InterceptedServiceRegistry) BundleContext(org.osgi.framework.BundleContext) Stream(java.util.stream.Stream) ProxyFactory(org.apache.karaf.service.interceptor.impl.runtime.proxy.ProxyFactory) FindHook(org.osgi.framework.hooks.service.FindHook) PropertiesManager(org.apache.karaf.service.interceptor.impl.runtime.PropertiesManager) INTERCEPTOR_PROPERTY(org.apache.karaf.service.interceptor.impl.runtime.ComponentProperties.INTERCEPTOR_PROPERTY) Hashtable(java.util.Hashtable) ServiceReference(org.osgi.framework.ServiceReference) INTERCEPTORS_PROPERTY(org.apache.karaf.service.interceptor.impl.runtime.ComponentProperties.INTERCEPTORS_PROPERTY) ServiceRegistration(org.osgi.framework.ServiceRegistration) PropertiesManager(org.apache.karaf.service.interceptor.impl.runtime.PropertiesManager) InterceptorRegistry(org.apache.karaf.service.interceptor.impl.runtime.registry.InterceptorRegistry) ProxyFactory(org.apache.karaf.service.interceptor.impl.runtime.proxy.ProxyFactory) ServiceEvent(org.osgi.framework.ServiceEvent) Hashtable(java.util.Hashtable) InterceptedServiceRegistry(org.apache.karaf.service.interceptor.impl.runtime.registry.InterceptedServiceRegistry) ProxiesManager(org.apache.karaf.service.interceptor.impl.runtime.ProxiesManager) InterceptedInstancesHooks(org.apache.karaf.service.interceptor.impl.runtime.hook.InterceptedInstancesHooks)

Aggregations

Hashtable (java.util.Hashtable)1 Optional.ofNullable (java.util.Optional.ofNullable)1 Stream (java.util.stream.Stream)1 INTERCEPTORS_PROPERTY (org.apache.karaf.service.interceptor.impl.runtime.ComponentProperties.INTERCEPTORS_PROPERTY)1 INTERCEPTOR_PROPERTY (org.apache.karaf.service.interceptor.impl.runtime.ComponentProperties.INTERCEPTOR_PROPERTY)1 PropertiesManager (org.apache.karaf.service.interceptor.impl.runtime.PropertiesManager)1 ProxiesManager (org.apache.karaf.service.interceptor.impl.runtime.ProxiesManager)1 InterceptedInstancesHooks (org.apache.karaf.service.interceptor.impl.runtime.hook.InterceptedInstancesHooks)1 ProxyFactory (org.apache.karaf.service.interceptor.impl.runtime.proxy.ProxyFactory)1 InterceptedServiceRegistry (org.apache.karaf.service.interceptor.impl.runtime.registry.InterceptedServiceRegistry)1 InterceptorRegistry (org.apache.karaf.service.interceptor.impl.runtime.registry.InterceptorRegistry)1 BundleActivator (org.osgi.framework.BundleActivator)1 BundleContext (org.osgi.framework.BundleContext)1 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)1 ServiceEvent (org.osgi.framework.ServiceEvent)1 ServiceReference (org.osgi.framework.ServiceReference)1 ServiceRegistration (org.osgi.framework.ServiceRegistration)1 EventListenerHook (org.osgi.framework.hooks.service.EventListenerHook)1 FindHook (org.osgi.framework.hooks.service.FindHook)1