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%2FTransactionChainProxy.java;h=b74c89d727c2a1761a7c993272abcab1e4ad9999;hb=1b8f7c7beaed83797320686bebddd536637aed9a;hp=20a74e30dab07258b4a4122d56d0b7f6c7630f1d;hpb=8ad0b28e56c6d0a1ce5cef45fae22d6fdea7f976;p=controller.git 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 20a74e30da..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 @@ -1,31 +1,79 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + 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 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 String transactionChainId; + private volatile List> cohortPathFutures = Collections.emptyList(); + + public TransactionChainProxy(ActorContext actorContext) { + this.actorContext = actorContext; + transactionChainId = actorContext.getCurrentMemberName() + "-" + System.currentTimeMillis(); + } + @Override public DOMStoreReadTransaction newReadOnlyTransaction() { - throw new UnsupportedOperationException("newReadOnlyTransaction"); + return new TransactionProxy(actorContext, + TransactionProxy.TransactionType.READ_ONLY, this); } @Override public DOMStoreReadWriteTransaction newReadWriteTransaction() { - throw new UnsupportedOperationException("newReadWriteTransaction"); + return new TransactionProxy(actorContext, + TransactionProxy.TransactionType.READ_WRITE, this); } @Override public DOMStoreWriteTransaction newWriteOnlyTransaction() { - throw new UnsupportedOperationException("newWriteOnlyTransaction"); + return new TransactionProxy(actorContext, + TransactionProxy.TransactionType.WRITE_ONLY, this); } @Override public void close() { - throw new UnsupportedOperationException("close"); + // 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); + } } }