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%2FTransactionChainProxy.java;h=b74c89d727c2a1761a7c993272abcab1e4ad9999;hp=c4ec760b40cd57d54579144f010b5e0f7425363e;hb=93bec87a3187c32ed3a2a684523b66db3b46645a;hpb=f0f107f9b889b728be457cf84289b53386d7d301 diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxy.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxy.java index c4ec760b40..b74c89d727 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxy.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxy.java @@ -8,46 +8,72 @@ package org.opendaylight.controller.cluster.datastore; +import akka.actor.ActorPath; +import akka.dispatch.Futures; +import org.opendaylight.controller.cluster.datastore.messages.CloseTransactionChain; import org.opendaylight.controller.cluster.datastore.utils.ActorContext; import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction; import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction; import org.opendaylight.controller.sal.core.spi.data.DOMStoreTransactionChain; import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import scala.concurrent.Await; +import scala.concurrent.Future; + +import java.util.Collections; +import java.util.List; /** * TransactionChainProxy acts as a proxy for a DOMStoreTransactionChain created on a remote shard */ public class TransactionChainProxy implements DOMStoreTransactionChain{ private final ActorContext actorContext; - private final SchemaContext schemaContext; + private final String transactionChainId; + private volatile List> cohortPathFutures = Collections.emptyList(); - public TransactionChainProxy(ActorContext actorContext, SchemaContext schemaContext) { + public TransactionChainProxy(ActorContext actorContext) { this.actorContext = actorContext; - this.schemaContext = schemaContext; + transactionChainId = actorContext.getCurrentMemberName() + "-" + System.currentTimeMillis(); } @Override public DOMStoreReadTransaction newReadOnlyTransaction() { return new TransactionProxy(actorContext, - TransactionProxy.TransactionType.READ_ONLY, schemaContext); + TransactionProxy.TransactionType.READ_ONLY, this); } @Override public DOMStoreReadWriteTransaction newReadWriteTransaction() { return new TransactionProxy(actorContext, - TransactionProxy.TransactionType.WRITE_ONLY, schemaContext); + TransactionProxy.TransactionType.READ_WRITE, this); } @Override public DOMStoreWriteTransaction newWriteOnlyTransaction() { return new TransactionProxy(actorContext, - TransactionProxy.TransactionType.READ_WRITE, schemaContext); + TransactionProxy.TransactionType.WRITE_ONLY, this); } @Override public void close() { - // FIXME : The problem here is don't know which shard the transaction chain is to be created on ??? - throw new UnsupportedOperationException("close - not sure what to do here?"); + // Send a close transaction chain request to each and every shard + actorContext.broadcast(new CloseTransactionChain(transactionChainId)); + } + + public String getTransactionChainId() { + return transactionChainId; + } + + public void onTransactionReady(List> cohortPathFutures){ + this.cohortPathFutures = cohortPathFutures; + } + + public void waitTillCurrentTransactionReady(){ + try { + Await.result(Futures + .sequence(this.cohortPathFutures, actorContext.getActorSystem().dispatcher()), + actorContext.getOperationDuration()); + } catch (Exception e) { + throw new IllegalStateException("Failed when waiting for transaction on a chain to become ready", e); + } } }