Search in sources :

Example 1 with ZooDiscoveryContainer

use of org.eclipse.ecf.provider.zookeeper.core.ZooDiscoveryContainer 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

Dictionary (java.util.Dictionary)1 Properties (java.util.Properties)1 ContainerTypeDescription (org.eclipse.ecf.core.ContainerTypeDescription)1 Namespace (org.eclipse.ecf.core.identity.Namespace)1 ExtensionRegistryRunnable (org.eclipse.ecf.core.util.ExtensionRegistryRunnable)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 LogService (org.osgi.service.log.LogService)1 ServiceTracker (org.osgi.util.tracker.ServiceTracker)1