use of org.opendaylight.controller.cluster.access.commands.ReadTransactionRequest in project controller by opendaylight.
the class RemoteProxyTransaction method handleForwardedRequest.
void handleForwardedRequest(final TransactionRequest<?> request, final Consumer<Response<?, ?>> callback) {
if (request instanceof ModifyTransactionRequest) {
handleForwardedModifyTransactionRequest(callback, (ModifyTransactionRequest) request);
} else if (request instanceof ReadTransactionRequest) {
ensureFlushedBuider();
sendRequest(new ReadTransactionRequest(getIdentifier(), nextSequence(), localActor(), ((ReadTransactionRequest) request).getPath(), isSnapshotOnly()), resp -> {
recordFinishedRequest(resp);
callback.accept(resp);
});
} else if (request instanceof ExistsTransactionRequest) {
ensureFlushedBuider();
sendRequest(new ExistsTransactionRequest(getIdentifier(), nextSequence(), localActor(), ((ExistsTransactionRequest) request).getPath(), isSnapshotOnly()), resp -> {
recordFinishedRequest(resp);
callback.accept(resp);
});
} else if (request instanceof TransactionPreCommitRequest) {
ensureFlushedBuider();
final TransactionRequest<?> tmp = new TransactionPreCommitRequest(getIdentifier(), nextSequence(), localActor());
sendRequest(tmp, resp -> {
recordSuccessfulRequest(tmp);
callback.accept(resp);
});
} else if (request instanceof TransactionDoCommitRequest) {
ensureFlushedBuider();
sendRequest(new TransactionDoCommitRequest(getIdentifier(), nextSequence(), localActor()), callback);
} else if (request instanceof TransactionAbortRequest) {
ensureFlushedBuider();
sendDoAbort(callback);
} else if (request instanceof TransactionPurgeRequest) {
enqueuePurge(callback);
} else {
throw new IllegalArgumentException("Unhandled request {}" + request);
}
}
use of org.opendaylight.controller.cluster.access.commands.ReadTransactionRequest in project controller by opendaylight.
the class RemoteProxyTransactionTest method testRead.
@Override
@Test
public void testRead() throws Exception {
final TransactionTester<RemoteProxyTransaction> tester = getTester();
final CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read = transaction.read(PATH_2);
final ReadTransactionRequest req = tester.expectTransactionRequest(ReadTransactionRequest.class);
final Optional<NormalizedNode<?, ?>> result = Optional.of(DATA_1);
tester.replySuccess(new ReadTransactionSuccess(TRANSACTION_ID, req.getSequence(), result));
assertFutureEquals(result, read);
}
use of org.opendaylight.controller.cluster.access.commands.ReadTransactionRequest in project controller by opendaylight.
the class FrontendReadWriteTransactionTest method testReadAfterAbort.
@Test(expected = IllegalStateException.class)
public void testReadAfterAbort() throws RequestException {
final ModifyTransactionRequestBuilder b = new ModifyTransactionRequestBuilder(TX_ID, mock(ActorRef.class));
b.setSequence(0);
b.setAbort();
final TransactionRequest<?> abortReq = b.build();
assertNull(handleRequest(abortReq));
verify(mockParent).abortTransaction(same(shardTransaction), any(Runnable.class));
handleRequest(new ReadTransactionRequest(TX_ID, 0, mock(ActorRef.class), YangInstanceIdentifier.EMPTY, true));
}
use of org.opendaylight.controller.cluster.access.commands.ReadTransactionRequest in project controller by opendaylight.
the class LocalProxyTransaction method handleReadRequest.
private boolean handleReadRequest(final TransactionRequest<?> request, @Nullable final Consumer<Response<?, ?>> callback) {
// listeners, which we do not want to execute while we are reconnecting.
if (request instanceof ReadTransactionRequest) {
final YangInstanceIdentifier path = ((ReadTransactionRequest) request).getPath();
final Optional<NormalizedNode<?, ?>> result = Optional.fromJavaUtil(readOnlyView().readNode(path));
if (callback != null) {
// XXX: FB does not see that callback is final, on stack and has be check for non-null.
final Consumer<Response<?, ?>> fbIsStupid = Preconditions.checkNotNull(callback);
executeInActor(() -> fbIsStupid.accept(new ReadTransactionSuccess(request.getTarget(), request.getSequence(), result)));
}
return true;
} else if (request instanceof ExistsTransactionRequest) {
final YangInstanceIdentifier path = ((ExistsTransactionRequest) request).getPath();
final boolean result = readOnlyView().readNode(path).isPresent();
if (callback != null) {
// XXX: FB does not see that callback is final, on stack and has be check for non-null.
final Consumer<Response<?, ?>> fbIsStupid = Preconditions.checkNotNull(callback);
executeInActor(() -> fbIsStupid.accept(new ExistsTransactionSuccess(request.getTarget(), request.getSequence(), result)));
}
return true;
} else {
return false;
}
}
Aggregations