use of org.eclipse.ecf.provider.zookeeper.core.ZooDiscoveryNamespace 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());
}
}
Aggregations