use of org.apache.flink.shaded.netty4.io.netty.util.concurrent.GenericFutureListener in project vert.x by eclipse.
the class HttpServerWorker method handle.
@Override
public void handle(Channel ch) {
if (HAProxyMessageCompletionHandler.canUseProxyProtocol(options.isUseProxyProtocol())) {
IdleStateHandler idle;
io.netty.util.concurrent.Promise<Channel> p = ch.eventLoop().newPromise();
ch.pipeline().addLast(new HAProxyMessageDecoder());
if (options.getProxyProtocolTimeout() > 0) {
ch.pipeline().addLast("idle", idle = new IdleStateHandler(0, 0, options.getProxyProtocolTimeout(), options.getProxyProtocolTimeoutUnit()));
} else {
idle = null;
}
ch.pipeline().addLast(new HAProxyMessageCompletionHandler(p));
p.addListener((GenericFutureListener<Future<Channel>>) future -> {
if (future.isSuccess()) {
if (idle != null) {
ch.pipeline().remove(idle);
}
configurePipeline(future.getNow());
} else {
handleException(future.cause());
}
});
} else {
configurePipeline(ch);
}
}
use of org.apache.flink.shaded.netty4.io.netty.util.concurrent.GenericFutureListener in project riposte by Nike-Inc.
the class DTraceEndHandlerTest method endDtrace_completes_the_trace_using_ChannelFutureListener_if_state_is_not_null_and_isResponseSendingLastChunkSent_returns_true.
@Test
public void endDtrace_completes_the_trace_using_ChannelFutureListener_if_state_is_not_null_and_isResponseSendingLastChunkSent_returns_true() throws Exception {
// given
assertThat(state.isTraceCompletedOrScheduled(), is(false));
assertThat(state.isResponseSendingLastChunkSent(), is(true));
assertThat(state.getDistributedTraceStack(), nullValue());
Pair<Deque<Span>, Map<String, String>> expectedDtraceInfo = setupStateWithNewSpan("blahTrace");
assertThat(state.getDistributedTraceStack(), notNullValue());
assertThat(state.getDistributedTraceStack(), is(expectedDtraceInfo.getLeft()));
assertThat(state.getDistributedTraceStack().size(), is(1));
assertThat(state.isTracingResponseTaggingAndFinalSpanNameCompleted(), is(false));
Span expectedSpan = expectedDtraceInfo.getLeft().peek();
// when
handlerSpy.endDtrace(ctxMock);
// then
// completeCurrentSpan() not immediately called, but scheduled
verify(handlerSpy, never()).completeCurrentSpan();
assertThat(state.isTraceCompletedOrScheduled(), is(true));
// Response tagging was done.
assertThat(state.isTracingResponseTaggingAndFinalSpanNameCompleted(), is(true));
// Extract the listener that was attached to the last chunk future.
GenericFutureListener lastChunkListener = extractChannelFutureListenerAddedToLastChunkFuture();
assertThat(lastChunkListener, notNullValue());
assertThat(lastChunkListener, instanceOf(ChannelFutureListenerWithTracingAndMdc.class));
assertThat(Whitebox.getInternalState(lastChunkListener, "distributedTraceStackForExecution"), is(expectedDtraceInfo.getLeft()));
assertThat(Whitebox.getInternalState(lastChunkListener, "mdcContextMapForExecution"), is(expectedDtraceInfo.getRight()));
Consumer<ChannelFuture> embeddedListenerConsumer = (Consumer<ChannelFuture>) Whitebox.getInternalState(lastChunkListener, "postCompleteOperation");
// Execute the embedded listener so we can validate what it does. Note that we can't verify using mockito spy verify(),
// because the method call goes through the internal handler, not the spy impl. But we can still verify by
// setting up the Tracer state to what we expect, execute the embedded listener, and verify subsequent Tracer state.
AsyncNettyHelper.linkTracingAndMdcToCurrentThread(expectedDtraceInfo);
assertThat(Tracer.getInstance().getCurrentSpan(), is(expectedSpan));
embeddedListenerConsumer.accept(null);
assertThat(Tracer.getInstance().getCurrentSpan(), nullValue());
}
use of org.apache.flink.shaded.netty4.io.netty.util.concurrent.GenericFutureListener in project ambry by linkedin.
the class MultiplexedChannelRecord method acquireClaimedStream.
void acquireClaimedStream(Promise<Channel> promise) {
NettyUtils.doInEventLoop(parentChannel.eventLoop(), () -> {
if (state != RecordState.OPEN) {
String message;
// GOAWAY
if (state == RecordState.CLOSED_TO_NEW) {
message = String.format("Connection %s received GOAWAY with Last Stream ID %d. Unable to open new " + "streams on this connection.", parentChannel, lastStreamId);
} else {
message = String.format("Connection %s was closed while acquiring new stream.", parentChannel);
}
log.warn(message);
promise.setFailure(new IOException(message));
return;
}
Future<Http2StreamChannel> streamFuture = new Http2StreamChannelBootstrap(parentChannel).handler(streamChannelInitializer).open();
streamFuture.addListener((GenericFutureListener<Future<Http2StreamChannel>>) future -> {
NettyUtils.warnIfNotInEventLoop(parentChannel.eventLoop());
if (!future.isSuccess()) {
promise.setFailure(future.cause());
return;
}
Http2StreamChannel channel = future.getNow();
streamChannels.put(channel.id(), channel);
promise.setSuccess(channel);
if (closeIfIdleTask == null && allowedIdleTimeInMs != null && allowedIdleTimeInMs > 0) {
enableCloseIfIdleTask();
}
});
}, promise);
}
use of org.apache.flink.shaded.netty4.io.netty.util.concurrent.GenericFutureListener in project netty by netty.
the class Http2ConnectionHandlerTest method canSendGoAwayFrame.
@SuppressWarnings("unchecked")
@Test
public void canSendGoAwayFrame() throws Exception {
ByteBuf data = dummyData();
long errorCode = Http2Error.INTERNAL_ERROR.code();
when(future.isDone()).thenReturn(true);
when(future.isSuccess()).thenReturn(true);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
((GenericFutureListener) invocation.getArgument(0)).operationComplete(future);
return null;
}
}).when(future).addListener(any(GenericFutureListener.class));
handler = newHandler();
handler.goAway(ctx, STREAM_ID, errorCode, data, promise);
verify(connection).goAwaySent(eq(STREAM_ID), eq(errorCode), eq(data));
verify(frameWriter).writeGoAway(eq(ctx), eq(STREAM_ID), eq(errorCode), eq(data), eq(promise));
verify(ctx).close();
assertEquals(0, data.refCnt());
}
use of org.apache.flink.shaded.netty4.io.netty.util.concurrent.GenericFutureListener in project netty by netty.
the class FixedChannelPoolTest method testCloseAsync.
@Test
public void testCloseAsync() throws ExecutionException, InterruptedException {
LocalAddress addr = new LocalAddress(getLocalAddrId());
Bootstrap cb = new Bootstrap();
cb.remoteAddress(addr);
cb.group(group).channel(LocalChannel.class);
ServerBootstrap sb = new ServerBootstrap();
sb.group(group).channel(LocalServerChannel.class).childHandler(new ChannelInitializer<LocalChannel>() {
@Override
public void initChannel(LocalChannel ch) throws Exception {
ch.pipeline().addLast(new ChannelInboundHandlerAdapter());
}
});
// Start server
final Channel sc = sb.bind(addr).syncUninterruptibly().channel();
final FixedChannelPool pool = new FixedChannelPool(cb, new TestChannelPoolHandler(), 2);
pool.acquire().get();
pool.acquire().get();
final ChannelPromise closePromise = sc.newPromise();
pool.closeAsync().addListener(new GenericFutureListener<Future<? super Void>>() {
@Override
public void operationComplete(Future<? super Void> future) throws Exception {
assertEquals(0, pool.acquiredChannelCount());
sc.close(closePromise).syncUninterruptibly();
}
}).awaitUninterruptibly();
closePromise.awaitUninterruptibly();
}
Aggregations