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