Example usage for io.netty.util.concurrent GenericFutureListener operationComplete

List of usage examples for io.netty.util.concurrent GenericFutureListener operationComplete

Introduction

In this page you can find the example usage for io.netty.util.concurrent GenericFutureListener operationComplete.

Prototype

void operationComplete(F future) throws Exception;

Source Link

Document

Invoked when the operation associated with the Future has been completed.

Usage

From source file:com.github.mrstampy.kitchensync.stream.StreamerFuture.java

License:Open Source License

/**
 * Notifies listeners and counts the latch down.
 *///from www. jav  a  2 s .  c  om
protected void finish() {
    for (GenericFutureListener<ChannelFuture> l : listeners) {
        try {
            l.operationComplete(this);
        } catch (Exception e) {
            log.error("Error notifying listener of completion", e);
        }
    }

    latch.countDown();
}

From source file:com.linecorp.armeria.client.circuitbreaker.CircuitBreakerRemoteInvokerTest.java

License:Apache License

@SuppressWarnings("unchecked")
private static <T> Future<T> mockFuture() {
    Future<T> future = (Future<T>) mock(Future.class);
    when(future.addListener(any())).then(invoc -> {
        GenericFutureListener<Future<T>> listener = invoc.getArgumentAt(0, GenericFutureListener.class);
        listener.operationComplete(future);
        return future;
    });//ww w.java2s .  c om
    return future;
}

From source file:com.linecorp.armeria.common.AbstractRequestContext.java

License:Apache License

private <T extends Future<?>> void invokeOperationComplete(GenericFutureListener<T> listener, T future)
        throws Exception {

    try (PushHandle ignored = propagateContextIfNotPresent()) {
        listener.operationComplete(future);
    }//from   ww w .j  a  v  a2  s .  c  om
}

From source file:com.linecorp.armeria.common.ServiceInvocationContext.java

License:Apache License

/**
 * Returns a {@link ChannelFutureListener} that makes sure the current invocation
 * context is set and then invokes the input {@code listener}.
 *///ww w. ja va  2  s .  c  o m
final <T extends Future<?>> GenericFutureListener<T> makeContextAware(GenericFutureListener<T> listener) {
    ServiceInvocationContext propagatedContext = this;
    return future -> {
        boolean mustResetContext = propagateContextIfNotPresent(propagatedContext);
        try {
            listener.operationComplete(future);
        } finally {
            if (mustResetContext) {
                resetContext(propagatedContext);
            }
        }
    };
}

From source file:com.linecorp.armeria.common.tracing.TracingTestBase.java

License:Apache License

@SuppressWarnings("unchecked")
public static <T> Future<T> mockFuture() {
    Future<T> future = (Future<T>) mock(Future.class);
    when(future.addListener(any())).then(invoc -> {
        GenericFutureListener<Future<T>> listener = invoc.getArgumentAt(0, GenericFutureListener.class);
        listener.operationComplete(future);
        return future;
    });/*from   w  w  w.j  ava 2  s . com*/
    return future;
}

From source file:com.linecorp.armeria.common.tracing.TracingTestBase.java

License:Apache License

@SuppressWarnings("unchecked")
public static <T> Promise<T> mockPromise() {
    Promise<T> promise = (Promise<T>) mock(Promise.class);
    when(promise.addListener(any())).then(invoc -> {
        GenericFutureListener<Future<T>> listener = invoc.getArgumentAt(0, GenericFutureListener.class);
        listener.operationComplete(promise);
        return promise;
    });/*w ww  . java2  s  . com*/
    return promise;
}

From source file:de.unipassau.isl.evs.ssh.app.activity.BoundFragment.java

License:Open Source License

/**
 * Wraps and returns a Listener that will, as soon as its operationComplete is called, call the operationComplete
 * of the given listener, but on the UI Thread.
 *///from  www . j  a v a 2  s  . c  o m
protected <T extends Future<?>> GenericFutureListener<T> listenerOnUiThread(
        final GenericFutureListener<T> listener) {
    final String tag = BoundFragment.this.getClass().getSimpleName();
    return new GenericFutureListener<T>() {
        @Override
        public void operationComplete(final T future) throws Exception {
            final FragmentActivity activity = getActivity();
            if (activity == null) {
                Log.i(tag, "Not calling listener " + listener + " of future " + future
                        + " as fragment is no longer attached.");
            } else {
                activity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            listener.operationComplete(future);
                        } catch (Exception e) {
                            Log.w(tag, "Listener for Future " + future + " threw an Exception", e);
                        }
                    }
                });
            }
        }
    };
}