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%2FTimedRunnable.java;h=93b5f04df33d8ee92ccef6c6b4a007ad56189859;hp=933b134341ae6502c59074d75c27f1a9f275d6dc;hb=HEAD;hpb=135129e0cca66040fd512fab740d59b2ab1f8382 diff --git a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/TimedRunnable.java b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/TimedRunnable.java index 933b134341..93b5f04df3 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/TimedRunnable.java +++ b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/TimedRunnable.java @@ -7,13 +7,16 @@ */ package org.opendaylight.controller.cluster.raft; +import static java.util.Objects.requireNonNull; + import akka.actor.Cancellable; -import com.google.common.base.Preconditions; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import scala.concurrent.duration.FiniteDuration; /** * An abstract class that implements a Runnable operation with a timer such that if the run method isn't * invoked within a timeout period, the operation is cancelled via {@link #doCancel}. + * *

* Note: this class is not thread safe and is intended for use only within the context of the same * actor that's passed on construction. The run method must be called on this actor's thread dispatcher as it @@ -25,20 +28,17 @@ abstract class TimedRunnable implements Runnable { private final Cancellable cancelTimer; private boolean canRun = true; - TimedRunnable(FiniteDuration timeout, RaftActor actor) { - Preconditions.checkNotNull(timeout); - Preconditions.checkNotNull(actor); - cancelTimer = actor.getContext().system().scheduler().scheduleOnce(timeout, actor.self(), new Runnable() { - @Override - public void run() { - cancel(); - } - }, actor.getContext().system().dispatcher(), actor.self()); + @SuppressFBWarnings(value = "MC_OVERRIDABLE_METHOD_CALL_IN_CONSTRUCTOR", + justification = "https://github.com/spotbugs/spotbugs/issues/1867") + TimedRunnable(final FiniteDuration timeout, final RaftActor actor) { + cancelTimer = requireNonNull(actor).getContext().system().scheduler() + .scheduleOnce(requireNonNull(timeout), actor.self(), (Runnable) this::cancel, + actor.getContext().system().dispatcher(), actor.self()); } @Override public void run() { - if(canRun) { + if (canRun) { canRun = false; cancelTimer.cancel(); doRun();