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.datastore.actors.client;
10 import akka.persistence.DeleteSnapshotsFailure;
11 import akka.persistence.DeleteSnapshotsSuccess;
12 import akka.persistence.SaveSnapshotFailure;
13 import akka.persistence.SaveSnapshotSuccess;
14 import akka.persistence.SnapshotSelectionCriteria;
15 import com.google.common.base.Preconditions;
16 import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
21 * @author Robert Varga
23 final class SavingClientActorBehavior extends RecoveredClientActorBehavior<InitialClientActorContext> {
24 private static final Logger LOG = LoggerFactory.getLogger(SavingClientActorBehavior.class);
25 private final ClientIdentifier myId;
27 SavingClientActorBehavior(final InitialClientActorContext context, final ClientIdentifier nextId) {
29 this.myId = Preconditions.checkNotNull(nextId);
33 AbstractClientActorBehavior<?> onReceiveCommand(final Object command) {
34 if (command instanceof SaveSnapshotFailure) {
35 LOG.error("{}: failed to persist state", persistenceId(), ((SaveSnapshotFailure) command).cause());
37 } else if (command instanceof SaveSnapshotSuccess) {
38 LOG.debug("{}: got command: {}", persistenceId(), command);
39 SaveSnapshotSuccess saved = (SaveSnapshotSuccess)command;
40 context().deleteSnapshots(new SnapshotSelectionCriteria(saved.metadata().sequenceNr(),
41 saved.metadata().timestamp() - 1, 0L, 0L));
43 } else if (command instanceof DeleteSnapshotsSuccess) {
44 LOG.debug("{}: got command: {}", persistenceId(), command);
45 } else if (command instanceof DeleteSnapshotsFailure) {
46 // Not treating this as a fatal error.
47 LOG.warn("{}: failed to delete prior snapshots", persistenceId(), ((DeleteSnapshotsFailure) command).cause());
49 LOG.debug("{}: stashing command {}", persistenceId(), command);
55 return context().createBehavior(myId);