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.SaveSnapshotFailure;
11 import akka.persistence.SaveSnapshotSuccess;
12 import akka.persistence.SnapshotSelectionCriteria;
13 import com.google.common.base.Preconditions;
14 import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
19 * @author Robert Varga
21 final class SavingClientActorBehavior extends RecoveredClientActorBehavior<InitialClientActorContext> {
22 private static final Logger LOG = LoggerFactory.getLogger(SavingClientActorBehavior.class);
23 private final ClientIdentifier myId;
25 SavingClientActorBehavior(final InitialClientActorContext context, final ClientIdentifier nextId) {
27 this.myId = Preconditions.checkNotNull(nextId);
31 AbstractClientActorBehavior<?> onReceiveCommand(final Object command) {
32 if (command instanceof SaveSnapshotFailure) {
33 LOG.error("{}: failed to persist state", persistenceId(), ((SaveSnapshotFailure) command).cause());
35 } else if (command instanceof SaveSnapshotSuccess) {
38 SaveSnapshotSuccess saved = (SaveSnapshotSuccess)command;
39 context().deleteSnapshots(new SnapshotSelectionCriteria(saved.metadata().sequenceNr(),
40 saved.metadata().timestamp() - 1, 0L, 0L));
42 return context().createBehavior(myId);
44 LOG.debug("{}: stashing command {}", persistenceId(), command);