BUG-5280: centralize ShardSnapshot operations
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / ShardReadTransaction.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.cluster.datastore;
10
11 import akka.actor.ActorRef;
12 import com.google.common.base.Preconditions;
13 import org.opendaylight.controller.cluster.datastore.jmx.mbeans.shard.ShardStats;
14 import org.opendaylight.controller.cluster.datastore.messages.DataExists;
15 import org.opendaylight.controller.cluster.datastore.messages.ReadData;
16
17 /**
18  * @author: syedbahm
19  * Date: 8/6/14
20  */
21 public class ShardReadTransaction extends ShardTransaction {
22     private final AbstractShardDataTreeTransaction<?> transaction;
23
24     public ShardReadTransaction(AbstractShardDataTreeTransaction<?> transaction, ActorRef shardActor,
25             ShardStats shardStats) {
26         super(shardActor, shardStats, transaction.getId());
27         this.transaction = Preconditions.checkNotNull(transaction);
28     }
29
30     @Override
31     public void handleReceive(Object message) {
32         if (ReadData.isSerializedType(message)) {
33             readData(transaction, ReadData.fromSerializable(message));
34         } else if (DataExists.isSerializedType(message)) {
35             dataExists(transaction, DataExists.fromSerializable(message));
36         } else {
37             super.handleReceive(message);
38         }
39     }
40
41     @Override
42     protected AbstractShardDataTreeTransaction<?> getDOMStoreTransaction() {
43         return transaction;
44     }
45
46     @Override
47     protected boolean returnCloseTransactionReply() {
48         return false;
49     }
50 }