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 this.myId = requireNonNull(nextId);
36 AbstractClientActorBehavior<?> onReceiveCommand(final Object command) {
37 if (command instanceof SaveSnapshotFailure) {
38 LOG.error("{}: failed to persist state", persistenceId(), ((SaveSnapshotFailure) command).cause());
40 } else if (command instanceof SaveSnapshotSuccess) {
41 LOG.debug("{}: got command: {}", persistenceId(), command);
42 SaveSnapshotSuccess saved = (SaveSnapshotSuccess)command;
43 context().deleteSnapshots(new SnapshotSelectionCriteria(scala.Long.MaxValue(),
44 saved.metadata().timestamp() - 1, 0L, 0L));
46 } else if (command instanceof DeleteSnapshotsSuccess) {
47 LOG.debug("{}: got command: {}", persistenceId(), command);
48 } else if (command instanceof DeleteSnapshotsFailure) {
49 // Not treating this as a fatal error.
50 LOG.warn("{}: failed to delete prior snapshots", persistenceId(),
51 ((DeleteSnapshotsFailure) command).cause());
53 LOG.debug("{}: stashing command {}", persistenceId(), command);
59 return context().createBehavior(myId);