Search in sources :

Example 36 with ServiceTracker

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

the class SimpleWebConsolePlugin method deactivate.

/**
 * This method will close all service trackers, created by
 * {@link #getService(String)} method. If you override this method, don't
 * forget to call the super.
 *
 * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#deactivate()
 */
public void deactivate() {
    for (Iterator ti = services.values().iterator(); ti.hasNext(); ) {
        ServiceTracker tracker = (ServiceTracker) ti.next();
        tracker.close();
        ti.remove();
    }
    super.deactivate();
}
Also used : ServiceTracker(org.osgi.util.tracker.ServiceTracker) Iterator(java.util.Iterator)

Example 37 with ServiceTracker

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

the class BundlesServlet method activate.

/**
 * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#activate(org.osgi.framework.BundleContext)
 */
@Override
public void activate(BundleContext bundleContext) {
    super.activate(bundleContext);
    bundleInfoTracker = new ServiceTracker(bundleContext, BundleInfoProvider.class.getName(), null);
    bundleInfoTracker.open();
    // bootdelegation property parsing from Apache Felix R4SearchPolicyCore
    String bootDelegation = bundleContext.getProperty(Constants.FRAMEWORK_BOOTDELEGATION);
    bootDelegation = (bootDelegation == null) ? "java.*" : bootDelegation + ",java.*";
    StringTokenizer st = new StringTokenizer(bootDelegation, " ,");
    bootPkgs = new String[st.countTokens()];
    bootPkgWildcards = new boolean[bootPkgs.length];
    for (int i = 0; i < bootPkgs.length; i++) {
        bootDelegation = st.nextToken();
        if (bootDelegation.endsWith("*")) {
            bootPkgWildcards[i] = true;
            bootDelegation = bootDelegation.substring(0, bootDelegation.length() - 1);
        }
        bootPkgs[i] = bootDelegation;
    }
    Hashtable props = new Hashtable();
    props.put(WebConsoleConstants.CONFIG_PRINTER_MODES, new String[] { ConfigurationPrinter.MODE_TXT, ConfigurationPrinter.MODE_ZIP });
    configurationPrinter = bundleContext.registerService(ConfigurationPrinter.SERVICE, this, props);
}
Also used : StringTokenizer(java.util.StringTokenizer) ServiceTracker(org.osgi.util.tracker.ServiceTracker) Hashtable(java.util.Hashtable)

Example 38 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, DeploymentAdmin.class.getName(), this);
    this.tracker.open();
}
Also used : ServiceTracker(org.osgi.util.tracker.ServiceTracker)

Example 39 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;
    Filter filter = context.createFilter(// $NON-NLS-1$
    "(|" + '(' + OBJECTCLASS + // $NON-NLS-1$
    "=org.osgi.service.obr.RepositoryAdmin)" + '(' + OBJECTCLASS + // $NON-NLS-1$
    "=org.apache.felix.bundlerepository.RepositoryAdmin)" + ')');
    this.tracker = new ServiceTracker(context, filter, this);
    this.tracker.open();
}
Also used : Filter(org.osgi.framework.Filter) ServiceTracker(org.osgi.util.tracker.ServiceTracker)

Example 40 with ServiceTracker

use of org.osgi.util.tracker.ServiceTracker in project hale by halestudio.

the class Activator method getBooleanDebugOption.

/**
 * Return the debug value of the option if founded otherwise return
 * defaultValue.
 *
 * @param option
 * @param defaultValue
 * @return
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public static boolean getBooleanDebugOption(String option, boolean defaultValue) {
    // 1) search param from JVM
    String s = System.getProperty(DEBUG_PROPERTY);
    if (!Utils.isEmpty(s)) {
        return Utils.isTrue(s, defaultValue);
    }
    // 2) search param from nonosgiregistry.properties files.
    if (nonosgiregistryProps == null) {
        nonosgiregistryProps = Utils.load(Activator.class.getClassLoader());
        s = nonosgiregistryProps.getProperty(DEBUG_PROPERTY);
        if (!Utils.isEmpty(s)) {
            return Utils.isTrue(s, defaultValue);
        }
    }
    // 3) Search param from OSGi options
    Activator activator = getDefault();
    if (activator == null)
        // No OSGi context
        return defaultValue;
    BundleContext myBundleContext = activator.bundleContext;
    if (myBundleContext == null)
        return defaultValue;
    // Search the DebugOptions OSGi service
    if (getDefault().debugTracker == null) {
        getDefault().debugTracker = new ServiceTracker(getDefault().bundleContext, DebugOptions.class.getName(), null);
        getDefault().debugTracker.open();
    }
    DebugOptions options = (DebugOptions) getDefault().debugTracker.getService();
    if (options != null) {
        // get the value of the option by using OSGi service DebugOptions
        return Utils.isTrue(options.getOption(option), defaultValue);
    }
    return defaultValue;
}
Also used : BundleActivator(org.osgi.framework.BundleActivator) ServiceTracker(org.osgi.util.tracker.ServiceTracker) DebugOptions(org.eclipse.osgi.service.debug.DebugOptions) BundleContext(org.osgi.framework.BundleContext)

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