Search in sources :

Example 31 with ServiceTracker

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

the class ConfigurationAdminUpdateStressTest method startup.

// ----------------------- Initialization -------------------------------------------
@Before
public void startup() {
    bundleContext.registerService(LogService.class.getName(), this, null);
    _tracker = new ServiceTracker(bundleContext, ConfigurationAdmin.class.getName(), null);
    _tracker.open();
}
Also used : ServiceTracker(org.osgi.util.tracker.ServiceTracker) LogService(org.osgi.service.log.LogService) Before(org.junit.Before)

Example 32 with ServiceTracker

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

the class ClassUtils method getPackageAdmin.

public static Object getPackageAdmin() {
    if (m_packageAdmin == null) {
        synchronized (ClassUtils.class) {
            if (m_packageAdmin == null) {
                m_packageAdmin = new ServiceTracker(m_context, PACKAGEADMIN_CLASS, null);
                m_packageAdmin.open();
            }
        }
    }
    return m_packageAdmin.getService();
}
Also used : ServiceTracker(org.osgi.util.tracker.ServiceTracker)

Example 33 with ServiceTracker

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

the class Activator method start.

public void start(BundleContext context) {
    m_context = context;
    // Register impl service implementation.
    String[] classes = { org.apache.felix.shell.ShellService.class.getName(), org.ungoverned.osgi.service.shell.ShellService.class.getName() };
    context.registerService(classes, m_shell = new ShellServiceImpl(), null);
    // Create a service tracker to listen for command services.
    String filter = "(|(objectClass=" + org.apache.felix.shell.Command.class.getName() + ")(objectClass=" + org.ungoverned.osgi.service.shell.Command.class.getName() + "))";
    try {
        m_tracker = new ServiceTracker(context, FrameworkUtil.createFilter(filter), m_tracker);
    } catch (InvalidSyntaxException ex) {
    // This should never happen.
    }
    m_tracker.open();
    // Register "bundlelevel" command service.
    context.registerService(org.apache.felix.shell.Command.class.getName(), new BundleLevelCommandImpl(m_context), null);
    // Register "cd" command service.
    classes = new String[2];
    classes[0] = org.apache.felix.shell.Command.class.getName();
    classes[1] = org.apache.felix.shell.CdCommand.class.getName();
    context.registerService(classes, new CdCommandImpl(m_context), null);
    // Register "find" command service.
    context.registerService(org.apache.felix.shell.Command.class.getName(), new FindCommandImpl(m_context), null);
    // Register "headers" command service.
    context.registerService(org.apache.felix.shell.Command.class.getName(), new HeadersCommandImpl(m_context), null);
    // Register "help" command service.
    context.registerService(org.apache.felix.shell.Command.class.getName(), new HelpCommandImpl(m_context), null);
    // Register "inspect" command service.
    context.registerService(org.apache.felix.shell.Command.class.getName(), new InspectCommandImpl(m_context), null);
    // Register "install" command service.
    context.registerService(org.apache.felix.shell.Command.class.getName(), new InstallCommandImpl(m_context), null);
    // Register "log" command service.
    context.registerService(org.apache.felix.shell.Command.class.getName(), new LogCommandImpl(m_context), null);
    // Register "ps" command service.
    context.registerService(org.apache.felix.shell.Command.class.getName(), new PsCommandImpl(m_context), null);
    // Register "refresh" command service.
    context.registerService(org.apache.felix.shell.Command.class.getName(), new RefreshCommandImpl(m_context), null);
    // Register "resolve" command service.
    context.registerService(org.apache.felix.shell.Command.class.getName(), new ResolveCommandImpl(m_context), null);
    // Register "startlevel" command service.
    context.registerService(org.apache.felix.shell.Command.class.getName(), new StartLevelCommandImpl(m_context), null);
    // Register "shutdown" command service.
    context.registerService(org.apache.felix.shell.Command.class.getName(), new ShutdownCommandImpl(m_context), null);
    // Register "start" command service.
    context.registerService(org.apache.felix.shell.Command.class.getName(), new StartCommandImpl(m_context), null);
    // Register "stop" command service.
    context.registerService(org.apache.felix.shell.Command.class.getName(), new StopCommandImpl(m_context), null);
    // Register "sysprop" command service.
    context.registerService(org.apache.felix.shell.Command.class.getName(), new SystemPropertiesCommandImpl(), null);
    // Register "uninstall" command service.
    context.registerService(org.apache.felix.shell.Command.class.getName(), new UninstallCommandImpl(m_context), null);
    // Register "update" command service.
    context.registerService(org.apache.felix.shell.Command.class.getName(), new UpdateCommandImpl(m_context), null);
    // Register "version" command service.
    context.registerService(org.apache.felix.shell.Command.class.getName(), new VersionCommandImpl(m_context), null);
}
Also used : ServiceTracker(org.osgi.util.tracker.ServiceTracker) Command(org.apache.felix.shell.Command)

Example 34 with ServiceTracker

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

the class BaseIntegrationTest method getService.

/**
 * Obtains a service without waiting for it to become available.
 * @param serviceName
 * @return
 * @throws Exception
 */
protected <T> T getService(String serviceName) throws Exception {
    ServiceTracker tracker = new ServiceTracker(m_context, serviceName, null);
    tracker.open();
    T result;
    try {
        result = (T) tracker.getService();
    } finally {
        tracker.close();
    }
    return result;
}
Also used : ServiceTracker(org.osgi.util.tracker.ServiceTracker)

Example 35 with ServiceTracker

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

the class Activator method start.

/**
 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
 */
public final void start(BundleContext context) throws Exception {
    this.context = context;
    this.tracker = new ServiceTracker(context, UserAdmin.class.getName(), this);
    this.tracker.open();
}
Also used : ServiceTracker(org.osgi.util.tracker.ServiceTracker)

Aggregations

ServiceTracker (org.osgi.util.tracker.ServiceTracker)321 ServiceReference (org.osgi.framework.ServiceReference)65 Filter (org.osgi.framework.Filter)41 ServiceTrackerCustomizer (org.osgi.util.tracker.ServiceTrackerCustomizer)32 BundleContext (org.osgi.framework.BundleContext)28 Hashtable (java.util.Hashtable)26 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)23 Activate (org.apache.felix.scr.annotations.Activate)20 IContainerManager (org.eclipse.ecf.core.IContainerManager)20 Bundle (org.osgi.framework.Bundle)19 LogService (org.osgi.service.log.LogService)17 Dictionary (java.util.Dictionary)13 ArrayList (java.util.ArrayList)12 HashMap (java.util.HashMap)12 IOException (java.io.IOException)11 Test (org.junit.Test)10 ConfigurationException (org.osgi.service.cm.ConfigurationException)10 Map (java.util.Map)7 List (java.util.List)6 Properties (java.util.Properties)6