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.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;
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;
41 public ShardReadWriteTransaction(DOMStoreReadWriteTransaction transaction, ActorRef shardActor, SchemaContext schemaContext) {
42 super( shardActor, schemaContext);
43 this.transaction = transaction;
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());
59 super.handleReceive(message);
63 protected void closeTransaction(CloseTransaction message) {
65 getSender().tell(new CloseTransactionReply().toSerializable(), getSelf());
66 getSelf().tell(PoisonPill.getInstance(), getSelf());