Merge "Bug-1338: Create a grouping for order to help create generic OrderComparator...
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / ShardReadTransaction.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.DataExists;
20 import org.opendaylight.controller.cluster.datastore.messages.ReadData;
21 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction;
22 import org.opendaylight.controller.sal.core.spi.data.DOMStoreTransactionChain;
23 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
24
25 /**
26  * @author: syedbahm
27  * Date: 8/6/14
28  */
29 public class ShardReadTransaction extends ShardTransaction {
30   private final DOMStoreReadTransaction transaction;
31   private final LoggingAdapter log =
32       Logging.getLogger(getContext().system(), this);
33
34   public ShardReadTransaction(DOMStoreReadTransaction transaction, ActorRef shardActor, SchemaContext schemaContext) {
35     super(shardActor, schemaContext);
36     this.transaction = transaction;
37
38   }
39
40   public ShardReadTransaction(DOMStoreTransactionChain transactionChain, DOMStoreReadTransaction transaction, ActorRef shardActor, SchemaContext schemaContext) {
41     super(transactionChain, shardActor, schemaContext);
42     this.transaction = transaction;
43   }
44
45   @Override
46   public void handleReceive(Object message) throws Exception {
47     if (ReadData.SERIALIZABLE_CLASS.equals(message.getClass())) {
48         readData(transaction, ReadData.fromSerializable(message));
49     } else if(DataExists.SERIALIZABLE_CLASS.equals(message.getClass())) {
50         dataExists(transaction, DataExists.fromSerializable(message));
51     } else {
52       super.handleReceive(message);
53     }
54   }
55   protected void closeTransaction(CloseTransaction message) {
56     transaction.close();
57     getSender().tell(new CloseTransactionReply().toSerializable(), getSelf());
58     getSelf().tell(PoisonPill.getInstance(), getSelf());
59   }
60
61   //default scope test method to check if we get correct exception
62   void forUnitTestOnlyExplicitTransactionClose(){
63       transaction.close();
64   }
65
66 }