import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.SettableFuture;
-import org.opendaylight.controller.cluster.datastore.utils.ActorContext;
+import org.opendaylight.controller.cluster.datastore.identifiers.TransactionIdentifier;
import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction;
import org.opendaylight.controller.sal.core.spi.data.DOMStoreTransaction;
import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction;
*/
abstract class LocalTransactionContext extends AbstractTransactionContext {
private final DOMStoreTransaction txDelegate;
+ private final LocalTransactionReadySupport readySupport;
+ private Exception operationError;
- LocalTransactionContext(DOMStoreTransaction txDelegate, OperationLimiter limiter) {
- super(limiter);
+ LocalTransactionContext(DOMStoreTransaction txDelegate, TransactionIdentifier identifier,
+ LocalTransactionReadySupport readySupport) {
+ super(identifier);
this.txDelegate = Preconditions.checkNotNull(txDelegate);
+ this.readySupport = readySupport;
}
protected abstract DOMStoreWriteTransaction getWriteDelegate();
@Override
public void writeData(YangInstanceIdentifier path, NormalizedNode<?, ?> data) {
incrementModificationCount();
- getWriteDelegate().write(path, data);
- releaseOperation();
+ if(operationError == null) {
+ try {
+ getWriteDelegate().write(path, data);
+ } catch (Exception e) {
+ operationError = e;
+ }
+ }
+
}
@Override
public void mergeData(YangInstanceIdentifier path, NormalizedNode<?, ?> data) {
incrementModificationCount();
- getWriteDelegate().merge(path, data);
- releaseOperation();
+ if(operationError == null) {
+ try {
+ getWriteDelegate().merge(path, data);
+ } catch (Exception e) {
+ operationError = e;
+ }
+ }
}
@Override
public void deleteData(YangInstanceIdentifier path) {
incrementModificationCount();
- getWriteDelegate().delete(path);
- releaseOperation();
+ if(operationError == null) {
+ try {
+ getWriteDelegate().delete(path);
+ } catch (Exception e) {
+ operationError = e;
+ }
+ }
}
@Override
@Override
public void onSuccess(final Optional<NormalizedNode<?, ?>> result) {
proxyFuture.set(result);
- releaseOperation();
}
@Override
public void onFailure(final Throwable t) {
proxyFuture.setException(t);
- releaseOperation();
}
});
}
@Override
public void onSuccess(final Boolean result) {
proxyFuture.set(result);
- releaseOperation();
}
@Override
public void onFailure(final Throwable t) {
proxyFuture.setException(t);
- releaseOperation();
}
});
}
private LocalThreePhaseCommitCohort ready() {
logModificationCount();
- acquireOperation();
- return (LocalThreePhaseCommitCohort) getWriteDelegate().ready();
- }
-
- @SuppressWarnings({ "unchecked", "rawtypes" })
- private <T extends Future> T completeOperation(final ActorContext actorContext, final T operationFuture) {
- operationFuture.onComplete(getLimiter(), actorContext.getClientDispatcher());
- return operationFuture;
+ LocalThreePhaseCommitCohort cohort = readySupport.onTransactionReady(getWriteDelegate());
+ cohort.setOperationError(operationError);
+ return cohort;
}
@Override
public Future<ActorSelection> readyTransaction() {
final LocalThreePhaseCommitCohort cohort = ready();
- return completeOperation(cohort.getActorContext(), cohort.initiateCoordinatedCommit());
+ return cohort.initiateCoordinatedCommit();
}
@Override
public Future<Object> directCommit() {
final LocalThreePhaseCommitCohort cohort = ready();
- return completeOperation(cohort.getActorContext(), cohort.initiateDirectCommit());
+ return cohort.initiateDirectCommit();
}
@Override
@Override
public void closeTransaction() {
txDelegate.close();
- releaseOperation();
}
}