import akka.actor.ActorSelection;
import com.google.common.base.Optional;
-import com.google.common.util.concurrent.CheckedFuture;
-import com.google.common.util.concurrent.Futures;
-import java.util.concurrent.Semaphore;
+import com.google.common.util.concurrent.SettableFuture;
+import org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException;
import org.opendaylight.controller.cluster.datastore.identifiers.TransactionIdentifier;
+import org.opendaylight.controller.md.sal.common.api.data.DataStoreUnavailableException;
import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
private static final Logger LOG = LoggerFactory.getLogger(NoOpTransactionContext.class);
private final Throwable failure;
- private final Semaphore operationLimiter;
+ private final OperationLimiter operationLimiter;
- public NoOpTransactionContext(Throwable failure, TransactionIdentifier identifier, Semaphore operationLimiter) {
+ public NoOpTransactionContext(Throwable failure, TransactionIdentifier identifier, OperationLimiter operationLimiter) {
super(identifier);
this.failure = failure;
this.operationLimiter = operationLimiter;
@Override
public void closeTransaction() {
- LOG.debug("NoOpTransactionContext {} closeTransaction called", identifier);
+ LOG.debug("NoOpTransactionContext {} closeTransaction called", getIdentifier());
+ }
+
+ @Override
+ public boolean supportsDirectCommit() {
+ return true;
+ }
+
+ @Override
+ public Future<Object> directCommit() {
+ LOG.debug("Tx {} directCommit called, failure: {}", getIdentifier(), failure);
+ operationLimiter.release();
+ return akka.dispatch.Futures.failed(failure);
}
@Override
public Future<ActorSelection> readyTransaction() {
- LOG.debug("Tx {} readyTransaction called", identifier);
+ LOG.debug("Tx {} readyTransaction called, failure: {}", getIdentifier(), failure);
operationLimiter.release();
return akka.dispatch.Futures.failed(failure);
}
@Override
public void deleteData(YangInstanceIdentifier path) {
- LOG.debug("Tx {} deleteData called path = {}", identifier, path);
+ LOG.debug("Tx {} deleteData called path = {}", getIdentifier(), path);
operationLimiter.release();
}
@Override
public void mergeData(YangInstanceIdentifier path, NormalizedNode<?, ?> data) {
- LOG.debug("Tx {} mergeData called path = {}", identifier, path);
+ LOG.debug("Tx {} mergeData called path = {}", getIdentifier(), path);
operationLimiter.release();
}
@Override
public void writeData(YangInstanceIdentifier path, NormalizedNode<?, ?> data) {
- LOG.debug("Tx {} writeData called path = {}", identifier, path);
+ LOG.debug("Tx {} writeData called path = {}", getIdentifier(), path);
operationLimiter.release();
}
@Override
- public CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> readData(
- YangInstanceIdentifier path) {
- LOG.debug("Tx {} readData called path = {}", identifier, path);
+ public void readData(final YangInstanceIdentifier path, SettableFuture<Optional<NormalizedNode<?, ?>>> proxyFuture) {
+ LOG.debug("Tx {} readData called path = {}", getIdentifier(), path);
operationLimiter.release();
- return Futures.immediateFailedCheckedFuture(new ReadFailedException(
- "Error reading data for path " + path, failure));
+ Throwable t;
+ if(failure instanceof NoShardLeaderException) {
+ t = new DataStoreUnavailableException(failure.getMessage(), failure);
+ } else {
+ t = failure;
+ }
+ proxyFuture.setException(new ReadFailedException("Error reading data for path " + path, t));
}
@Override
- public CheckedFuture<Boolean, ReadFailedException> dataExists(
- YangInstanceIdentifier path) {
- LOG.debug("Tx {} dataExists called path = {}", identifier, path);
+ public void dataExists(YangInstanceIdentifier path, SettableFuture<Boolean> proxyFuture) {
+ LOG.debug("Tx {} dataExists called path = {}", getIdentifier(), path);
operationLimiter.release();
- return Futures.immediateFailedCheckedFuture(new ReadFailedException(
- "Error checking exists for path " + path, failure));
+ proxyFuture.setException(new ReadFailedException("Error checking exists for path " + path, failure));
}
-}
\ No newline at end of file
+}