3 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
11 package org.opendaylight.controller.cluster.datastore;
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.DeleteData;
21 import org.opendaylight.controller.cluster.datastore.messages.MergeData;
22 import org.opendaylight.controller.cluster.datastore.messages.ReadData;
23 import org.opendaylight.controller.cluster.datastore.messages.ReadyTransaction;
24 import org.opendaylight.controller.cluster.datastore.messages.WriteData;
25 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction;
26 import org.opendaylight.controller.sal.core.spi.data.DOMStoreTransactionChain;
27 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
33 public class ShardReadWriteTransaction extends ShardTransaction {
34 private final DOMStoreReadWriteTransaction transaction;
35 private final LoggingAdapter log =
36 Logging.getLogger(getContext().system(), this);
37 public ShardReadWriteTransaction(DOMStoreTransactionChain transactionChain, DOMStoreReadWriteTransaction transaction, ActorRef shardActor, SchemaContext schemaContext) {
38 super(transactionChain, shardActor, schemaContext);
39 this.transaction = transaction;
42 public ShardReadWriteTransaction(DOMStoreReadWriteTransaction transaction, ActorRef shardActor, SchemaContext schemaContext) {
43 super( shardActor, schemaContext);
44 this.transaction = transaction;
48 public void handleReceive(Object message) throws Exception {
49 if (ReadData.SERIALIZABLE_CLASS.equals(message.getClass())) {
50 readData(transaction,ReadData.fromSerializable(message));
51 }else if (WriteData.SERIALIZABLE_CLASS.equals(message.getClass())) {
52 writeData(transaction, WriteData.fromSerializable(message, schemaContext));
53 } else if (MergeData.SERIALIZABLE_CLASS.equals(message.getClass())) {
54 mergeData(transaction, MergeData.fromSerializable(message, schemaContext));
55 } else if (DeleteData.SERIALIZABLE_CLASS.equals(message.getClass())) {
56 deleteData(transaction,DeleteData.fromSerizalizable(message));
57 } else if (ReadyTransaction.SERIALIZABLE_CLASS.equals(message.getClass())) {
58 readyTransaction(transaction,new ReadyTransaction());
59 } else if(DataExists.SERIALIZABLE_CLASS.equals(message.getClass())) {
60 dataExists(transaction, DataExists.fromSerializable(message));
62 super.handleReceive(message);
66 protected void closeTransaction(CloseTransaction message) {
68 getSender().tell(new CloseTransactionReply().toSerializable(), getSelf());
69 getSelf().tell(PoisonPill.getInstance(), getSelf());
73 * The following method is used in unit testing only
74 * hence the default scope.
75 * This is done to test out failure cases.
77 public void forUnitTestOnlyExplicitTransactionClose() {