import javax.annotation.concurrent.GuardedBy;
import javax.annotation.concurrent.NotThreadSafe;
import org.opendaylight.controller.cluster.access.client.ConnectionEntry;
+import org.opendaylight.controller.cluster.access.commands.AbstractLocalTransactionRequest;
import org.opendaylight.controller.cluster.access.commands.TransactionAbortRequest;
import org.opendaylight.controller.cluster.access.commands.TransactionAbortSuccess;
import org.opendaylight.controller.cluster.access.commands.TransactionCanCommitSuccess;
if (t instanceof TransactionAbortSuccess) {
ret.voteYes();
} else if (t instanceof RequestFailure) {
- ret.voteNo(((RequestFailure<?, ?>) t).getCause());
+ ret.voteNo(((RequestFailure<?, ?>) t).getCause().unwrap());
} else {
ret.voteNo(new IllegalStateException("Unhandled response " + t.getClass()));
}
if (t instanceof TransactionCommitSuccess) {
ret.set(Boolean.TRUE);
} else if (t instanceof RequestFailure) {
- ret.setException(((RequestFailure<?, ?>) t).getCause());
+ ret.setException(((RequestFailure<?, ?>) t).getCause().unwrap());
} else {
ret.setException(new IllegalStateException("Unhandled response " + t.getClass()));
}
if (t instanceof TransactionCanCommitSuccess) {
ret.voteYes();
} else if (t instanceof RequestFailure) {
- ret.voteNo(((RequestFailure<?, ?>) t).getCause());
+ ret.voteNo(((RequestFailure<?, ?>) t).getCause().unwrap());
} else {
ret.voteNo(new IllegalStateException("Unhandled response " + t.getClass()));
}
if (t instanceof TransactionPreCommitSuccess) {
ret.voteYes();
} else if (t instanceof RequestFailure) {
- ret.voteNo(((RequestFailure<?, ?>) t).getCause());
+ ret.voteNo(((RequestFailure<?, ?>) t).getCause().unwrap());
} else {
ret.voteNo(new IllegalStateException("Unhandled response " + t.getClass()));
}
if (t instanceof TransactionCommitSuccess) {
ret.voteYes();
} else if (t instanceof RequestFailure) {
- ret.voteNo(((RequestFailure<?, ?>) t).getCause());
+ ret.voteNo(((RequestFailure<?, ?>) t).getCause().unwrap());
} else {
ret.voteNo(new IllegalStateException("Unhandled response " + t.getClass()));
}
});
}
- private void purge() {
+ void purge() {
successfulRequests.clear();
final TransactionRequest<?> req = new TransactionPurgeRequest(getIdentifier(), nextSequence(), localActor());
for (Object obj : successfulRequests) {
if (obj instanceof TransactionRequest) {
LOG.debug("Forwarding successful request {} to successor {}", obj, successor);
- successor.handleForwardedRemoteRequest((TransactionRequest<?>) obj, null);
+ successor.replay((TransactionRequest<?>) obj, response -> { });
} else {
Verify.verify(obj instanceof IncrementSequence);
successor.incrementSequence(((IncrementSequence) obj).getDelta());
if (getIdentifier().equals(req.getTarget())) {
Verify.verify(req instanceof TransactionRequest, "Unhandled request %s", req);
- LOG.debug("Forwarding queued request{} to successor {}", req, successor);
- successor.handleForwardedRemoteRequest((TransactionRequest<?>) req, e.getCallback());
+ LOG.debug("Forwarding queued request {} to successor {}", req, successor);
+ successor.replay((TransactionRequest<?>) req, e.getCallback());
it.remove();
}
}
}
}
+ /**
+ * Invoked from {@link #replayMessages(AbstractProxyTransaction, Iterable)} to have successor adopt an in-flight
+ * request.
+ *
+ * <p>
+ * Note: this method is invoked by the predecessor on the successor.
+ *
+ * @param request Request which needs to be forwarded
+ * @param callback Callback to be invoked once the request completes
+ */
+ private void replay(TransactionRequest<?> request, Consumer<Response<?, ?>> callback) {
+ if (request instanceof AbstractLocalTransactionRequest) {
+ handleForwardedLocalRequest((AbstractLocalTransactionRequest<?>) request, callback);
+ } else {
+ handleForwardedRemoteRequest(request, callback);
+ }
+ }
+
// Called with the connection locked
final void finishReconnect() {
final SuccessorState local = getSuccessorState();
* @param request Request to be forwarded
* @param callback Original callback
*/
- final void replayRequest(final TransactionRequest<?> request, final Consumer<Response<?, ?>> callback) {
+ final void forwardRequest(final TransactionRequest<?> request, final Consumer<Response<?, ?>> callback) {
final AbstractProxyTransaction successor = getSuccessorState().getSuccessor();
if (successor instanceof LocalProxyTransaction) {
abstract TransactionRequest<?> commitRequest(boolean coordinated);
/**
- * Invoked from {@link RemoteProxyTransaction} when it replays its successful requests to its successor. There is
- * no equivalent of this call from {@link LocalProxyTransaction} because it does not send a request until all
- * operations are packaged in the message.
+ * Replay a request originating in this proxy to a successor remote proxy.
+ */
+ abstract void forwardToRemote(RemoteProxyTransaction successor, TransactionRequest<?> request,
+ Consumer<Response<?, ?>> callback);
+
+ /**
+ * Replay a request originating in this proxy to a successor local proxy.
+ */
+ abstract void forwardToLocal(LocalProxyTransaction successor, TransactionRequest<?> request,
+ Consumer<Response<?, ?>> callback);
+
+ /**
+ * Invoked from {@link LocalProxyTransaction} when it replays its successful requests to its successor.
*
* <p>
* Note: this method is invoked by the predecessor on the successor.
* @param request Request which needs to be forwarded
* @param callback Callback to be invoked once the request completes
*/
- abstract void handleForwardedRemoteRequest(TransactionRequest<?> request,
+ abstract void handleForwardedLocalRequest(AbstractLocalTransactionRequest<?> request,
@Nullable Consumer<Response<?, ?>> callback);
/**
- * Replay a request originating in this proxy to a successor remote proxy.
- */
- abstract void forwardToRemote(RemoteProxyTransaction successor, TransactionRequest<?> request,
- Consumer<Response<?, ?>> callback);
-
- /**
- * Replay a request originating in this proxy to a successor local proxy.
+ * Invoked from {@link RemoteProxyTransaction} when it replays its successful requests to its successor.
+ *
+ * <p>
+ * Note: this method is invoked by the predecessor on the successor.
+ *
+ * @param request Request which needs to be forwarded
+ * @param callback Callback to be invoked once the request completes
*/
- abstract void forwardToLocal(LocalProxyTransaction successor, TransactionRequest<?> request,
- Consumer<Response<?, ?>> callback);
+ abstract void handleForwardedRemoteRequest(TransactionRequest<?> request,
+ @Nullable Consumer<Response<?, ?>> callback);
@Override
public final String toString() {