Merge "Fix test coverage not being reported in Sonar"
[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 akka.actor.PoisonPill;
15 import akka.event.Logging;
16 import akka.event.LoggingAdapter;
17 import org.opendaylight.controller.cluster.datastore.messages.CloseTransaction;
18 import org.opendaylight.controller.cluster.datastore.messages.CloseTransactionReply;
19 import org.opendaylight.controller.cluster.datastore.messages.DeleteData;
20 import org.opendaylight.controller.cluster.datastore.messages.MergeData;
21 import org.opendaylight.controller.cluster.datastore.messages.ReadData;
22 import org.opendaylight.controller.cluster.datastore.messages.ReadyTransaction;
23 import org.opendaylight.controller.cluster.datastore.messages.WriteData;
24 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction;
25 import org.opendaylight.controller.sal.core.spi.data.DOMStoreTransactionChain;
26 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
27
28 /**
29  * @author: syedbahm
30  * Date: 8/6/14
31  */
32 public class ShardReadWriteTransaction extends ShardTransaction {
33   private final DOMStoreReadWriteTransaction transaction;
34   private final LoggingAdapter log =
35       Logging.getLogger(getContext().system(), this);
36   public ShardReadWriteTransaction(DOMStoreTransactionChain transactionChain, DOMStoreReadWriteTransaction transaction, ActorRef shardActor, SchemaContext schemaContext) {
37     super(transactionChain,  shardActor, schemaContext);
38     this.transaction = transaction;
39   }
40
41   public ShardReadWriteTransaction(DOMStoreReadWriteTransaction transaction, ActorRef shardActor, SchemaContext schemaContext) {
42     super( shardActor, schemaContext);
43     this.transaction = transaction;
44   }
45
46   @Override
47   public void handleReceive(Object message) throws Exception {
48     if (ReadData.SERIALIZABLE_CLASS.equals(message.getClass())) {
49       readData(transaction,ReadData.fromSerializable(message));
50     }else if (WriteData.SERIALIZABLE_CLASS.equals(message.getClass())) {
51       writeData(transaction, WriteData.fromSerializable(message, schemaContext));
52     } else if (MergeData.SERIALIZABLE_CLASS.equals(message.getClass())) {
53       mergeData(transaction, MergeData.fromSerializable(message, schemaContext));
54     } else if (DeleteData.SERIALIZABLE_CLASS.equals(message.getClass())) {
55       deleteData(transaction,DeleteData.fromSerizalizable(message));
56     } else if (ReadyTransaction.SERIALIZABLE_CLASS.equals(message.getClass())) {
57       readyTransaction(transaction,new ReadyTransaction());
58     }else {
59       super.handleReceive(message);
60     }
61   }
62
63   protected void closeTransaction(CloseTransaction message) {
64     transaction.close();
65     getSender().tell(new CloseTransactionReply().toSerializable(), getSelf());
66     getSelf().tell(PoisonPill.getInstance(), getSelf());
67   }
68 }