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 org.opendaylight.controller.cluster.datastore.jmx.mbeans.shard.ShardStats;
15 import org.opendaylight.controller.cluster.datastore.messages.CreateSnapshot;
16 import org.opendaylight.controller.cluster.datastore.messages.DataExists;
17 import org.opendaylight.controller.cluster.datastore.messages.ReadData;
18 import org.opendaylight.controller.cluster.datastore.utils.SerializationUtils;
19 import org.opendaylight.controller.cluster.raft.base.messages.CaptureSnapshotReply;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
21 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
27 public class ShardReadTransaction extends ShardTransaction {
28 private static final YangInstanceIdentifier DATASTORE_ROOT = YangInstanceIdentifier.builder().build();
30 private final AbstractShardDataTreeTransaction<?> transaction;
32 public ShardReadTransaction(AbstractShardDataTreeTransaction<?> transaction, ActorRef shardActor,
33 ShardStats shardStats, String transactionID) {
34 super(shardActor, shardStats, transactionID);
35 this.transaction = transaction;
39 public void handleReceive(Object message) throws Exception {
40 if (message instanceof CreateSnapshot) {
42 } else if(ReadData.isSerializedType(message)) {
43 readData(transaction, ReadData.fromSerializable(message));
44 } else if(DataExists.isSerializedType(message)) {
45 dataExists(transaction, DataExists.fromSerializable(message));
48 super.handleReceive(message);
52 private void createSnapshot() {
54 // This is a special message sent by the shard to send back a serialized snapshot of the whole
55 // data store tree. This transaction was created for that purpose only so we can
56 // self-destruct after sending the reply.
58 final ActorRef sender = getSender();
59 final ActorRef self = getSelf();
60 final Optional<NormalizedNode<?, ?>> result = transaction.getSnapshot().readNode(DATASTORE_ROOT);
62 byte[] serialized = SerializationUtils.serializeNormalizedNode(result.get());
63 sender.tell(new CaptureSnapshotReply(serialized), self);
65 self.tell(PoisonPill.getInstance(), self);
69 protected AbstractShardDataTreeTransaction<?> getDOMStoreTransaction() {
74 protected boolean returnCloseTransactionReply() {