import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
private static final ServiceGroupIdentifier SERVICE_GROUP_IDENTIFIER =
ServiceGroupIdentifier.create("flapping-singleton-service");
- private static final ScheduledExecutorService EXECUTOR = FinalizableScheduledExecutorService.newSingleThread();
-
private final ClusterSingletonServiceProvider singletonServiceProvider;
private final AtomicBoolean active = new AtomicBoolean(true);
@SuppressWarnings("checkstyle:IllegalCatch")
public void instantiateServiceInstance() {
LOG.debug("Instantiating flapping-singleton-service.");
-
- // TODO direct registration/close seem to trigger a bug in singleton state transitions,
- // remove the whole executor shenanigans after it's fixed.
- EXECUTOR.submit(() -> {
- try {
- registration.close();
- registration = null;
- } catch (Exception e) {
- LOG.warn("There was a problem closing flapping singleton service.", e);
- setInactive();
-
- final long count = flapCount.get();
- flapCount.compareAndSet(count, -count);
- }
- });
+ try {
+ registration.close();
+ registration = null;
+ } catch (Exception e) {
+ LOG.warn("There was a problem closing flapping singleton service.", e);
+ setInactive();
+
+ final long count = flapCount.get();
+ flapCount.compareAndSet(count, -count);
+ }
}
@Override
flapCount.incrementAndGet();
if (active.get()) {
- // TODO direct registration/close seem to trigger a bug in singleton state transitions,
- // remove whole executor shenanigans after it's fixed.
- // Needs to be delayed slightly otherwise it's triggered as well.
- EXECUTOR.schedule(() -> {
- LOG.debug("Running re-registration");
- try {
- registration = singletonServiceProvider.registerClusterSingletonService(this);
- } catch (RuntimeException e) {
- LOG.warn("There was a problem re-registering flapping singleton service.", e);
- setInactive();
-
- final long count = flapCount.get();
- flapCount.compareAndSet(count, -count - 1);
- }
-
- }, 200, TimeUnit.MILLISECONDS);
+ LOG.debug("Running re-registration");
+ try {
+ registration = singletonServiceProvider.registerClusterSingletonService(this);
+ } catch (RuntimeException e) {
+ LOG.warn("There was a problem re-registering flapping singleton service.", e);
+ setInactive();
+
+ final long count = flapCount.get();
+ flapCount.compareAndSet(count, -count - 1);
+ }
}
return Futures.immediateFuture(null);