X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-akka-raft%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fraft%2FRaftActorContextImpl.java;h=8ba0f48d72e9ca8c5825f657bdc5ec9940365c17;hp=19d796c9363aa928e7f287e218807093fa93f2a3;hb=refs%2Fchanges%2F09%2F83009%2F6;hpb=2d60632f7cf63712e8357a3cf3fc40d83366e5e6 diff --git a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActorContextImpl.java b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActorContextImpl.java index 19d796c936..8ba0f48d72 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActorContextImpl.java +++ b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActorContextImpl.java @@ -5,9 +5,10 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.controller.cluster.raft; +import static java.util.Objects.requireNonNull; + import akka.actor.ActorContext; import akka.actor.ActorRef; import akka.actor.ActorSelection; @@ -15,7 +16,6 @@ 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.Collection; import java.util.HashMap; @@ -24,10 +24,10 @@ import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Set; +import java.util.concurrent.Executor; import java.util.function.Consumer; import java.util.function.LongSupplier; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; +import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.controller.cluster.DataPersistenceProvider; import org.opendaylight.controller.cluster.io.FileBackedOutputStreamFactory; import org.opendaylight.controller.cluster.raft.base.messages.ApplyState; @@ -50,6 +50,8 @@ public class RaftActorContextImpl implements RaftActorContext { private final ActorContext context; + private final @NonNull Executor executor; + private final String id; private final ElectionTerm termInformation; @@ -94,25 +96,27 @@ public class RaftActorContextImpl implements RaftActorContext { private RaftActorLeadershipTransferCohort leadershipTransferCohort; public RaftActorContextImpl(final ActorRef actor, final ActorContext context, final String id, - @Nonnull final ElectionTerm termInformation, final long commitIndex, final long lastApplied, - @Nonnull final Map peerAddresses, - @Nonnull final ConfigParams configParams, @Nonnull final DataPersistenceProvider persistenceProvider, - @Nonnull final Consumer applyStateConsumer, @Nonnull final Logger logger) { + final @NonNull ElectionTerm termInformation, final long commitIndex, final long lastApplied, + final @NonNull Map peerAddresses, + final @NonNull ConfigParams configParams, final @NonNull DataPersistenceProvider persistenceProvider, + final @NonNull Consumer applyStateConsumer, final @NonNull Logger logger, + final @NonNull Executor executor) { this.actor = actor; this.context = context; this.id = id; - this.termInformation = Preconditions.checkNotNull(termInformation); + this.termInformation = requireNonNull(termInformation); + this.executor = requireNonNull(executor); this.commitIndex = commitIndex; this.lastApplied = lastApplied; - this.configParams = Preconditions.checkNotNull(configParams); - this.persistenceProvider = Preconditions.checkNotNull(persistenceProvider); - this.log = Preconditions.checkNotNull(logger); - this.applyStateConsumer = Preconditions.checkNotNull(applyStateConsumer); + this.configParams = requireNonNull(configParams); + this.persistenceProvider = requireNonNull(persistenceProvider); + this.log = requireNonNull(logger); + this.applyStateConsumer = requireNonNull(applyStateConsumer); fileBackedOutputStreamFactory = new FileBackedOutputStreamFactory( configParams.getFileBackedStreamingThreshold(), configParams.getTempFileDirectory()); - for (Map.Entry e: Preconditions.checkNotNull(peerAddresses).entrySet()) { + for (Map.Entry e : requireNonNull(peerAddresses).entrySet()) { peerInfoMap.put(e.getKey(), new PeerInfo(e.getKey(), e.getValue(), VotingState.VOTING)); } } @@ -151,6 +155,11 @@ public class RaftActorContextImpl implements RaftActorContext { return actor; } + @Override + public final Executor getExecutor() { + return executor; + } + @Override @SuppressWarnings("checkstyle:IllegalCatch") public Optional getCluster() { @@ -159,7 +168,7 @@ public class RaftActorContextImpl implements RaftActorContext { 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); + log.debug("{}: Could not obtain Cluster", getId(), e); cluster = Optional.empty(); } } @@ -404,7 +413,7 @@ public class RaftActorContextImpl implements RaftActorContext { } void setCurrentBehavior(final RaftActorBehavior behavior) { - this.currentBehavior = Preconditions.checkNotNull(behavior); + this.currentBehavior = requireNonNull(behavior); } @Override @@ -429,15 +438,13 @@ public class RaftActorContextImpl implements RaftActorContext { } @Override - @Nullable public RaftActorLeadershipTransferCohort getRaftActorLeadershipTransferCohort() { return leadershipTransferCohort; } @Override @SuppressWarnings("checkstyle:hiddenField") - public void setRaftActorLeadershipTransferCohort( - @Nullable final RaftActorLeadershipTransferCohort leadershipTransferCohort) { + public void setRaftActorLeadershipTransferCohort(final RaftActorLeadershipTransferCohort leadershipTransferCohort) { this.leadershipTransferCohort = leadershipTransferCohort; } }