Search in sources :

Example 6 with ExtensionRegistryRunnable

use of org.eclipse.ecf.core.util.ExtensionRegistryRunnable 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)

Aggregations

Namespace (org.eclipse.ecf.core.identity.Namespace)6 ExtensionRegistryRunnable (org.eclipse.ecf.core.util.ExtensionRegistryRunnable)6 ContainerTypeDescription (org.eclipse.ecf.core.ContainerTypeDescription)5 Properties (java.util.Properties)3 ServiceTracker (org.osgi.util.tracker.ServiceTracker)3 Dictionary (java.util.Dictionary)1 ContainerConnectException (org.eclipse.ecf.core.ContainerConnectException)1 TrivialNamespace (org.eclipse.ecf.examples.provider.trivial.identity.TrivialNamespace)1 TrivialContainerInstantiator (org.eclipse.ecf.internal.examples.provider.trivial.container.TrivialContainerInstantiator)1 LocalRemoteServiceContainerInstantiator (org.eclipse.ecf.internal.provider.local.container.LocalRemoteServiceContainerInstantiator)1 ContainerInstantiator (org.eclipse.ecf.provider.jslp.container.ContainerInstantiator)1 JSLPNamespace (org.eclipse.ecf.provider.jslp.identity.JSLPNamespace)1 LocalNamespace (org.eclipse.ecf.provider.local.identity.LocalNamespace)1 ZooDiscoveryContainer (org.eclipse.ecf.provider.zookeeper.core.ZooDiscoveryContainer)1 ZooDiscoveryContainerInstantiator (org.eclipse.ecf.provider.zookeeper.core.ZooDiscoveryContainerInstantiator)1 ZooDiscoveryNamespace (org.eclipse.ecf.provider.zookeeper.core.ZooDiscoveryNamespace)1 Bundle (org.osgi.framework.Bundle)1 ServiceFactory (org.osgi.framework.ServiceFactory)1 ServiceReference (org.osgi.framework.ServiceReference)1 ServiceRegistration (org.osgi.framework.ServiceRegistration)1