• Equinox DS's METE-INF/MANIFEST.MF
  •  Manifest-Version: 1.0
    Lazy-ManifestFilter: (Service-Component=*)
    Bundle-Localization: plugin
    Bundle-RequiredExecutionEnvironment: OSGi/Minimum-1.2,CDC-1.1/Foundation-1.1,J2SE-1.4
    Bundle-SymbolicName: org.eclipse.equinox.ds;singleton:=true
    Eclipse-SourceReferences: scm:git:git://git.eclipse.org/gitroot/equino
    x/rt.equinox.bundles.git;path="bundles/org.eclipse.equinox.ds";tag=v2
    -
    Bundle-Activator: org.eclipse.equinox.internal.ds.Activator
    Export-Package: org.eclipse.equinox.internal.ds;x-internal:=true,org.e
    clipse.equinox.internal.ds.impl;x-internal:=true,org.eclipse.equinox.
    internal.ds.model;x-internal:=true,org.eclipse.equinox.internal.ds.st
    orage.file;x-internal:=true,org.eclipse.equinox.internal.util.io;x-in
    ternal:=true,org.eclipse.equinox.internal.util.xml;x-internal:=true,o
    rg.eclipse.equinox.internal.util.xml.impl;x-internal:=true,org.eclips
    e.equinox.internal.util.string;x-internal:=true,org.apache.felix.scr;
    version="1.6"
    Bundle-Version: 1.4..v20120522-
    Bundle-Description: This bundle provides support for OSGi Declarative Services
    Bundle-Vendor: %bundleVendor
    Bundle-Name: %bundleName
    Import-Package: org.eclipse.equinox.internal.util.event;version="1.0",
    org.eclipse.equinox.internal.util.hash;version="1.0",org.eclipse.equi
    nox.internal.util.pool;version="1.0",org.eclipse.equinox.internal.uti
    l.ref;version="1.0",org.eclipse.equinox.internal.util.threadpool;vers
    ion="1.0",org.eclipse.equinox.internal.util.timer;version="1.0",org.e
    clipse.osgi.framework.console;version="1.0.0";resolution:=optional,or
    g.eclipse.osgi.framework.log;version="1.0.0",org.eclipse.osgi.service
    .debug;version="1.0",org.eclipse.osgi.service.environment;version="1.
    2.0",org.eclipse.osgi.util,org.osgi.framework;version="1.3",org.osgi.
    service.cm;version="1.2",org.osgi.service.component;version="[1.1,1.3
    )",org.osgi.service.log;version="1.3.",org.osgi.util.tracker;version
    ="1.3",org.apache.felix.scr; version="[1.6,1.7)"
    Bundle-ManifestVersion:
  • org.eclipse.equinox.internal.ds.Activator
  •  /*******************************************************************************
    * Copyright (c) 1997, 2010 by ProSyst Software GmbH
    * http://www.prosyst.com
    * All rights reserved. This program and the accompanying materials
    * are made available under the terms of the Eclipse Public License v1.0
    * which accompanies this distribution, and is available at
    * http://www.eclipse.org/legal/epl-v10.html
    *
    * Contributors:
    * ProSyst Software GmbH - initial API and implementation
    *******************************************************************************/
    package org.eclipse.equinox.internal.ds; import java.io.IOException;
    import java.util.Dictionary;
    import java.util.Hashtable;
    import org.apache.felix.scr.ScrService;
    import org.eclipse.equinox.internal.util.ref.Log;
    import org.eclipse.osgi.framework.log.FrameworkLog;
    import org.eclipse.osgi.framework.log.FrameworkLogEntry;
    import org.eclipse.osgi.service.debug.DebugOptions;
    import org.eclipse.osgi.service.environment.EnvironmentInfo;
    import org.osgi.framework.*;
    import org.osgi.service.cm.*;
    import org.osgi.service.component.ComponentConstants;
    import org.osgi.service.log.LogService;
    import org.osgi.util.tracker.ServiceTracker; /**
    * This is the main starting class for the Service Component Runtime.
    * The SCR is not fully initialized until it detects at least one bundle providing DS components.
    * Thus it has considerably small startup time and does improve a little the runtime performance
    * since it does not listen for service events.
    *
    * @author Valentin Valchev
    * @author Stoyan Boshev
    * @author Pavlin Dobrev
    */ public class Activator implements BundleActivator, SynchronousBundleListener, ServiceListener { public static BundleContext bc = null;
    public static ConfigurationAdmin configAdmin = null;
    public static boolean security = false; private ServiceRegistration configListenerReg;
    private SCRManager scrManager = null;
    public ScrServiceImpl scrService = null;
    private ServiceRegistration scrServiceReg;
    private ServiceRegistration scrCommandProviderReg;
    private static FrameworkLog fwLog;
    private boolean inited = false; public static Log log;
    public static boolean DEBUG;
    public static boolean PERF;
    public static boolean DBSTORE;
    public static boolean INSTANTIATE_ALL;
    public static boolean startup; static long time[] = null; public static void timeLog(String message) {
    time[1] = time[0];
    log.debug(message + String.valueOf((time[0] = System.currentTimeMillis()) - time[1]), null);
    } private void initSCR() {
    synchronized (this) {
    if (inited)
    return;
    inited = true;
    } boolean lazyIniting = false;
    if (startup && time == null) {
    long tmp = System.currentTimeMillis();
    time = new long[] {tmp, 0, tmp};
    lazyIniting = true;
    if (startup)
    timeLog("[BEGIN - lazy SCR init]"); //$NON-NLS-1$
    } WorkThread.IDLE_TIMEOUT = getInteger("equinox.ds.idle_timeout", 1000); //$NON-NLS-1$
    WorkThread.BLOCK_TIMEOUT = getInteger("equinox.ds.block_timeout", 30000); //$NON-NLS-1$ try {
    bc.addServiceListener(this, "(objectClass=" + ConfigurationAdmin.class.getName() + ')'); //$NON-NLS-1$
    } catch (InvalidSyntaxException e) {
    //should never happen
    }
    //get config admin service if available
    ServiceReference caRef = bc.getServiceReference(ConfigurationAdmin.class.getName());
    if (caRef != null) {
    configAdmin = (ConfigurationAdmin) bc.getService(caRef);
    }
    if (startup)
    timeLog("ConfigurationAdmin service getting took "); //$NON-NLS-1$ scrManager = new SCRManager();
    if (startup)
    timeLog("SCRManager instantiation took "); //$NON-NLS-1$ // add the configuration listener - we to receive CM events to restart
    // components
    configListenerReg = bc.registerService(ConfigurationListener.class.getName(), scrManager, null);
    if (startup)
    timeLog("ConfigurationListener service registered for "); //$NON-NLS-1$
    bc.addServiceListener(scrManager); scrManager.startIt();
    if (Activator.startup)
    Activator.timeLog("startIt() method took "); //$NON-NLS-1$ installCommandProvider(); if (startup && lazyIniting) {
    log.debug("[END - lazy SCR init] Activator.initSCR() method executed for " + String.valueOf(time[0] - time[2]), null); //$NON-NLS-1$
    time = null;
    }
    } /*
    * (non-Javadoc)
    *
    * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
    */
    public void start(BundleContext bundleContext) throws Exception {
    Activator.bc = bundleContext;
    startup = getBoolean("equinox.measurements.bundles", false); //$NON-NLS-1$
    if (startup) {
    long tmp = System.currentTimeMillis();
    time = new long[] {tmp, 0, tmp};
    }
    // initialize the logging routines
    log = new Log(bundleContext, false);
    ServiceTracker debugTracker = new ServiceTracker(bundleContext, DebugOptions.class.getName(), null);
    debugTracker.open();
    DebugOptions debugOptions = (DebugOptions) debugTracker.getService();
    DEBUG = getBooleanDebugOption(debugOptions, "org.eclipse.equinox.ds/debug", false) || getBoolean("equinox.ds.debug", false); //$NON-NLS-1$ //$NON-NLS-2$
    PERF = getBooleanDebugOption(debugOptions, "org.eclipse.equinox.ds/performance", false) || getBoolean("equinox.ds.perf", false); //$NON-NLS-1$ //$NON-NLS-2$
    INSTANTIATE_ALL = getBooleanDebugOption(debugOptions, "org.eclipse.equinox.ds/instantiate_all", false) || getBoolean("equinox.ds.instantiate_all", false); //$NON-NLS-1$ //$NON-NLS-2$ DBSTORE = getBooleanDebugOption(debugOptions, "org.eclipse.equinox.ds/cache_descriptions", true) || getBoolean("equinox.ds.dbstore", true); //$NON-NLS-1$ //$NON-NLS-2$
    boolean print = getBooleanDebugOption(debugOptions, "org.eclipse.equinox.ds/print_on_console", false) || getBoolean("equinox.ds.print", false); //$NON-NLS-1$ //$NON-NLS-2$
    log.setDebug(DEBUG);
    log.setPrintOnConsole(print);
    //DebugOptions no longer needed
    debugTracker.close();
    ServiceReference fwRef = bc.getServiceReference(FrameworkLog.class.getName());
    if (fwRef != null) {
    fwLog = (FrameworkLog) bc.getService(fwRef);
    } if (startup)
    timeLog("[BEGIN - start method] Creating Log instance and initializing log system took "); //$NON-NLS-1$ security = Log.security();
    boolean hasHeaders = false;
    Bundle[] allBundles = bundleContext.getBundles();
    for (int i = 0; i < allBundles.length; i++) {
    Dictionary allHeaders = allBundles[i].getHeaders(""); //$NON-NLS-1$
    if (allHeaders.get(ComponentConstants.SERVICE_COMPONENT) != null) {
    hasHeaders = true;
    break;
    }
    } if (hasHeaders) {
    initSCR();
    } else {
    // there are no bundles holding components - SCR will not be
    // initialized yet
    bundleContext.addBundleListener(this);
    }
    ServiceReference envInfoRef = bc.getServiceReference(EnvironmentInfo.class.getName());
    EnvironmentInfo envInfo = null;
    if (envInfoRef != null) {
    envInfo = (EnvironmentInfo) bc.getService(envInfoRef);
    }
    if (envInfo != null) {
    envInfo.setProperty("equinox.use.ds", "true"); //$NON-NLS-1$//$NON-NLS-2$
    bc.ungetService(envInfoRef);
    } else {
    System.setProperty("equinox.use.ds", "true"); //$NON-NLS-1$ //$NON-NLS-2$
    } scrService = new ScrServiceImpl();
    scrServiceReg = bc.registerService(ScrService.class.getName(), scrService, null); if (startup) {
    log.debug("[END - start method] Activator.start() method executed for " + String.valueOf(time[0] - time[2]), null); //$NON-NLS-1$
    time = null;
    }
    } /*
    * (non-Javadoc)
    *
    * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
    */
    public void stop(BundleContext bundleContext) throws Exception {
    if (scrManager != null) {
    scrManager.stopIt();
    bundleContext.removeServiceListener(scrManager);
    }
    // dispose the CM Listener
    if (configListenerReg != null) {
    configListenerReg.unregister();
    }
    if (scrService != null) {
    scrService.dispose();
    scrServiceReg.unregister();
    } if (scrCommandProviderReg != null)
    scrCommandProviderReg.unregister(); if (scrManager != null) {
    bundleContext.removeBundleListener(scrManager);
    } else {
    bundleContext.removeBundleListener(this);
    }
    ServiceReference envInfoRef = bc.getServiceReference(EnvironmentInfo.class.getName());
    EnvironmentInfo envInfo = null;
    if (envInfoRef != null) {
    envInfo = (EnvironmentInfo) bc.getService(envInfoRef);
    }
    if (envInfo != null) {
    envInfo.setProperty("equinox.use.ds", "false"); //$NON-NLS-1$//$NON-NLS-2$
    bc.ungetService(envInfoRef);
    } else {
    System.setProperty("equinox.use.ds", "false"); //$NON-NLS-1$ //$NON-NLS-2$
    } log.close();
    log = null;
    } public static Filter createFilter(String filter) throws InvalidSyntaxException {
    return bc.createFilter(filter);
    } public void bundleChanged(BundleEvent event) {
    if (event.getType() == BundleEvent.STARTED || event.getType() == BundleEvent.LAZY_ACTIVATION) {
    Dictionary allHeaders = event.getBundle().getHeaders(""); //$NON-NLS-1$
    if ((allHeaders.get(ComponentConstants.SERVICE_COMPONENT)) != null) {
    // The bundle is holding components - activate scr
    bc.removeBundleListener(this);
    initSCR();
    }
    }
    } public static Configuration getConfiguration(String pid) throws IOException {
    if (configAdmin != null) {
    return configAdmin.getConfiguration(pid);
    }
    return null;
    } public static Configuration[] listConfigurations(String filter) throws IOException, InvalidSyntaxException {
    if (configAdmin != null) {
    return configAdmin.listConfigurations(filter);
    }
    return null;
    } public static boolean getBoolean(String property, boolean defaultValue) {
    String prop = (bc != null) ? bc.getProperty(property) : System.getProperty(property);
    if (prop != null) {
    return prop.equalsIgnoreCase("true"); //$NON-NLS-1$
    }
    return defaultValue;
    } public static boolean getBoolean(String property) {
    return getBoolean(property, false);
    } public static int getInteger(String property, int defaultValue) {
    String prop = (bc != null) ? bc.getProperty(property) : System.getProperty(property);
    if (prop != null) {
    try {
    return Integer.decode(prop).intValue();
    } catch (NumberFormatException e) {
    //do nothing
    }
    }
    return defaultValue;
    } public boolean getBooleanDebugOption(DebugOptions optionsService, String option, boolean defaultValue) {
    if (optionsService != null) {
    String value = optionsService.getOption(option);
    if (value != null)
    return value.equalsIgnoreCase("true"); //$NON-NLS-1$
    }
    return defaultValue;
    } private void installCommandProvider() {
    try {
    SCRCommandProvider scrCommandProvider = new SCRCommandProvider(scrManager);
    Hashtable reg_props = new Hashtable(1, 1);
    reg_props.put(org.osgi.framework.Constants.SERVICE_RANKING, new Integer(Integer.MAX_VALUE));
    scrCommandProviderReg = bc.registerService(org.eclipse.osgi.framework.console.CommandProvider.class.getName(), scrCommandProvider, reg_props);
    } catch (NoClassDefFoundError e) {
    //the org.eclipse.osgi.framework.console package is optional
    if (Activator.DEBUG) {
    log.debug("Cannot register SCR CommandProvider!", e); //$NON-NLS-1$
    }
    }
    } public static void log(BundleContext bundleContext, int level, String message, Throwable t) {
    LogService logService = null;
    ServiceReference logRef = null;
    if (bundleContext != null) {
    try {
    logRef = bundleContext.getServiceReference(LogService.class.getName());
    if (logRef != null) {
    logService = (LogService) bundleContext.getService(logRef);
    }
    } catch (Exception e) {
    if (Activator.DEBUG) {
    log.debug("Cannot get LogService for bundle " + bundleContext.getBundle().getSymbolicName(), e); //$NON-NLS-1$
    }
    }
    }
    if (logService != null) {
    logService.log(level, message, t);
    bundleContext.ungetService(logRef);
    if (log.getPrintOnConsole()) {
    String prefix = ""; //$NON-NLS-1$
    switch (level) {
    case LogService.LOG_ERROR :
    prefix = "ERROR "; //$NON-NLS-1$
    break;
    case LogService.LOG_WARNING :
    prefix = "WARNING "; //$NON-NLS-1$
    break;
    case LogService.LOG_INFO :
    prefix = "INFO "; //$NON-NLS-1$
    break;
    }
    dumpOnConsole(prefix, bundleContext, message, t, level == LogService.LOG_ERROR);
    }
    } else {
    logRef = bc.getServiceReference(LogService.class.getName());
    if (logRef == null) {
    //log service is not available
    if (!log.getPrintOnConsole() && !log.autoPrintOnConsole && fwLog == null) {
    //The log will not print the message on the console and the FrameworkLog service is not available
    //Will print errors on the console as last resort
    if (level == LogService.LOG_ERROR) {
    dumpOnConsole("ERROR ", bundleContext, message, t, true); //$NON-NLS-1$
    }
    }
    } //using the SCR log
    switch (level) {
    case LogService.LOG_ERROR :
    log.error(message, t);
    break;
    case LogService.LOG_WARNING :
    log.warning(message, t);
    break;
    case LogService.LOG_INFO :
    log.info(message);
    break;
    default :
    log.debug(message, t);
    break;
    }
    }
    if (fwLog != null) {
    logToFWLog(bundleContext != null ? bundleContext.getBundle().getSymbolicName() : bc.getBundle().getSymbolicName(), level, message, t);
    }
    } private static void dumpOnConsole(String prefix, BundleContext bundleContext, String msg, Throwable t, boolean printInErr) {
    String message = prefix + bundleContext.getBundle().getBundleId() + " " + msg; //$NON-NLS-1$
    if (printInErr) {
    System.err.println(message);
    } else {
    System.out.println(message);
    }
    if (t != null) {
    t.printStackTrace();
    }
    } private static void logToFWLog(String bsn, int level, String message, Throwable t) {
    int severity = FrameworkLogEntry.INFO;
    switch (level) {
    case LogService.LOG_ERROR :
    severity = FrameworkLogEntry.ERROR;
    break;
    case LogService.LOG_WARNING :
    severity = FrameworkLogEntry.WARNING;
    break;
    case LogService.LOG_INFO :
    severity = FrameworkLogEntry.INFO;
    break;
    case LogService.LOG_DEBUG :
    severity = FrameworkLogEntry.INFO;
    break;
    }
    fwLog.log(new FrameworkLogEntry(bsn, severity, 0, message, 0, t, null));
    } public void serviceChanged(ServiceEvent event) {
    switch (event.getType()) {
    case ServiceEvent.REGISTERED :
    Object caService = bc.getService(event.getServiceReference());
    configAdmin = (ConfigurationAdmin) caService;
    if (caService != null) {
    // Config Admin registered
    if (scrManager != null) {
    scrManager.configAdminRegistered((ConfigurationAdmin) caService, event.getServiceReference());
    }
    }
    break;
    case ServiceEvent.UNREGISTERING :
    //get replacement config admin service if available
    ServiceReference caRef = bc.getServiceReference(ConfigurationAdmin.class.getName());
    if (caRef != null) {
    configAdmin = (ConfigurationAdmin) bc.getService(caRef);
    } else {
    configAdmin = null;
    }
    break;
    }
    }
    }

    Activator

  • One example of Service-Component
    • MAINFEST.INF
    •  Manifest-Version: 1.0
      Bundle-ManifestVersion: 2
      Bundle-Name: Toast Back End Emergency
      Bundle-SymbolicName: org.eclipse.examples.toast.backend.emergency
      Bundle-Version: 1.0.0
      Bundle-RequiredExecutionEnvironment: J2SE-1.4
      Service-Component: OSGI-INF/component.xml,OSGI-INF/emergencyCenter.xml
      Import-Package: javax.servlet;version="2.4.0",
      javax.servlet.http;version="2.4.0",
      org.eclipse.examples.toast.backend.controlcenter,
      org.eclipse.examples.toast.backend.data,
      org.eclipse.examples.toast.backend.data.internal,
      org.eclipse.examples.toast.core;version="[1.0.0,2.0.0)",
      org.eclipse.examples.toast.core.emergency;version="[1.0.0,2.0.0)",
      org.osgi.service.http;version="[1.2.0,2.0.0)"
      Export-Package: org.eclipse.examples.toast.internal.backend.emergency;version="1.0.0";x-internal:=true,
    • Service-Component: OSGI-INF/component.xml,OSGI-INF/emergencyCenter.xml
 <?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="startup" deactivate="shutdown" name="org.eclipse.examples.toast.backend.emergency">
