2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.cluster.access.client;
10 import static java.util.Objects.requireNonNull;
12 import akka.persistence.DeleteSnapshotsFailure;
13 import akka.persistence.DeleteSnapshotsSuccess;
14 import akka.persistence.SaveSnapshotFailure;
15 import akka.persistence.SaveSnapshotSuccess;
16 import akka.persistence.SnapshotSelectionCriteria;
17 import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
22 * Transient behavior handling messages while the new generation is being persisted.
24 * @author Robert Varga
26 final class SavingClientActorBehavior extends RecoveredClientActorBehavior<InitialClientActorContext> {
27 private static final Logger LOG = LoggerFactory.getLogger(SavingClientActorBehavior.class);
28 private final ClientIdentifier myId;
30 SavingClientActorBehavior(final InitialClientActorContext context, final ClientIdentifier nextId) {
32 myId = requireNonNull(nextId);
36 AbstractClientActorBehavior<?> onReceiveCommand(final Object command) {
37 if (command instanceof SaveSnapshotFailure saveFailure) {
38 LOG.error("{}: failed to persist state", persistenceId(), saveFailure.cause());
40 } else if (command instanceof SaveSnapshotSuccess saved) {
41 LOG.debug("{}: got command: {}", persistenceId(), saved);
42 context().deleteSnapshots(new SnapshotSelectionCriteria(scala.Long.MaxValue(),
43 saved.metadata().timestamp() - 1, 0L, 0L));
45 } else if (command instanceof DeleteSnapshotsSuccess deleteSuccess) {
46 LOG.debug("{}: got command: {}", persistenceId(), deleteSuccess);
47 } else if (command instanceof DeleteSnapshotsFailure deleteFailure) {
48 // Not treating this as a fatal error.
49 LOG.warn("{}: failed to delete prior snapshots", persistenceId(), deleteFailure.cause());
51 LOG.debug("{}: stashing command {}", persistenceId(), command);
57 return context().createBehavior(myId);