X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Factors%2FShardSnapshotActor.java;fp=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Factors%2FShardSnapshotActor.java;h=00bb424850027bd211b560edb025386da0894b00;hb=b70b396725749d3fd6ca761f02f4b630f6f4f1ce;hp=0000000000000000000000000000000000000000;hpb=92f2f20ea21e4e92d6407cd687d7dc34854e330a;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/actors/ShardSnapshotActor.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/actors/ShardSnapshotActor.java new file mode 100644 index 0000000000..00bb424850 --- /dev/null +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/actors/ShardSnapshotActor.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.cluster.datastore.actors; + +import akka.actor.ActorRef; +import akka.actor.Props; +import com.google.common.base.Preconditions; +import org.opendaylight.controller.cluster.common.actor.AbstractUntypedActorWithMetering; +import org.opendaylight.controller.cluster.datastore.persisted.ShardDataTreeSnapshot; +import org.opendaylight.controller.cluster.raft.base.messages.CaptureSnapshotReply; + +/** + * This is an offload actor, which is given an isolated snapshot of the data tree. It performs the potentially + * time-consuming operation of serializing the snapshot. + * + * @author Robert Varga + */ +public final class ShardSnapshotActor extends AbstractUntypedActorWithMetering { + // Internal message + private static final class SerializeSnapshot { + private final ShardDataTreeSnapshot snapshot; + private final ActorRef replyTo; + + SerializeSnapshot(final ShardDataTreeSnapshot snapshot, final ActorRef replyTo) { + this.snapshot = Preconditions.checkNotNull(snapshot); + this.replyTo = Preconditions.checkNotNull(replyTo); + } + + ShardDataTreeSnapshot getSnapshot() { + return snapshot; + } + + ActorRef getReplyTo() { + return replyTo; + } + } + + //actor name override used for metering. This does not change the "real" actor name + private static final String ACTOR_NAME_FOR_METERING = "shard-snapshot"; + + private ShardSnapshotActor() { + super(ACTOR_NAME_FOR_METERING); + } + + @Override + protected void handleReceive(final Object message) throws Exception { + if (message instanceof SerializeSnapshot) { + final SerializeSnapshot request = (SerializeSnapshot) message; + request.getReplyTo().tell(new CaptureSnapshotReply(request.getSnapshot().serialize()), ActorRef.noSender()); + } else { + unknownMessage(message); + } + } + + public static void requestSnapshot(final ActorRef snapshotActor, ShardDataTreeSnapshot snapshot, + final ActorRef replyTo) { + snapshotActor.tell(new SerializeSnapshot(snapshot, replyTo), ActorRef.noSender()); + } + + public static Props props() { + return Props.create(ShardSnapshotActor.class); + } +}