<implementation class="org.eclipse.examples.toast.internal.backend.emergency.bundle.Component"/>
<reference bind="setHttp" interface="org.osgi.service.http.HttpService" name="http"/>
<reference bind="setEmergencyCenter" interface="org.eclipse.examples.toast.core.emergency.IEmergencyCenter" name="emergencyCenter"/>
</scr:component> <?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="startup" deactivate="shutdown" name="org.eclipse.examples.toast.backend.emergency.center">
<implementation class="org.eclipse.examples.toast.internal.backend.emergency.EmergencyCenter"/>
<service>
<provide interface="org.eclipse.examples.toast.core.emergency.IEmergencyCenter"/>
</service>
<reference bind="setData" cardinality="1..1" interface="org.eclipse.examples.toast.backend.controlcenter.IData" name="IData" policy="static"/>
</scr:component>
  • start method  implemented by Activator
  •  public void start(BundleContext bundleContext) throws Exception {
    Activator.bc = bundleContext;
    startup = getBoolean("equinox.measurements.bundles", false); //$NON-NLS-1$
    if (startup) {
    long tmp = System.currentTimeMillis();
    time = new long[] {tmp, 0, tmp};
    }
    // initialize the logging routines
    log = new Log(bundleContext, false);
    ServiceTracker debugTracker = new ServiceTracker(bundleContext, DebugOptions.class.getName(), null);
    debugTracker.open();
    DebugOptions debugOptions = (DebugOptions) debugTracker.getService();
    DEBUG = getBooleanDebugOption(debugOptions, "org.eclipse.equinox.ds/debug", false) || getBoolean("equinox.ds.debug", false); //$NON-NLS-1$ //$NON-NLS-2$
    PERF = getBooleanDebugOption(debugOptions, "org.eclipse.equinox.ds/performance", false) || getBoolean("equinox.ds.perf", false); //$NON-NLS-1$ //$NON-NLS-2$
    INSTANTIATE_ALL = getBooleanDebugOption(debugOptions, "org.eclipse.equinox.ds/instantiate_all", false) || getBoolean("equinox.ds.instantiate_all", false); //$NON-NLS-1$ //$NON-NLS-2$ DBSTORE = getBooleanDebugOption(debugOptions, "org.eclipse.equinox.ds/cache_descriptions", true) || getBoolean("equinox.ds.dbstore", true); //$NON-NLS-1$ //$NON-NLS-2$
    boolean print = getBooleanDebugOption(debugOptions, "org.eclipse.equinox.ds/print_on_console", false) || getBoolean("equinox.ds.print", false); //$NON-NLS-1$ //$NON-NLS-2$
    log.setDebug(DEBUG);
    log.setPrintOnConsole(print);
    //DebugOptions no longer needed
    debugTracker.close();
    ServiceReference fwRef = bc.getServiceReference(FrameworkLog.class.getName());
    if (fwRef != null) {
    fwLog = (FrameworkLog) bc.getService(fwRef);
    } if (startup)
    timeLog("[BEGIN - start method] Creating Log instance and initializing log system took "); //$NON-NLS-1$ security = Log.security();
    boolean hasHeaders = false;
    Bundle[] allBundles = bundleContext.getBundles();
    for (int i = 0; i < allBundles.length; i++) {
    Dictionary allHeaders = allBundles[i].getHeaders(""); //$NON-NLS-1$
    if (allHeaders.get(ComponentConstants.SERVICE_COMPONENT) != null) {
    hasHeaders = true;
    break;
    }
    } if (hasHeaders) {
    initSCR();
    } else {
    // there are no bundles holding components - SCR will not be
    // initialized yet
    bundleContext.addBundleListener(this);
    }
    ServiceReference envInfoRef = bc.getServiceReference(EnvironmentInfo.class.getName());
    EnvironmentInfo envInfo = null;
    if (envInfoRef != null) {
    envInfo = (EnvironmentInfo) bc.getService(envInfoRef);
    }
    if (envInfo != null) {
    envInfo.setProperty("equinox.use.ds", "true"); //$NON-NLS-1$//$NON-NLS-2$
    bc.ungetService(envInfoRef);
    } else {
    System.setProperty("equinox.use.ds", "true"); //$NON-NLS-1$ //$NON-NLS-2$
    } scrService = new ScrServiceImpl();
    scrServiceReg = bc.registerService(ScrService.class.getName(), scrService, null); if (startup) {
    log.debug("[END - start method] Activator.start() method executed for " + String.valueOf(time[0] - time[2]), null); //$NON-NLS-1$
    time = null;
    }
    }
  • initSCR() in Activator
  •      private void initSCR() {
    synchronized (this) {
    if (inited)
    return;
    inited = true;
    } boolean lazyIniting = false;
    if (startup && time == null) {
    long tmp = System.currentTimeMillis();
    time = new long[] {tmp, 0, tmp};
    lazyIniting = true;
    if (startup)
    timeLog("[BEGIN - lazy SCR init]"); //$NON-NLS-1$
    } WorkThread.IDLE_TIMEOUT = getInteger("equinox.ds.idle_timeout", 1000); //$NON-NLS-1$
    WorkThread.BLOCK_TIMEOUT = getInteger("equinox.ds.block_timeout", 30000); //$NON-NLS-1$ try {
    bc.addServiceListener(this, "(objectClass=" + ConfigurationAdmin.class.getName() + ')'); //$NON-NLS-1$
    } catch (InvalidSyntaxException e) {
    //should never happen
    }
    //get config admin service if available
    ServiceReference caRef = bc.getServiceReference(ConfigurationAdmin.class.getName());
    if (caRef != null) {
    configAdmin = (ConfigurationAdmin) bc.getService(caRef);
    }
    if (startup)
    timeLog("ConfigurationAdmin service getting took "); //$NON-NLS-1$ scrManager = new SCRManager();
    if (startup)
    timeLog("SCRManager instantiation took "); //$NON-NLS-1$ // add the configuration listener - we to receive CM events to restart
    // components
    configListenerReg = bc.registerService(ConfigurationListener.class.getName(), scrManager, null);
    if (startup)
    timeLog("ConfigurationListener service registered for "); //$NON-NLS-1$
    bc.addServiceListener(scrManager); scrManager.startIt();
    if (Activator.startup)
    Activator.timeLog("startIt() method took "); //$NON-NLS-1$ installCommandProvider(); if (startup && lazyIniting) {
    log.debug("[END - lazy SCR init] Activator.initSCR() method executed for " + String.valueOf(time[0] - time[2]), null); //$NON-NLS-1$
    time = null;
    }
    }
     public void startIt() {
    // loop through the currently installed bundles
    Bundle[] bundles = Activator.bc.getBundles();
    if (bundles != null) {
    for (int i = 0; i < bundles.length; i++) {
    Bundle current = bundles[i];
    // try to process the active ones.
    if (current.getState() == Bundle.ACTIVE) {
    startedBundle(current);
    } else if (current.getState() == Bundle.STARTING) {
    String lazy = (String) current.getHeaders("").get(Constants.BUNDLE_ACTIVATIONPOLICY); //$NON-NLS-1$
    if (lazy != null && lazy.indexOf(Constants.ACTIVATION_LAZY) >= 0) {
    startedBundle(current);
    }
    }
    }
    }
    }
     void startedBundle(Bundle bundle) {
    synchronized (processingBundles) {
    if (processingBundles.get(bundle) != null) {
    //the bundle is already being processed
    return;
    }
    processingBundles.put(bundle, ""); //$NON-NLS-1$
    }
    try {
    startedBundle2(bundle);
    } finally {
    processingBundles.remove(bundle);
    }
    }
         void startedBundle2(Bundle bundle) {
    long start = 0l;
    if (Activator.PERF) {
    start = System.currentTimeMillis();
    }
    if (bundleToServiceComponents != null && bundleToServiceComponents.get(bundle) != null) {
    // the bundle is already processed - skipping it
    return;
    } String dsHeader = null;
    Dictionary allHeaders = bundle.getHeaders(""); //$NON-NLS-1$ if (!((dsHeader = (String) allHeaders.get(ComponentConstants.SERVICE_COMPONENT)) != null)) {
    // no component descriptions in this bundle
    return;
    } Vector components = storage.loadComponentDefinitions(bundle, dsHeader);
    if (components != null && !components.isEmpty()) {
    if (!hasRegisteredServiceListener) {
    hasRegisteredServiceListener = true;
    Activator.bc.addServiceListener(this);
    resolver.synchronizeServiceReferences();
    }
    if (Activator.PERF) {
    start = System.currentTimeMillis() - start;
    Activator.log.info("[DS perf] The components of bundle " + bundle + " are parsed for " + start + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    }
    if (bundleToServiceComponents == null) {
    synchronized (this) {
    if (bundleToServiceComponents == null) {
    bundleToServiceComponents = new Hashtable(11);
    }
    }
    } //check whether component's names are unique
    ServiceComponent comp;
    ServiceComponent comp2;
    L1: for (int i = 0; i < components.size(); i++) {
    comp = (ServiceComponent) components.elementAt(i);
    //check if unique in its bundle
    for (int j = i + 1; j < components.size(); j++) {
    comp2 = (ServiceComponent) components.elementAt(j);
    if (comp.name.equals(comp2.name)) {
    Activator.log(comp.bc, LogService.LOG_ERROR, NLS.bind(Messages.FOUND_COMPONENTS_WITH_DUPLICATED_NAMES, comp), null);
    //removing one of the components
    components.remove(i);
    i--;
    continue L1;
    }
    }
    //check if the component is globally unique
    Enumeration keys = bundleToServiceComponents.keys();
    while (keys.hasMoreElements()) {
    Vector components2 = (Vector) bundleToServiceComponents.get(keys.nextElement());
    for (int j = 0; j < components2.size(); j++) {
    comp2 = (ServiceComponent) components2.elementAt(j);
    if (comp.name.equals(comp2.name)) {
    Activator.log(comp.bc, LogService.LOG_WARNING, NLS.bind(Messages.FOUND_COMPONENTS_WITH_DUPLICATED_NAMES2, comp, comp2), null);
    }
    }
    } if (comp.autoenable) {
    comp.enabled = true;
    }
    }
    // store the components in the cache
    bundleToServiceComponents.put(bundle, components.clone());
    if (workThread != null && workThread.processingThread == Thread.currentThread()) {
    //we are in the queue thread already. Processing synchronously the job
    resolver.enableComponents(components);
    } else {
    // this will also resolve the component dependencies!
    enqueueWork(this, ENABLE_COMPONENTS, components, false);
    synchronized (components) {
    long startTime = System.currentTimeMillis();
    try {
    while (!components.isEmpty() && (System.currentTimeMillis() - startTime < WorkThread.BLOCK_TIMEOUT)) {
    components.wait(1000);
    }
    if (System.currentTimeMillis() - startTime >= WorkThread.BLOCK_TIMEOUT) {
    Activator.log(null, LogService.LOG_WARNING, NLS.bind(Messages.TIMEOUT_REACHED_ENABLING_COMPONENTS, getBundleName(bundle), Integer.toString(WorkThread.BLOCK_TIMEOUT)), null);
    }
    } catch (InterruptedException e) {
    //do nothing
    }
    }
    }
    }
    }
  • ad

