Search in sources :

Example 6 with ExistsTransactionRequest

use of org.opendaylight.controller.cluster.access.commands.ExistsTransactionRequest in project controller by opendaylight.

the class RemoteProxyTransactionTest method testForwardToRemoteModifyExists.

@Test
public void testForwardToRemoteModifyExists() throws Exception {
    final TestProbe probe = createProbe();
    final ExistsTransactionRequest request = new ExistsTransactionRequest(TRANSACTION_ID, 0L, probe.ref(), PATH_1, false);
    final ExistsTransactionRequest received = testForwardToRemote(request, ExistsTransactionRequest.class);
    Assert.assertEquals(request.getTarget(), received.getTarget());
    Assert.assertEquals(request.getPath(), received.getPath());
}
Also used : ExistsTransactionRequest(org.opendaylight.controller.cluster.access.commands.ExistsTransactionRequest) TestProbe(akka.testkit.TestProbe) Test(org.junit.Test)

Example 7 with ExistsTransactionRequest

use of org.opendaylight.controller.cluster.access.commands.ExistsTransactionRequest 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

ExistsTransactionRequest (org.opendaylight.controller.cluster.access.commands.ExistsTransactionRequest)7 ExistsTransactionSuccess (org.opendaylight.controller.cluster.access.commands.ExistsTransactionSuccess)5 Response (org.opendaylight.controller.cluster.access.concepts.Response)5 Test (org.junit.Test)4 ReadTransactionRequest (org.opendaylight.controller.cluster.access.commands.ReadTransactionRequest)4 TestProbe (akka.testkit.TestProbe)3 Consumer (java.util.function.Consumer)3 AbortLocalTransactionRequest (org.opendaylight.controller.cluster.access.commands.AbortLocalTransactionRequest)3 ModifyTransactionRequest (org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest)3 ReadTransactionSuccess (org.opendaylight.controller.cluster.access.commands.ReadTransactionSuccess)3 ReadFailedException (org.opendaylight.mdsal.common.api.ReadFailedException)3 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)3 Optional (com.google.common.base.Optional)2 CheckedFuture (com.google.common.util.concurrent.CheckedFuture)2 Futures (com.google.common.util.concurrent.Futures)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 SettableFuture (com.google.common.util.concurrent.SettableFuture)2 Nullable (javax.annotation.Nullable)2 AbstractLocalTransactionRequest (org.opendaylight.controller.cluster.access.commands.AbstractLocalTransactionRequest)2 AbstractReadTransactionRequest (org.opendaylight.controller.cluster.access.commands.AbstractReadTransactionRequest)2