2 * Copyright (c) 2014 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
9 package org.opendaylight.controller.cluster.datastore;
11 import akka.actor.ActorRef;
12 import akka.actor.PoisonPill;
13 import com.google.common.base.Optional;
14 import com.google.common.base.Preconditions;
15 import org.opendaylight.controller.cluster.datastore.jmx.mbeans.shard.ShardStats;
16 import org.opendaylight.controller.cluster.datastore.messages.CreateSnapshot;
17 import org.opendaylight.controller.cluster.datastore.messages.DataExists;
18 import org.opendaylight.controller.cluster.datastore.messages.ReadData;
19 import org.opendaylight.controller.cluster.datastore.utils.SerializationUtils;
20 import org.opendaylight.controller.cluster.raft.base.messages.CaptureSnapshotReply;
21 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
22 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
28 public class ShardReadTransaction extends ShardTransaction {
29 private final AbstractShardDataTreeTransaction<?> transaction;
31 public ShardReadTransaction(AbstractShardDataTreeTransaction<?> transaction, ActorRef shardActor,
32 ShardStats shardStats) {
33 super(shardActor, shardStats, transaction.getId());
34 this.transaction = Preconditions.checkNotNull(transaction);
38 public void handleReceive(Object message) {
39 if (message instanceof CreateSnapshot) {
41 } else if(ReadData.isSerializedType(message)) {
42 readData(transaction, ReadData.fromSerializable(message));
43 } else if(DataExists.isSerializedType(message)) {
44 dataExists(transaction, DataExists.fromSerializable(message));
46 super.handleReceive(message);
50 private void createSnapshot() {
52 // This is a special message sent by the shard to send back a serialized snapshot of the whole
53 // data store tree. This transaction was created for that purpose only so we can
54 // self-destruct after sending the reply.
56 final ActorRef sender = getSender();
57 final ActorRef self = getSelf();
58 final Optional<NormalizedNode<?, ?>> result = transaction.getSnapshot().readNode(YangInstanceIdentifier.EMPTY);
60 byte[] serialized = SerializationUtils.serializeNormalizedNode(result.get());
61 sender.tell(new CaptureSnapshotReply(serialized), self);
63 self.tell(PoisonPill.getInstance(), self);
67 protected AbstractShardDataTreeTransaction<?> getDOMStoreTransaction() {
72 protected boolean returnCloseTransactionReply() {