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;
10 import akka.actor.ActorRef;
11 import akka.actor.Props;
12 import com.google.common.base.Preconditions;
13 import org.opendaylight.controller.cluster.common.actor.AbstractUntypedActorWithMetering;
14 import org.opendaylight.controller.cluster.datastore.persisted.ShardDataTreeSnapshot;
15 import org.opendaylight.controller.cluster.raft.base.messages.CaptureSnapshotReply;
18 * This is an offload actor, which is given an isolated snapshot of the data tree. It performs the potentially
19 * time-consuming operation of serializing the snapshot.
21 * @author Robert Varga
23 public final class ShardSnapshotActor extends AbstractUntypedActorWithMetering {
25 private static final class SerializeSnapshot {
26 private final ShardDataTreeSnapshot snapshot;
27 private final ActorRef replyTo;
29 SerializeSnapshot(final ShardDataTreeSnapshot snapshot, final ActorRef replyTo) {
30 this.snapshot = Preconditions.checkNotNull(snapshot);
31 this.replyTo = Preconditions.checkNotNull(replyTo);
34 ShardDataTreeSnapshot getSnapshot() {
38 ActorRef getReplyTo() {
43 //actor name override used for metering. This does not change the "real" actor name
44 private static final String ACTOR_NAME_FOR_METERING = "shard-snapshot";
46 private ShardSnapshotActor() {
47 super(ACTOR_NAME_FOR_METERING);
51 protected void handleReceive(final Object message) throws Exception {
52 if (message instanceof SerializeSnapshot) {
53 final SerializeSnapshot request = (SerializeSnapshot) message;
54 request.getReplyTo().tell(new CaptureSnapshotReply(request.getSnapshot().serialize()), ActorRef.noSender());
56 unknownMessage(message);
60 public static void requestSnapshot(final ActorRef snapshotActor, ShardDataTreeSnapshot snapshot,
61 final ActorRef replyTo) {
62 snapshotActor.tell(new SerializeSnapshot(snapshot, replyTo), ActorRef.noSender());
65 public static Props props() {
66 return Props.create(ShardSnapshotActor.class);