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 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 * Transient behavior handling messages while the new generation is being persisted.
23 * @author Robert Varga
25 final class SavingClientActorBehavior extends RecoveredClientActorBehavior<InitialClientActorContext> {
26 private static final Logger LOG = LoggerFactory.getLogger(SavingClientActorBehavior.class);
27 private final ClientIdentifier myId;
29 SavingClientActorBehavior(final InitialClientActorContext context, final ClientIdentifier nextId) {
31 this.myId = Preconditions.checkNotNull(nextId);
35 AbstractClientActorBehavior<?> onReceiveCommand(final Object command) {
36 if (command instanceof SaveSnapshotFailure) {
37 LOG.error("{}: failed to persist state", persistenceId(), ((SaveSnapshotFailure) command).cause());
39 } else if (command instanceof SaveSnapshotSuccess) {
40 LOG.debug("{}: got command: {}", persistenceId(), command);
41 SaveSnapshotSuccess saved = (SaveSnapshotSuccess)command;
42 context().deleteSnapshots(new SnapshotSelectionCriteria(saved.metadata().sequenceNr(),
43 saved.metadata().timestamp() - 1, 0L, 0L));
45 } else if (command instanceof DeleteSnapshotsSuccess) {
46 LOG.debug("{}: got command: {}", persistenceId(), command);
47 } else if (command instanceof DeleteSnapshotsFailure) {
48 // Not treating this as a fatal error.
49 LOG.warn("{}: failed to delete prior snapshots", persistenceId(),
50 ((DeleteSnapshotsFailure) command).cause());
52 LOG.debug("{}: stashing command {}", persistenceId(), command);
58 return context().createBehavior(myId);