Merge "BUG-1679: optinally log allocation context"
[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
15 import org.opendaylight.controller.cluster.datastore.jmx.mbeans.shard.ShardStats;
16 import org.opendaylight.controller.cluster.datastore.messages.DataExists;
17 import org.opendaylight.controller.cluster.datastore.messages.DeleteData;
18 import org.opendaylight.controller.cluster.datastore.messages.MergeData;
19 import org.opendaylight.controller.cluster.datastore.messages.ReadData;
20 import org.opendaylight.controller.cluster.datastore.messages.ReadyTransaction;
21 import org.opendaylight.controller.cluster.datastore.messages.WriteData;
22 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction;
23 import org.opendaylight.controller.sal.core.spi.data.DOMStoreTransaction;
24 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
25
26 /**
27  * @author: syedbahm
28  * Date: 8/6/14
29  */
30 public class ShardReadWriteTransaction extends ShardTransaction {
31     private final DOMStoreReadWriteTransaction transaction;
32
33     public ShardReadWriteTransaction(DOMStoreReadWriteTransaction transaction, ActorRef shardActor,
34             SchemaContext schemaContext, ShardStats shardStats) {
35         super(shardActor, schemaContext, shardStats);
36         this.transaction = transaction;
37     }
38
39     @Override
40     public void handleReceive(Object message) throws Exception {
41         if(ReadData.SERIALIZABLE_CLASS.equals(message.getClass())) {
42             readData(transaction, ReadData.fromSerializable(message));
43         } else if(WriteData.SERIALIZABLE_CLASS.equals(message.getClass())) {
44             writeData(transaction, WriteData.fromSerializable(message, schemaContext));
45         } else if(MergeData.SERIALIZABLE_CLASS.equals(message.getClass())) {
46             mergeData(transaction, MergeData.fromSerializable(message, schemaContext));
47         } else if(DeleteData.SERIALIZABLE_CLASS.equals(message.getClass())) {
48             deleteData(transaction, DeleteData.fromSerializable(message));
49         } else if(ReadyTransaction.SERIALIZABLE_CLASS.equals(message.getClass())) {
50             readyTransaction(transaction, new ReadyTransaction());
51         } else if(DataExists.SERIALIZABLE_CLASS.equals(message.getClass())) {
52             dataExists(transaction, DataExists.fromSerializable(message));
53         } else {
54             super.handleReceive(message);
55         }
56     }
57
58     @Override
59     protected DOMStoreTransaction getDOMStoreTransaction() {
60         return transaction;
61     }
62 }