Search in sources :

Example 56 with LogService

use of org.osgi.service.log.LogService in project ecf by eclipse.

the class DiscoveryActivator method start.

public void start(final BundleContext ctxt) {
    context = ctxt;
    SafeRunner.run(new ExtensionRegistryRunnable(ctxt) {

        protected void runWithoutRegistry() throws Exception {
            ctxt.registerService(Namespace.class, new ZooDiscoveryNamespace(), null);
            ctxt.registerService(ContainerTypeDescription.class, new ContainerTypeDescription(ZooDiscoveryContainerInstantiator.NAME, new ZooDiscoveryContainerInstantiator(), "Zookeeper Discovery Container"), null);
            ctxt.registerService(ContainerTypeDescription.class, new ContainerTypeDescription(ZooDiscoveryContainerInstantiator.NAME + ".advertiser", new ZooDiscoveryContainerInstantiator(), "Zookeeper Discovery Advertiser Container"), null);
            ctxt.registerService(ContainerTypeDescription.class, new ContainerTypeDescription(ZooDiscoveryContainerInstantiator.NAME + ".locator", new ZooDiscoveryContainerInstantiator(), "Zookeeper Discovery Locator Container"), null);
        }
    });
    final Properties props = new Properties();
    props.put(IDiscoveryLocator.CONTAINER_NAME, ZooDiscoveryContainerInstantiator.NAME);
    props.put(IDiscoveryAdvertiser.CONTAINER_NAME, ZooDiscoveryContainerInstantiator.NAME);
    // register ourselves using a service factory
    discoveryRegistration = ctxt.registerService(new String[] { IDiscoveryLocator.class.getName(), IDiscoveryAdvertiser.class.getName() }, new ServiceFactory() {

        private volatile ZooDiscoveryContainer zdc;

        public Object getService(Bundle bundle, ServiceRegistration registration) {
            if (zdc == null) {
                zdc = ZooDiscoveryContainer.getSingleton();
                zdc.setDiscoveryProperties(props);
            }
            return zdc;
        }

        public void ungetService(Bundle bundle, ServiceRegistration registration, Object service) {
        }
    }, (Dictionary) props);
    // setup and open log service tracker
    logServiceTracker = new ServiceTracker(ctxt, org.osgi.service.log.LogService.class.getName(), null) {

        public Object addingService(ServiceReference reference) {
            Logger.bindLogService((LogService) context.getService(reference));
            return super.addingService(reference);
        }

        public void removedService(ServiceReference reference, Object service) {
            Logger.unbindLogService((LogService) service);
            super.removedService(reference, service);
        }
    };
    logServiceTracker.open(true);
    // Autostart by consuming our own service
    if (ZooDiscoveryContainer.autoStart()) {
        ctxt.getService(discoveryRegistration.getReference());
    }
}
Also used : Dictionary(java.util.Dictionary) ServiceFactory(org.osgi.framework.ServiceFactory) ServiceTracker(org.osgi.util.tracker.ServiceTracker) ContainerTypeDescription(org.eclipse.ecf.core.ContainerTypeDescription) Bundle(org.osgi.framework.Bundle) ExtensionRegistryRunnable(org.eclipse.ecf.core.util.ExtensionRegistryRunnable) Properties(java.util.Properties) ZooDiscoveryNamespace(org.eclipse.ecf.provider.zookeeper.core.ZooDiscoveryNamespace) ZooDiscoveryContainer(org.eclipse.ecf.provider.zookeeper.core.ZooDiscoveryContainer) ZooDiscoveryNamespace(org.eclipse.ecf.provider.zookeeper.core.ZooDiscoveryNamespace) Namespace(org.eclipse.ecf.core.identity.Namespace) ZooDiscoveryContainerInstantiator(org.eclipse.ecf.provider.zookeeper.core.ZooDiscoveryContainerInstantiator) ServiceReference(org.osgi.framework.ServiceReference) LogService(org.osgi.service.log.LogService) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 57 with LogService

use of org.osgi.service.log.LogService in project ecf by eclipse.

the class XmppPlugin method getLogService.

protected LogService getLogService() {
    if (logServiceTracker == null) {
        logServiceTracker = new ServiceTracker(this.context, LogService.class.getName(), null);
        logServiceTracker.open();
    }
    return (LogService) logServiceTracker.getService();
}
Also used : ServiceTracker(org.osgi.util.tracker.ServiceTracker) LogService(org.osgi.service.log.LogService)

Aggregations

LogService (org.osgi.service.log.LogService)57 ServiceTracker (org.osgi.util.tracker.ServiceTracker)15 File (java.io.File)10 ServiceReference (org.osgi.framework.ServiceReference)10 AbstractDeploymentPackage (org.apache.felix.deploymentadmin.AbstractDeploymentPackage)7 Bundle (org.osgi.framework.Bundle)7 HashMap (java.util.HashMap)6 PrintStream (java.io.PrintStream)5 StringWriter (java.io.StringWriter)5 Builder (aQute.bnd.osgi.Builder)4 Jar (aQute.bnd.osgi.Jar)4 Resource (aQute.bnd.osgi.Resource)4 XmlTester (aQute.bnd.test.XmlTester)4 Attributes (java.util.jar.Attributes)4 BundleInfoImpl (org.apache.felix.deploymentadmin.BundleInfoImpl)4 Before (org.junit.Before)4 BundleContext (org.osgi.framework.BundleContext)4 IOException (java.io.IOException)3 Date (java.util.Date)3 Matchers.anyString (org.mockito.Matchers.anyString)3