• 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

最新文章

  1. 将时区格式的时间转换为易于阅读的标准格式&quot;yyyy-MM-dd&quot;
  2. python打怪之路【第一篇】:99乘法表
  3. window下从硬盘安装linux系统iso镜像文件的方法
  4. Maven跳过test打包
  5. [原创]java WEB学习笔记57:Struts2学习之路---ActionSupport类的说明
  6. 【python cookbook】【数据结构与算法】12.找出序列中出现次数最多的元素
  7. css3 transiton
  8. package.json配置项
  9. 苹果也要开发AR眼镜,正与蔡司联手打造
  10. 四、oracle 用户管理(Profile)
  11. Handshakes
  12. ssh-copy-id 拷贝用户秘钥
  13. [译]《Sphinx权威指南》 - Sphinx入门
  14. Java并发编程(五)-- Java内存模型补充
  15. Spark2.2(三十八):Spark Structured Streaming2.4之前版本使用agg和dropduplication消耗内存比较多的问题(Memory issue with spark structured streaming)调研
  16. UVa 1596 Bug Hunt (STL栈)
  17. Spring Hello World
  18. 并发时-修改Linux系统下的最大文件描述符限制
  19. Tsung运行环境安装(转)
  20. 【Android】15.0 第15章 广播和通知—本章示例主界面

热门文章

  1. error while loading shared libraies :libopencv_core_so.3.4:cannot open shared object
  2. DQL、DML、DDL、DCL的区别
  3. Qt 学习之路 2(64):使用 QJsonDocument 处理 JSON
  4. 【转】Cannot add or update a child row: a foreign key constraint fails 解决办法
  5. abp + angular 项目 图标字体注意事项
  6. let 和 var 的区别笔记
  7. 【数学】【筛素数】Miller-Rabin素性测试 学习笔记
  8. CFD
  9. 计算机插U盘没用了
  10. vue指令与事件修饰符