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