X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FShardTransactionChain.java;h=1092e9a793d82443b2bda82eeb81fbebb7360675;hp=79aaa86b28baaa71f161dceca0d56f59528d94a1;hb=996ab3e41386da6b27cf21f6464ef1e55363e1ca;hpb=f78020d87663c8d9db1e4e33939f7b8b703703f8 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 79aaa86b28..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,7 +10,6 @@ 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; @@ -22,33 +21,42 @@ import org.opendaylight.controller.sal.core.spi.data.DOMStoreTransactionChain; /** * The ShardTransactionChain Actor represents a remote TransactionChain */ -public class ShardTransactionChain extends UntypedActor{ - - private final DOMStoreTransactionChain chain; - - public ShardTransactionChain(DOMStoreTransactionChain chain) { - this.chain = chain; - } - - @Override - public void onReceive(Object message) throws Exception { - if(message instanceof CreateTransaction){ - DOMStoreReadWriteTransaction transaction = chain.newReadWriteTransaction(); - ActorRef transactionActor = getContext().actorOf(ShardTransaction.props(transaction, getContext().parent())); - getSender().tell(new CreateTransactionReply(transactionActor.path()), getSelf()); - } else if (message instanceof CloseTransactionChain){ - chain.close(); - getSender().tell(new CloseTransactionChainReply(), getSelf()); +public class ShardTransactionChain extends AbstractUntypedActor { + + private final DOMStoreTransactionChain chain; + + public ShardTransactionChain(DOMStoreTransactionChain chain) { + this.chain = chain; } - } - public static Props props(final DOMStoreTransactionChain chain){ - return Props.create(new Creator(){ + @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 ShardTransactionChain create() throws Exception { - return new ShardTransactionChain(chain); - } - }); - } + 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() { + + @Override + public ShardTransactionChain create() throws Exception { + return new ShardTransactionChain(chain); + } + }); + } }