Eclipse Equinox DS(Declarative Service)的更多相关文章

  1. OSGiBundle出现 Could not find bundle: org.eclipse.equinox.console的解决方案

    按照网上教程创建OSGI HelloWorld实例配置run configuration时出现Could not find bundle: org.eclipse.equinox.console 和C ...

  2. Eclipse equinox implementation of OSGi

    Bundle package org.osgi.framework; public interface Bundle extends Comparable<Bundle> { int UN ...

  3. 【Tomcat】解决Eclipse无法添加Tomcat Service问题

    直接上图:今天因为弄Maven的时候,不小心把Tomcat7 Service 给弄没了,没法直接添加. 可以参照上图的结构进行 Download and Install...点击之后等待一会儿. 其实 ...

  4. 使用Eclipse自带Web Service插件(Axis1.4)生成Web Service服务端/客户端

    创建一个名字为math的Java web工程,并将WSDL文件拷入该工程中 将Axis所需的jar包拷贝至WebRoot\WEB-INF\lib目录下,这些jar包会自动导入math工程中 一,生成W ...

  5. Eclipse Configuration

    *** Date: 2013年9月12日星期四中国标准时间上午8时41分50秒 *** Platform Details: *** System properties:applicationXMI=o ...

  6. Equinox P2的学习

    product.configuration 点击“Add按钮”并添加以下插件: org.eclipse.equinox.p2.ui org.eclipse.equinox.p2.ui.sdk org. ...

  7. Equinox P2 介绍(一)Getting Start

    一直觉得 Equinox 的 P2 是个神秘的东西,常常使得 Eclipse 或 Equinox 表现出一些奇怪的行为,于是找来官方文档读一读,试图更好地理解与应用 Equinox . 官方文档很多, ...

  8. eclipse启动报错:An error has occurred.See the log file D:\eclipse\configuration\1552616709202.log

    如题,Eclipse崩了,只能按它留下的线索去看了1552616709202.log: !SESSION -- ::08.739 ----------------------------------- ...

  9. OSGi简介

    OSGi简介 OSGi是什么 下面来看看“维基百科”给出的解释: OSGi(Open Service Gateway Initiative)有双重含义.一方面它指OSGi Alliance组织:另一方 ...

随机推荐

  1. [AHOI2009]中国象棋 BZOJ1801 dp

    题目描述 这次小可可想解决的难题和中国象棋有关,在一个N行M列的棋盘上,让你放若干个炮(可以是0个),使得没有一个炮可以攻击到另一个炮,请问有多少种放置方法.大家肯定很清楚,在中国象棋中炮的行走方式是 ...

  2. 安装GCC-8.3.0及其依赖

    目录 目录 1 1. 前言 1 2. 安装日期 1 3. GCC国内镜像下载地址 2 4. GCC的依赖库 2 4.1. gmp库 2 4.2. mpfr库 2 4.3. mpc库 2 4.4. m4 ...

  3. Xilinx FPGA使用——ROM初始化文件

    在调用ROM的IP Core时,需要对其进行初始化,利用MATLAB生成其初始化数据文件. 工具:ISE 14.7.MATLAB.notepad++ 废话不多说,直接上MATLAB代码,生成了一个10 ...

  4. python基础02—运算符与流程控制

    运算符与流程控制 运算符 赋值运算 用'='表示,'='的左边只能是变量 算术运算 +.-.*:加.减.乘 /:除法运算,运算结果为浮点数 //:除法运算,运算结果为整数(商) %:求余 **:求幂 ...

  5. [洛谷 P4612][COCI 2011-2012#7] Setnja

    传送门 TM :setnja (1S256M) 一个人要散步去会见他的 N 个朋友(按给定的顺序会见).我们可以理解成他们都住在一个 很大的网格内,每个朋友住其中的一个单元格,所有人每一步都可以走到相 ...

  6. QQ链接病毒分析

    QQ链接病毒分析 特征 点击病毒链接后,自动会在每一时刻范围内通过所有途径群发新的病毒链接(途径包括Qzone,群聊等) 分析 首先看一下病毒链接的一个样例 http://news.soso.com/ ...

  7. WebApi接入Swagger

    1.新建webApi项目 2.nuget引入 swagger 3.在项目属性里配置输出 xml文件 4.打开SwaggerConfig.cs编辑 protected static string Get ...

  8. [转] Spring Integration 系统集成

    [From] http://blog.csdn.net/w_x_z_/article/details/53316618 pring Ingegration 提供了基于Spring的EIP(Enterp ...

  9. PIE SDK Geometry的坐标转换

    1. 基于SpatialReference对象的坐标转换 1.1 示例简介 Geometry类是所有几何形体对象的父类,它是一个抽象类,IGeometry接口定义了所有的几何对象都有的方法和属性. 下 ...

  10. java中的线程(2):如何正确停止线程之3种常见停止方式

    1.常见停止方式 自定义线程,其中含退出标志位,在run中判断它. 使用interrupt()方法中断线程 使用stop方法暴力终止(已经弃用) 2.使用标志位 class TestThread ex ...