Skip to content

Commit

Permalink
Update to 1.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
scottslewis committed Aug 16, 2024
1 parent 14a87c9 commit 3dbe346
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
3 changes: 2 additions & 1 deletion org.eclipse.ecf.provider.etcd3/bnd.bnd
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
osgi.core,\
org.osgi.service.component.annotations,\
json,\
wrapped.com.google.protobuf.protobuf-java
wrapped.com.google.protobuf.protobuf-java,\
org.apache.felix.framework

javac.source=17
javac.target=17
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,28 @@
******************************************************************************/
package org.eclipse.ecf.provider.etcd3;

import java.util.Hashtable;

import org.eclipse.ecf.core.ContainerConnectException;
import org.eclipse.ecf.core.ContainerCreateException;
import org.eclipse.ecf.core.ContainerTypeDescription;
import org.eclipse.ecf.core.IContainerFactory;
import org.eclipse.ecf.core.identity.IDFactory;
import org.eclipse.ecf.core.identity.Namespace;
import org.eclipse.ecf.discovery.IDiscoveryAdvertiser;
import org.eclipse.ecf.discovery.IDiscoveryLocator;
import org.eclipse.ecf.provider.etcd3.container.Etcd3DiscoveryContainer;
import org.eclipse.ecf.provider.etcd3.container.Etcd3DiscoveryContainerConfig;
import org.eclipse.ecf.provider.etcd3.container.Etcd3DiscoveryContainerInstantiator;
import org.eclipse.ecf.provider.etcd3.identity.Etcd3Namespace;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceFactory;
import org.osgi.framework.ServiceRegistration;
import org.osgi.util.tracker.ServiceTracker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.osgi.framework.Bundle;

public class Activator implements BundleActivator {

Expand All @@ -40,6 +49,7 @@ public static BundleContext getContext() {
return context;
}

private Etcd3DiscoveryContainer container;
private ServiceTracker<IContainerFactory, IContainerFactory> cfTracker;

@SuppressWarnings("unchecked")
Expand All @@ -58,7 +68,45 @@ public void start(BundleContext ctxt) throws Exception {
null);
// Only create/setup if not explicitly disabled
if (!Boolean.parseBoolean(System.getProperty(Etcd3DiscoveryContainerConfig.ETCD_DISABLED_PROP, "false"))) {
context.registerService(new String[] { Etcd3DiscoveryContainerConfig.class.getName()},Etcd3DiscoveryContainerConfig.newBuilder().build(),null);
logger.debug("starting Etcd3 discovery provider");
@SuppressWarnings("rawtypes")
final Hashtable props = new Hashtable();
props.put(IDiscoveryLocator.CONTAINER_NAME, Etcd3DiscoveryContainerInstantiator.NAME);
context.registerService(
new String[] { IDiscoveryAdvertiser.class.getName(), IDiscoveryLocator.class.getName() },
new ServiceFactory<Etcd3DiscoveryContainer>() {
public Etcd3DiscoveryContainer getService(Bundle bundle,
ServiceRegistration<Etcd3DiscoveryContainer> registration) {
if (container == null) {
try {
container = (Etcd3DiscoveryContainer) getContainerFactory()
.createContainer(Etcd3DiscoveryContainerInstantiator.NAME);
logger.debug("Etcd3 discovery container created with name="+ Etcd3DiscoveryContainerInstantiator.NAME);
} catch (ContainerCreateException e) {
logger.error("Could not create Etcd3 discovery="+ Etcd3DiscoveryContainerInstantiator.NAME, e);
container = null;
}
}
// Connect
try {
container.connect(null, null);
logger.debug("Etcd3 discovery container connected with name="+ Etcd3DiscoveryContainerInstantiator.NAME);
} catch (ContainerConnectException e) {
logger.error("Could not connect Etcd3 discovery="+ Etcd3DiscoveryContainerInstantiator.NAME, e);
container = null;
}
return container;
}

public void ungetService(Bundle bundle,
ServiceRegistration<Etcd3DiscoveryContainer> registration,
Etcd3DiscoveryContainer service) {
if (container != null) {
container.disconnect();
container = null;
}
}
}, props);
} else {
logger.debug("Etcd3 discovery provider DISABLED");
}
Expand All @@ -73,4 +121,14 @@ public void stop(BundleContext context) throws Exception {
plugin = null;
}

@SuppressWarnings("unchecked")
IContainerFactory getContainerFactory() {
if (cfTracker == null) {
cfTracker = new ServiceTracker<IContainerFactory, IContainerFactory>(context, IContainerFactory.class,
null);
cfTracker.open();
}
return (IContainerFactory) cfTracker.getService();
}

}

0 comments on commit 3dbe346

Please sign in to comment.