Using AsyncLeaderElector primitive for Leadership

Change-Id: I0ff91ddaa3b5dec79e073496044c2f860ae94616
diff --git a/core/net/src/main/java/org/onosproject/cluster/impl/LeadershipManager.java b/core/net/src/main/java/org/onosproject/cluster/impl/LeadershipManager.java
index 9ceffee..aa9004c 100644
--- a/core/net/src/main/java/org/onosproject/cluster/impl/LeadershipManager.java
+++ b/core/net/src/main/java/org/onosproject/cluster/impl/LeadershipManager.java
@@ -18,9 +18,6 @@
 import static org.slf4j.LoggerFactory.getLogger;
 
 import java.util.Map;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
 
 import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
@@ -28,9 +25,7 @@
 import org.apache.felix.scr.annotations.Reference;
 import org.apache.felix.scr.annotations.ReferenceCardinality;
 import org.apache.felix.scr.annotations.Service;
-import org.onlab.util.Tools;
 import org.onosproject.cluster.ClusterService;
-import org.onosproject.cluster.ControllerNode;
 import org.onosproject.cluster.Leadership;
 import org.onosproject.cluster.LeadershipAdminService;
 import org.onosproject.cluster.LeadershipEvent;
@@ -65,25 +60,16 @@
 
     private NodeId localNodeId;
 
-    private final ScheduledExecutorService deadlockDetector =
-            Executors.newSingleThreadScheduledExecutor(Tools.groupedThreads("onos/leadership", ""));
-
     @Activate
     public void activate() {
         localNodeId = clusterService.getLocalNode().id();
         store.setDelegate(delegate);
         eventDispatcher.addSink(LeadershipEvent.class, listenerRegistry);
-        deadlockDetector.scheduleWithFixedDelay(() -> clusterService.getNodes()
-                .stream()
-                .map(ControllerNode::id)
-                .filter(id -> !clusterService.getState(id).isActive())
-                .forEach(this::unregister), 0, 2, TimeUnit.SECONDS);
         log.info("Started");
     }
 
     @Deactivate
     public void deactivate() {
-        deadlockDetector.shutdown();
         Maps.filterValues(store.getLeaderships(), v -> v.candidates().contains(localNodeId))
             .keySet()
             .forEach(this::withdraw);
diff --git a/core/store/dist/src/main/java/org/onosproject/store/cluster/impl/DistributedLeadershipStore.java b/core/store/dist/src/main/java/org/onosproject/store/cluster/impl/DistributedLeadershipStore.java
index 78ccc47..fbf6b60 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/cluster/impl/DistributedLeadershipStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/cluster/impl/DistributedLeadershipStore.java
@@ -56,7 +56,7 @@
  * Implementation of {@code LeadershipStore} backed by {@link ConsistentMap}.
  */
 @Service
-@Component(immediate = true, enabled = true)
+@Component(immediate = true, enabled = false)
 public class DistributedLeadershipStore
     extends AbstractStore<LeadershipEvent, LeadershipStoreDelegate>
     implements LeadershipStore {
diff --git a/core/store/dist/src/main/java/org/onosproject/store/cluster/impl/NewDistributedLeadershipStore.java b/core/store/dist/src/main/java/org/onosproject/store/cluster/impl/NewDistributedLeadershipStore.java
index 01f61c7..f4b4302 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/cluster/impl/NewDistributedLeadershipStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/cluster/impl/NewDistributedLeadershipStore.java
@@ -47,7 +47,7 @@
  * primitive.
  */
 @Service
-@Component(immediate = true, enabled = false)
+@Component(immediate = true, enabled = true)
 public class NewDistributedLeadershipStore
     extends AbstractStore<LeadershipEvent, LeadershipStoreDelegate>
     implements LeadershipStore {