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.RecoveryCompleted;
11 import akka.persistence.SnapshotOffer;
12 import com.google.common.base.Preconditions;
13 import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
14 import org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
19 * Transient behavior handling messages during initial actor recovery.
21 * @author Robert Varga
23 final class RecoveringClientActorBehavior extends AbstractClientActorBehavior<InitialClientActorContext> {
24 private static final Logger LOG = LoggerFactory.getLogger(RecoveringClientActorBehavior.class);
25 private final FrontendIdentifier currentFrontend;
26 private ClientIdentifier lastId = null;
28 RecoveringClientActorBehavior(final InitialClientActorContext context, final FrontendIdentifier frontendId) {
30 currentFrontend = Preconditions.checkNotNull(frontendId);
34 AbstractClientActorBehavior<?> onReceiveCommand(final Object command) {
35 throw new IllegalStateException("Frontend is recovering");
39 AbstractClientActorBehavior<?> onReceiveRecover(final Object recover) {
40 if (recover instanceof RecoveryCompleted) {
41 final ClientIdentifier nextId;
43 if (!currentFrontend.equals(lastId.getFrontendId())) {
44 LOG.error("{}: Mismatched frontend identifier, shutting down. Current: {} Saved: {}",
45 persistenceId(), currentFrontend, lastId.getFrontendId());
49 nextId = ClientIdentifier.create(currentFrontend, lastId.getGeneration() + 1);
51 nextId = ClientIdentifier.create(currentFrontend, 0);
54 LOG.debug("{}: persisting new identifier {}", persistenceId(), nextId);
55 context().saveSnapshot(nextId);
56 return new SavingClientActorBehavior(context(), nextId);
57 } else if (recover instanceof SnapshotOffer) {
58 lastId = (ClientIdentifier) ((SnapshotOffer)recover).snapshot();
59 LOG.debug("{}: recovered identifier {}", persistenceId(), lastId);
61 LOG.warn("{}: ignoring recovery message {}", persistenceId(), recover);