Search in sources :

Example 21 with Response

use of org.opendaylight.controller.cluster.access.concepts.Response 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;
    }
}
Also used : Response(org.opendaylight.controller.cluster.access.concepts.Response) ExistsTransactionRequest(org.opendaylight.controller.cluster.access.commands.ExistsTransactionRequest) Consumer(java.util.function.Consumer) ReadTransactionRequest(org.opendaylight.controller.cluster.access.commands.ReadTransactionRequest) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) ExistsTransactionSuccess(org.opendaylight.controller.cluster.access.commands.ExistsTransactionSuccess) ReadTransactionSuccess(org.opendaylight.controller.cluster.access.commands.ReadTransactionSuccess)

Aggregations

Response (org.opendaylight.controller.cluster.access.concepts.Response)21 Test (org.junit.Test)17 TransactionPurgeRequest (org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest)11 TransactionPurgeResponse (org.opendaylight.controller.cluster.access.commands.TransactionPurgeResponse)9 ModifyTransactionRequestBuilder (org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder)7 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)7 TestProbe (akka.testkit.TestProbe)5 ExistsTransactionRequest (org.opendaylight.controller.cluster.access.commands.ExistsTransactionRequest)5 ModifyTransactionRequest (org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest)5 ReadTransactionRequest (org.opendaylight.controller.cluster.access.commands.ReadTransactionRequest)5 RequestEnvelope (org.opendaylight.controller.cluster.access.concepts.RequestEnvelope)5 ExistsTransactionSuccess (org.opendaylight.controller.cluster.access.commands.ExistsTransactionSuccess)4 ReadTransactionSuccess (org.opendaylight.controller.cluster.access.commands.ReadTransactionSuccess)4 TransactionWrite (org.opendaylight.controller.cluster.access.commands.TransactionWrite)4 Consumer (java.util.function.Consumer)3 AbortLocalTransactionRequest (org.opendaylight.controller.cluster.access.commands.AbortLocalTransactionRequest)3 CommitLocalTransactionRequest (org.opendaylight.controller.cluster.access.commands.CommitLocalTransactionRequest)3 TransactionDelete (org.opendaylight.controller.cluster.access.commands.TransactionDelete)3 TransactionMerge (org.opendaylight.controller.cluster.access.commands.TransactionMerge)3 TransactionModification (org.opendaylight.controller.cluster.access.commands.TransactionModification)3