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;
import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
private final ClusterSingletonServiceProvider singletonServiceProvider;
private final AtomicBoolean active = new AtomicBoolean(true);
- private volatile long flapCount = 0;
+ private final AtomicLong flapCount = new AtomicLong();
private volatile ClusterSingletonServiceRegistration registration;
public FlappingSingletonService(final ClusterSingletonServiceProvider singletonServiceProvider) {
} catch (Exception e) {
LOG.warn("There was a problem closing flapping singleton service.", e);
setInactive();
- flapCount = -flapCount;
+
+ final long count = flapCount.get();
+ flapCount.compareAndSet(count, -count);
}
});
}
public ListenableFuture<Void> closeServiceInstance() {
LOG.debug("Closing flapping-singleton-service, flapCount: {}", flapCount);
- flapCount++;
+ 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.
} catch (RuntimeException e) {
LOG.warn("There was a problem re-registering flapping singleton service.", e);
setInactive();
- flapCount = -flapCount - 1;
+
+ final long count = flapCount.get();
+ flapCount.compareAndSet(count, -count - 1);
}
}, 200, TimeUnit.MILLISECONDS);
LOG.debug("Setting flapping-singleton-service to inactive, flap-count: {}", flapCount);
active.set(false);
- return flapCount;
+ return flapCount.get();
}
}