Merge changes I3e404877,Ida2a5c32,I9e6ce426,I6a4b90f6,I79717533
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / ShardReadWriteTransaction.java
1 /*
2  *
3  *  Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
4  *
5  *  This program and the accompanying materials are made available under the
6  *  terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  *  and is available at http://www.eclipse.org/legal/epl-v10.html
8  *
9  */
10
11 package org.opendaylight.controller.cluster.datastore;
12
13 import akka.actor.ActorRef;
14 import org.opendaylight.controller.cluster.datastore.jmx.mbeans.shard.ShardStats;
15 import org.opendaylight.controller.cluster.datastore.messages.DataExists;
16 import org.opendaylight.controller.cluster.datastore.messages.ReadData;
17 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction;
18 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
19
20 /**
21  * @author: syedbahm
22  * Date: 8/6/14
23  */
24 public class ShardReadWriteTransaction extends ShardWriteTransaction {
25     private final DOMStoreReadWriteTransaction transaction;
26
27     public ShardReadWriteTransaction(DOMStoreReadWriteTransaction transaction, ActorRef shardActor,
28             SchemaContext schemaContext, ShardStats shardStats, String transactionID,
29             short clientTxVersion) {
30         super(transaction, shardActor, schemaContext, shardStats, transactionID, clientTxVersion);
31         this.transaction = transaction;
32     }
33
34     @Override
35     public void handleReceive(Object message) throws Exception {
36         if (message instanceof ReadData) {
37             readData(transaction, (ReadData) message, !SERIALIZED_REPLY);
38
39         } else if (message instanceof DataExists) {
40             dataExists(transaction, (DataExists) message, !SERIALIZED_REPLY);
41
42         } else if(ReadData.SERIALIZABLE_CLASS.equals(message.getClass())) {
43             readData(transaction, ReadData.fromSerializable(message), SERIALIZED_REPLY);
44
45         } else if(DataExists.SERIALIZABLE_CLASS.equals(message.getClass())) {
46             dataExists(transaction, DataExists.fromSerializable(message), SERIALIZED_REPLY);
47
48         } else {
49             super.handleReceive(message);
50         }
51     }
52 }