X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fcds-access-client%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Faccess%2Fclient%2FSavingClientActorBehavior.java;h=feca185812c7652c4ef84bb74d204723e9864ff4;hb=HEAD;hp=58a10776f4b6723303c42eeae05024c841ad1f44;hpb=2f606b3ee1b8e47977320374e37f3d5c1d546f9b;p=controller.git diff --git a/opendaylight/md-sal/cds-access-client/src/main/java/org/opendaylight/controller/cluster/access/client/SavingClientActorBehavior.java b/opendaylight/md-sal/cds-access-client/src/main/java/org/opendaylight/controller/cluster/access/client/SavingClientActorBehavior.java index 58a10776f4..bf0713cef6 100644 --- a/opendaylight/md-sal/cds-access-client/src/main/java/org/opendaylight/controller/cluster/access/client/SavingClientActorBehavior.java +++ b/opendaylight/md-sal/cds-access-client/src/main/java/org/opendaylight/controller/cluster/access/client/SavingClientActorBehavior.java @@ -7,20 +7,19 @@ */ package org.opendaylight.controller.cluster.access.client; +import static java.util.Objects.requireNonNull; + import akka.persistence.DeleteSnapshotsFailure; import akka.persistence.DeleteSnapshotsSuccess; import akka.persistence.SaveSnapshotFailure; import akka.persistence.SaveSnapshotSuccess; import akka.persistence.SnapshotSelectionCriteria; -import com.google.common.base.Preconditions; import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Transient behavior handling messages while the new generation is being persisted. - * - * @author Robert Varga */ final class SavingClientActorBehavior extends RecoveredClientActorBehavior { private static final Logger LOG = LoggerFactory.getLogger(SavingClientActorBehavior.class); @@ -28,30 +27,34 @@ final class SavingClientActorBehavior extends RecoveredClientActorBehavior onReceiveCommand(final Object command) { - if (command instanceof SaveSnapshotFailure) { - LOG.error("{}: failed to persist state", persistenceId(), ((SaveSnapshotFailure) command).cause()); - return null; - } else if (command instanceof SaveSnapshotSuccess) { - LOG.debug("{}: got command: {}", persistenceId(), command); - SaveSnapshotSuccess saved = (SaveSnapshotSuccess)command; - context().deleteSnapshots(new SnapshotSelectionCriteria(scala.Long.MaxValue(), - saved.metadata().timestamp() - 1, 0L, 0L)); - return this; - } else if (command instanceof DeleteSnapshotsSuccess) { - LOG.debug("{}: got command: {}", persistenceId(), command); - } else if (command instanceof DeleteSnapshotsFailure) { - // Not treating this as a fatal error. - LOG.warn("{}: failed to delete prior snapshots", persistenceId(), - ((DeleteSnapshotsFailure) command).cause()); - } else { - LOG.debug("{}: stashing command {}", persistenceId(), command); - context().stash(); - return this; + switch (command) { + case SaveSnapshotFailure saveFailure -> { + LOG.error("{}: failed to persist state", persistenceId(), saveFailure.cause()); + return null; + } + case SaveSnapshotSuccess saved -> { + LOG.debug("{}: got command: {}", persistenceId(), saved); + context().deleteSnapshots(new SnapshotSelectionCriteria(scala.Long.MaxValue(), + saved.metadata().timestamp() - 1, 0L, 0L)); + return this; + } + case DeleteSnapshotsSuccess deleteSuccess -> { + LOG.debug("{}: got command: {}", persistenceId(), deleteSuccess); + } + case DeleteSnapshotsFailure deleteFailure -> { + // Not treating this as a fatal error. + LOG.warn("{}: failed to delete prior snapshots", persistenceId(), deleteFailure.cause()); + } + default -> { + LOG.debug("{}: stashing command {}", persistenceId(), command); + context().stash(); + return this; + } } context().unstash();