Search in sources :

Example 76 with ServiceTracker

use of org.osgi.util.tracker.ServiceTracker in project sling by apache.

the class SlingAuthenticator method activate.

// ---------- SCR integration
@SuppressWarnings("unused")
@Activate
private void activate(final BundleContext bundleContext, final Map<String, Object> properties) {
    modified(properties);
    AuthenticatorWebConsolePlugin plugin = new AuthenticatorWebConsolePlugin(this);
    Hashtable<String, Object> props = new Hashtable<String, Object>();
    props.put("felix.webconsole.label", plugin.getLabel());
    props.put("felix.webconsole.title", plugin.getTitle());
    props.put("felix.webconsole.category", "Sling");
    props.put(Constants.SERVICE_DESCRIPTION, "Sling Request Authenticator WebConsole Plugin");
    props.put(Constants.SERVICE_VENDOR, properties.get(Constants.SERVICE_VENDOR));
    webConsolePlugin = bundleContext.registerService("javax.servlet.Servlet", plugin, props);
    serviceListener = SlingAuthenticatorServiceListener.createListener(bundleContext, this.authRequiredCache);
    authHandlerTracker = new AuthenticationHandlerTracker(bundleContext, authHandlerCache);
    engineAuthHandlerTracker = new EngineAuthenticationHandlerTracker(bundleContext, authHandlerCache);
    authInfoPostProcessorTracker = new ServiceTracker(bundleContext, AuthenticationInfoPostProcessor.SERVICE_NAME, null);
    authInfoPostProcessorTracker.open();
}
Also used : ServiceTracker(org.osgi.util.tracker.ServiceTracker) Hashtable(java.util.Hashtable) Activate(org.apache.felix.scr.annotations.Activate)

Example 77 with ServiceTracker

use of org.osgi.util.tracker.ServiceTracker in project sling by apache.

the class Activator method start.

/**
     * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
     */
public void start(BundleContext context) {
    this.bundleContext = context;
    this.packageAdminTracker = new ServiceTracker(this.bundleContext, PACKAGE_ADMIN_NAME, null);
    this.packageAdminTracker.open();
    // register service
    this.registerManagerFactory();
    this.bundleContext.addBundleListener(this);
}
Also used : ServiceTracker(org.osgi.util.tracker.ServiceTracker)

Example 78 with ServiceTracker

use of org.osgi.util.tracker.ServiceTracker in project sling by apache.

the class AdapterWebConsolePlugin method activate.

protected void activate(final ComponentContext ctx) throws InvalidSyntaxException {
    this.bundleContext = ctx.getBundleContext();
    this.adapterServiceReferences = new HashMap<>();
    this.adapterBundles = new HashMap<>();
    for (final Bundle bundle : this.bundleContext.getBundles()) {
        if (bundle.getState() == Bundle.ACTIVE) {
            addBundle(bundle);
        }
    }
    this.bundleContext.addBundleListener(this);
    final Filter filter = this.bundleContext.createFilter("(&(adaptables=*)(adapters=*)(" + Constants.OBJECTCLASS + "=" + AdapterFactory.SERVICE_NAME + "))");
    this.adapterTracker = new ServiceTracker(this.bundleContext, filter, this);
    this.adapterTracker.open();
}
Also used : Filter(org.osgi.framework.Filter) ServiceTracker(org.osgi.util.tracker.ServiceTracker) Bundle(org.osgi.framework.Bundle)

Example 79 with ServiceTracker

use of org.osgi.util.tracker.ServiceTracker in project sling by apache.

the class ResourceProviderTracker method activate.

public void activate(final BundleContext bundleContext, final EventAdmin eventAdmin, final ChangeListener listener) {
    this.bundleContext = bundleContext;
    this.eventAdmin = eventAdmin;
    this.listener = listener;
    this.tracker = new ServiceTracker(bundleContext, ResourceProvider.class.getName(), new ServiceTrackerCustomizer() {

        @Override
        public void removedService(final ServiceReference reference, final Object service) {
            final ServiceReference ref = (ServiceReference) service;
            final ResourceProviderInfo info = infos.remove(ref);
            if (info != null) {
                Object pid = ref.getProperty(Constants.SERVICE_PID);
                if (pid != null && !(pid instanceof String)) {
                    pid = null;
                }
                unregister(info, (String) pid);
            }
        }

        @Override
        public void modifiedService(final ServiceReference reference, final Object service) {
            removedService(reference, service);
            addingService(reference);
        }

        @Override
        public Object addingService(final ServiceReference reference) {
            final ResourceProviderInfo info = new ResourceProviderInfo(reference);
            infos.put(reference, info);
            register(info);
            return reference;
        }
    });
    this.tracker.open();
}
Also used : ServiceTracker(org.osgi.util.tracker.ServiceTracker) ServiceTrackerCustomizer(org.osgi.util.tracker.ServiceTrackerCustomizer) ServiceReference(org.osgi.framework.ServiceReference)

Example 80 with ServiceTracker

use of org.osgi.util.tracker.ServiceTracker in project sling by apache.

the class HealthCheckMBeanCreator method activate.

@Activate
protected void activate(final BundleContext btx) {
    this.hcTracker = new ServiceTracker(btx, HealthCheck.class.getName(), null) {

        @Override
        public Object addingService(final ServiceReference reference) {
            return registerHCMBean(btx, reference);
        }

        @Override
        public void modifiedService(final ServiceReference reference, final Object service) {
            unregisterHCMBean(btx, reference);
            registerHCMBean(btx, reference);
        }

        @Override
        public void removedService(final ServiceReference reference, final Object service) {
            unregisterHCMBean(btx, reference);
        }
    };
    this.hcTracker.open();
}
Also used : ServiceTracker(org.osgi.util.tracker.ServiceTracker) ServiceReference(org.osgi.framework.ServiceReference) Activate(org.apache.felix.scr.annotations.Activate)

Aggregations

ServiceTracker (org.osgi.util.tracker.ServiceTracker)96 ServiceReference (org.osgi.framework.ServiceReference)32 Filter (org.osgi.framework.Filter)27 Activate (org.apache.felix.scr.annotations.Activate)18 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)14 Hashtable (java.util.Hashtable)12 BundleContext (org.osgi.framework.BundleContext)11 ConfigurationException (org.osgi.service.cm.ConfigurationException)10 ServiceTrackerCustomizer (org.osgi.util.tracker.ServiceTrackerCustomizer)10 ArrayList (java.util.ArrayList)8 Test (org.junit.Test)8 Bundle (org.osgi.framework.Bundle)7 Dictionary (java.util.Dictionary)6 Converter (net.heartsome.cat.converter.Converter)6 AndFilter (net.heartsome.cat.converter.util.AndFilter)6 EqFilter (net.heartsome.cat.converter.util.EqFilter)6 Configuration (org.osgi.service.cm.Configuration)6 IOException (java.io.IOException)5 HashMap (java.util.HashMap)5 CdiContainer (org.osgi.service.cdi.CdiContainer)4