Merge "Bug 1446: Add JMX stats for clustered data store"
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / ShardWriteTransaction.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.DeleteData;
17 import org.opendaylight.controller.cluster.datastore.messages.MergeData;
18 import org.opendaylight.controller.cluster.datastore.messages.ReadyTransaction;
19 import org.opendaylight.controller.cluster.datastore.messages.WriteData;
20 import org.opendaylight.controller.sal.core.spi.data.DOMStoreTransaction;
21 import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction;
22 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
23
24 /**
25  * @author: syedbahm
26  * Date: 8/6/14
27  */
28 public class ShardWriteTransaction extends ShardTransaction {
29     private final DOMStoreWriteTransaction transaction;
30
31     public ShardWriteTransaction(DOMStoreWriteTransaction transaction, ActorRef shardActor,
32             SchemaContext schemaContext, ShardStats shardStats) {
33         super(shardActor, schemaContext, shardStats);
34         this.transaction = transaction;
35     }
36
37     @Override
38     public void handleReceive(Object message) throws Exception {
39         if(WriteData.SERIALIZABLE_CLASS.equals(message.getClass())) {
40             writeData(transaction, WriteData.fromSerializable(message, schemaContext));
41         } else if(MergeData.SERIALIZABLE_CLASS.equals(message.getClass())) {
42             mergeData(transaction, MergeData.fromSerializable(message, schemaContext));
43         } else if(DeleteData.SERIALIZABLE_CLASS.equals(message.getClass())) {
44             deleteData(transaction, DeleteData.fromSerializable(message));
45         } else if(ReadyTransaction.SERIALIZABLE_CLASS.equals(message.getClass())) {
46             readyTransaction(transaction, new ReadyTransaction());
47         } else {
48             super.handleReceive(message);
49         }
50     }
51
52     @Override
53     protected DOMStoreTransaction getDOMStoreTransaction() {
54         return transaction;
55     }
56 }