X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FShardTransactionChain.java;h=1092e9a793d82443b2bda82eeb81fbebb7360675;hb=cbe83ca3074fa0182d4f079f528bb710a997ced7;hp=a42b51338bcfa952a6fd3cec0875a88f1fe04e14;hpb=eda0ef295a7c6aac904da33132885cd86bfcb855;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardTransactionChain.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardTransactionChain.java index a42b51338b..1092e9a793 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardTransactionChain.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardTransactionChain.java @@ -10,8 +10,9 @@ package org.opendaylight.controller.cluster.datastore; import akka.actor.ActorRef; import akka.actor.Props; -import akka.actor.UntypedActor; import akka.japi.Creator; +import org.opendaylight.controller.cluster.datastore.messages.CloseTransactionChain; +import org.opendaylight.controller.cluster.datastore.messages.CloseTransactionChainReply; import org.opendaylight.controller.cluster.datastore.messages.CreateTransaction; import org.opendaylight.controller.cluster.datastore.messages.CreateTransactionReply; import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction; @@ -20,30 +21,42 @@ import org.opendaylight.controller.sal.core.spi.data.DOMStoreTransactionChain; /** * The ShardTransactionChain Actor represents a remote TransactionChain */ -public class ShardTransactionChain extends UntypedActor{ +public class ShardTransactionChain extends AbstractUntypedActor { - private final DOMStoreTransactionChain chain; + private final DOMStoreTransactionChain chain; - public ShardTransactionChain(DOMStoreTransactionChain chain) { - this.chain = chain; - } + public ShardTransactionChain(DOMStoreTransactionChain chain) { + this.chain = chain; + } + + @Override + public void handleReceive(Object message) throws Exception { + if (message instanceof CreateTransaction) { + CreateTransaction createTransaction = (CreateTransaction) message; + createTransaction(createTransaction); + } else if (message instanceof CloseTransactionChain) { + chain.close(); + getSender().tell(new CloseTransactionChainReply(), getSelf()); + } + } - @Override - public void onReceive(Object message) throws Exception { - if(message instanceof CreateTransaction){ - DOMStoreReadWriteTransaction transaction = chain.newReadWriteTransaction(); - ActorRef transactionActor = getContext().actorOf(ShardTransaction.props(transaction)); - getSender().tell(new CreateTransactionReply(transactionActor.path()), getSelf()); + private void createTransaction(CreateTransaction createTransaction) { + DOMStoreReadWriteTransaction transaction = + chain.newReadWriteTransaction(); + ActorRef transactionActor = getContext().actorOf(ShardTransaction + .props(chain, transaction, getContext().parent()), "shard-" + createTransaction.getTransactionId()); + getSender() + .tell(new CreateTransactionReply(transactionActor.path(), createTransaction.getTransactionId()), + getSelf()); } - } - public static Props props(final DOMStoreTransactionChain chain){ - return Props.create(new Creator(){ + public static Props props(final DOMStoreTransactionChain chain) { + return Props.create(new Creator() { - @Override - public ShardTransactionChain create() throws Exception { - return new ShardTransactionChain(chain); - } - }); - } + @Override + public ShardTransactionChain create() throws Exception { + return new ShardTransactionChain(chain); + } + }); + } }