Search in sources :

Example 41 with ServiceTracker

use of org.osgi.util.tracker.ServiceTracker in project chuidiang-ejemplos by chuidiang.

the class Activator method start.

/*
	 * (non-Javadoc)
	 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
	 */
public void start(BundleContext context) throws Exception {
    // This �apa is needed only if you use ds equinox implementation !!!!!
    tracker = new ServiceTracker(context, Adder.class.getName(), null);
    tracker.open();
    log.info("A la escucha");
}
Also used : ServiceTracker(org.osgi.util.tracker.ServiceTracker)

Example 42 with ServiceTracker

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

the class StartupFilterImpl method activate.

@Activate
protected void activate(final BundleContext ctx, final Map<String, Object> properties) throws InterruptedException {
    bundleContext = ctx;
    providersTracker = new ServiceTracker(bundleContext, StartupInfoProvider.class, null);
    providersTracker.open();
    Object prop = properties.get(DEFAULT_MESSAGE_PROP);
    defaultMessage = prop == null ? DEFAULT_MESSAGE : prop.toString();
    prop = properties.get(ACTIVE_BY_DEFAULT_PROP);
    defaultFilterActive = (prop instanceof Boolean ? (Boolean) prop : false);
    prop = bundleContext.getProperty(FRAMEWORK_PROP_MANAGER_ROOT);
    managerRoot = prop == null ? DEFAULT_MANAGER_ROOT : prop.toString();
    if (defaultFilterActive) {
        enable();
    }
    log.info("Activated, enabled={}, managerRoot={}", isEnabled(), managerRoot);
}
Also used : ServiceTracker(org.osgi.util.tracker.ServiceTracker) StartupInfoProvider(org.apache.sling.startupfilter.StartupInfoProvider) Activate(org.apache.felix.scr.annotations.Activate)

Example 43 with ServiceTracker

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

the class MDCStateServlet method start.

public void start(BundleContext context) throws Exception {
    Properties p = new Properties();
    p.setProperty("alias", "/mdc");
    context.registerService(Servlet.class.getName(), this, p);
    configAdminTracker = new ServiceTracker(context, ConfigurationAdmin.class.getName(), null);
    configAdminTracker.open();
}
Also used : ServiceTracker(org.osgi.util.tracker.ServiceTracker) HttpServlet(javax.servlet.http.HttpServlet) Servlet(javax.servlet.Servlet) Properties(java.util.Properties)

Example 44 with ServiceTracker

use of org.osgi.util.tracker.ServiceTracker in project bnd by bndtools.

the class RepoIndexTask method execute.

@Override
public void execute() throws BuildException {
    printCopyright(System.err);
    if (repositoryFile == null)
        throw new BuildException("Output file not specified");
    try {
        // Configure PojoSR
        Map<String, Object> pojoSrConfig = new HashMap<String, Object>();
        pojoSrConfig.put(PojoServiceRegistryFactory.BUNDLE_DESCRIPTORS, new ClasspathScanner());
        // Start PojoSR 'framework'
        Framework framework = new PojoServiceRegistryFactoryImpl().newFramework(pojoSrConfig);
        framework.init();
        framework.start();
        if (knownBundles) {
            registerKnownBundles(framework.getBundleContext());
        }
        // Look for indexer and run index generation
        ServiceTracker<ResourceIndexer, ResourceIndexer> tracker = new ServiceTracker<ResourceIndexer, ResourceIndexer>(framework.getBundleContext(), ResourceIndexer.class, null);
        tracker.open();
        ResourceIndexer index = tracker.waitForService(1000);
        if (index == null)
            throw new IllegalStateException("Timed out waiting for ResourceIndexer service.");
        // Flatten the file sets into a single list
        Set<File> fileList = new LinkedHashSet<File>();
        for (FileSet fileSet : fileSets) {
            DirectoryScanner ds = fileSet.getDirectoryScanner(getProject());
            File basedir = ds.getBasedir();
            String[] files = ds.getIncludedFiles();
            for (int i = 0; i < files.length; i++) fileList.add(new File(basedir, files[i]));
        }
        // Run
        try (OutputStream fos = Files.newOutputStream(repositoryFile.toPath())) {
            index.index(fileList, fos, config);
        }
    } catch (Exception e) {
        throw new BuildException(e);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) FileSet(org.apache.tools.ant.types.FileSet) HashMap(java.util.HashMap) ServiceTracker(org.osgi.util.tracker.ServiceTracker) OutputStream(java.io.OutputStream) ResourceIndexer(org.osgi.service.indexer.ResourceIndexer) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) ClasspathScanner(de.kalpatec.pojosr.framework.launch.ClasspathScanner) PojoServiceRegistryFactoryImpl(de.kalpatec.pojosr.framework.PojoServiceRegistryFactoryImpl) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) Framework(org.osgi.framework.launch.Framework)

Example 45 with ServiceTracker

use of org.osgi.util.tracker.ServiceTracker in project bnd by bndtools.

the class Index method main.

/**
	 * Main entry point. See -help for options.
	 * 
	 * @param args Program arguments
	 */
public static void main(String[] args) {
    try {
        // Configure PojoSR
        Map<String, Object> pojoSrConfig = new HashMap<String, Object>();
        pojoSrConfig.put(PojoServiceRegistryFactory.BUNDLE_DESCRIPTORS, new ClasspathScanner());
        // Start PojoSR 'framework'
        Framework framework = new PojoServiceRegistryFactoryImpl().newFramework(pojoSrConfig);
        framework.init();
        framework.start();
        // Look for indexer and run index generation
        ServiceTracker<ResourceIndexer, ResourceIndexer> tracker = new ServiceTracker<ResourceIndexer, ResourceIndexer>(framework.getBundleContext(), ResourceIndexer.class, null);
        tracker.open();
        ResourceIndexer index = tracker.waitForService(1000);
        if (index == null)
            throw new IllegalStateException("Timed out waiting for ResourceIndexer service.");
        // Process arguments
        Set<File> fileList = new LinkedHashSet<File>();
        Map<String, String> config = new HashMap<String, String>();
        File outputFile = processArgs(args, System.err, config, fileList, framework.getBundleContext());
        if (outputFile == null) {
            System.exit(1);
        }
        boolean verbose = Boolean.parseBoolean(config.get(ResourceIndexer.VERBOSE));
        if (verbose) {
            printCopyright(System.err);
        }
        try (@SuppressWarnings("null") OutputStream fos = Files.newOutputStream(outputFile.toPath())) {
            index.index(fileList, fos, config);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } catch (Exception e) {
        e.printStackTrace();
        System.err.println(e.getMessage());
        System.exit(1);
    }
    // We really need to ensure all non-daemon threads -- which may have
    // been started by a bundle -- are terminated.
    System.exit(0);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) ServiceTracker(org.osgi.util.tracker.ServiceTracker) OutputStream(java.io.OutputStream) ResourceIndexer(org.osgi.service.indexer.ResourceIndexer) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) CmdLineException(org.kohsuke.args4j.CmdLineException) ClasspathScanner(de.kalpatec.pojosr.framework.launch.ClasspathScanner) PojoServiceRegistryFactoryImpl(de.kalpatec.pojosr.framework.PojoServiceRegistryFactoryImpl) File(java.io.File) Framework(org.osgi.framework.launch.Framework)

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