import akka.actor.ActorSelection;
import akka.actor.ActorSystem;
import akka.actor.Props;
+import akka.cluster.Cluster;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.Set;
import java.util.function.LongSupplier;
import org.opendaylight.controller.cluster.DataPersistenceProvider;
private int numVotingPeers = -1;
+ private Optional<Cluster> cluster;
+
public RaftActorContextImpl(ActorRef actor, ActorContext context, String id,
ElectionTerm termInformation, long commitIndex, long lastApplied, Map<String, String> peerAddresses,
ConfigParams configParams, DataPersistenceProvider persistenceProvider, Logger logger) {
return actor;
}
+ @Override
+ public Optional<Cluster> getCluster() {
+ if(cluster == null) {
+ try {
+ cluster = Optional.of(Cluster.get(getActorSystem()));
+ } catch(Exception e) {
+ // An exception means there's no cluster configured. This will only happen in unit tests.
+ LOG.debug("{}: Could not obtain Cluster: {}", getId(), e);
+ cluster = Optional.empty();
+ }
+ }
+
+ return cluster;
+ }
+
@Override
public ElectionTerm getTermInformation() {
return termInformation;