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.DeleteData;
20 import org.opendaylight.controller.cluster.datastore.messages.MergeData;
21 import org.opendaylight.controller.cluster.datastore.messages.ReadyTransaction;
22 import org.opendaylight.controller.cluster.datastore.messages.WriteData;
23 import org.opendaylight.controller.sal.core.spi.data.DOMStoreTransactionChain;
24 import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction;
25 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
31 public class ShardWriteTransaction extends ShardTransaction {
32 private final DOMStoreWriteTransaction transaction;
33 private final LoggingAdapter log =
34 Logging.getLogger(getContext().system(), this);
35 public ShardWriteTransaction(DOMStoreWriteTransaction transaction, ActorRef shardActor, SchemaContext schemaContext) {
36 super( shardActor, schemaContext);
37 this.transaction = transaction;
41 public ShardWriteTransaction(DOMStoreTransactionChain transactionChain, DOMStoreWriteTransaction transaction, ActorRef shardActor, SchemaContext schemaContext) {
42 super(transactionChain, shardActor, schemaContext);
43 this.transaction = transaction;
47 public void handleReceive(Object message) throws Exception {
48 if (WriteData.SERIALIZABLE_CLASS.equals(message.getClass())) {
49 writeData(transaction, WriteData.fromSerializable(message, schemaContext));
50 } else if (MergeData.SERIALIZABLE_CLASS.equals(message.getClass())) {
51 mergeData(transaction, MergeData.fromSerializable(message, schemaContext));
52 } else if (DeleteData.SERIALIZABLE_CLASS.equals(message.getClass())) {
53 deleteData(transaction,DeleteData.fromSerializable(message));
54 } else if (ReadyTransaction.SERIALIZABLE_CLASS.equals(message.getClass())) {
55 readyTransaction(transaction,new ReadyTransaction());
57 super.handleReceive(message);
61 protected void closeTransaction(CloseTransaction message) {
63 getSender().tell(new CloseTransactionReply().toSerializable(), getSelf());
64 getSelf().tell(PoisonPill.getInstance(), getSelf());
68 * The following method is used in unit testing only
69 * hence the default scope.
70 * This is done to test out failure cases.
72 public void forUnitTestOnlyExplicitTransactionClose() {