use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelFuture in project vert.x by eclipse.
the class Http2ServerTest method testHandlerFailure.
private void testHandlerFailure(boolean data, BiConsumer<RuntimeException, HttpServer> configurator) throws Exception {
RuntimeException failure = new RuntimeException();
io.vertx.core.http.Http2Settings settings = TestUtils.randomHttp2Settings();
server.close();
server = vertx.createHttpServer(serverOptions.setInitialSettings(settings));
configurator.accept(failure, server);
Context ctx = vertx.getOrCreateContext();
ctx.exceptionHandler(err -> {
assertSame(err, failure);
testComplete();
});
startServer(ctx);
TestClient client = new TestClient();
ChannelFuture fut = client.connect(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, request -> {
int id = request.nextStreamId();
request.encoder.writeHeaders(request.context, id, GET("/"), 0, !data, request.context.newPromise());
if (data) {
request.encoder.writeData(request.context, id, Buffer.buffer("hello").getByteBuf(), 0, true, request.context.newPromise());
}
});
fut.sync();
await();
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelFuture in project vert.x by eclipse.
the class Http2ServerTest method testShutdownOverride.
@Test
public void testShutdownOverride() throws Exception {
AtomicLong shutdown = new AtomicLong();
Handler<HttpServerRequest> requestHandler = req -> {
HttpConnection conn = req.connection();
shutdown.set(System.currentTimeMillis());
conn.shutdown(10000);
vertx.setTimer(300, v -> {
conn.shutdown(300);
});
};
server.requestHandler(requestHandler);
startServer();
TestClient client = new TestClient();
ChannelFuture fut = client.connect(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, request -> {
request.channel.closeFuture().addListener(v1 -> {
vertx.runOnContext(v2 -> {
assertTrue(shutdown.get() - System.currentTimeMillis() < 1200);
testComplete();
});
});
Http2ConnectionEncoder encoder = request.encoder;
int id = request.nextStreamId();
encoder.writeHeaders(request.context, id, GET("/"), 0, true, request.context.newPromise());
request.context.flush();
});
fut.sync();
await();
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelFuture in project vert.x by eclipse.
the class Http2ServerTest method testServerSendGoAway.
private void testServerSendGoAway(Handler<HttpServerRequest> requestHandler, int expectedError) throws Exception {
server.requestHandler(requestHandler);
startServer();
TestClient client = new TestClient();
ChannelFuture fut = client.connect(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, request -> {
request.decoder.frameListener(new Http2EventAdapter() {
@Override
public void onGoAwayRead(ChannelHandlerContext ctx, int lastStreamId, long errorCode, ByteBuf debugData) throws Http2Exception {
vertx.runOnContext(v -> {
assertEquals(expectedError, errorCode);
complete();
});
}
});
Http2ConnectionEncoder encoder = request.encoder;
int id1 = request.nextStreamId();
encoder.writeHeaders(request.context, id1, GET("/"), 0, true, request.context.newPromise());
int id2 = request.nextStreamId();
encoder.writeHeaders(request.context, id2, GET("/"), 0, true, request.context.newPromise());
request.context.flush();
});
fut.sync();
await();
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelFuture in project hbase by apache.
the class FanOutOneBlockAsyncDFSOutputHelper method connectToDataNodes.
private static List<Future<Channel>> connectToDataNodes(Configuration conf, DFSClient client, String clientName, LocatedBlock locatedBlock, long maxBytesRcvd, long latestGS, BlockConstructionStage stage, DataChecksum summer, EventLoop eventLoop) {
Enum<?>[] storageTypes = locatedBlock.getStorageTypes();
DatanodeInfo[] datanodeInfos = locatedBlock.getLocations();
boolean connectToDnViaHostname = conf.getBoolean(DFS_CLIENT_USE_DN_HOSTNAME, DFS_CLIENT_USE_DN_HOSTNAME_DEFAULT);
int timeoutMs = conf.getInt(DFS_CLIENT_SOCKET_TIMEOUT_KEY, READ_TIMEOUT);
ExtendedBlock blockCopy = new ExtendedBlock(locatedBlock.getBlock());
blockCopy.setNumBytes(locatedBlock.getBlockSize());
ClientOperationHeaderProto header = ClientOperationHeaderProto.newBuilder().setBaseHeader(BaseHeaderProto.newBuilder().setBlock(PB_HELPER.convert(blockCopy)).setToken(PB_HELPER.convert(locatedBlock.getBlockToken()))).setClientName(clientName).build();
ChecksumProto checksumProto = DataTransferProtoUtil.toProto(summer);
OpWriteBlockProto.Builder writeBlockProtoBuilder = OpWriteBlockProto.newBuilder().setHeader(header).setStage(OpWriteBlockProto.BlockConstructionStage.valueOf(stage.name())).setPipelineSize(1).setMinBytesRcvd(locatedBlock.getBlock().getNumBytes()).setMaxBytesRcvd(maxBytesRcvd).setLatestGenerationStamp(latestGS).setRequestedChecksum(checksumProto).setCachingStrategy(CachingStrategyProto.newBuilder().setDropBehind(true).build());
List<Future<Channel>> futureList = new ArrayList<>(datanodeInfos.length);
for (int i = 0; i < datanodeInfos.length; i++) {
DatanodeInfo dnInfo = datanodeInfos[i];
Enum<?> storageType = storageTypes[i];
Promise<Channel> promise = eventLoop.newPromise();
futureList.add(promise);
String dnAddr = dnInfo.getXferAddr(connectToDnViaHostname);
new Bootstrap().group(eventLoop).channel(NioSocketChannel.class).option(CONNECT_TIMEOUT_MILLIS, timeoutMs).handler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
// we need to get the remote address of the channel so we can only move on after
// channel connected. Leave an empty implementation here because netty does not allow
// a null handler.
}
}).connect(NetUtils.createSocketAddr(dnAddr)).addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
if (future.isSuccess()) {
initialize(conf, future.channel(), dnInfo, storageType, writeBlockProtoBuilder, timeoutMs, client, locatedBlock.getBlockToken(), promise);
} else {
promise.tryFailure(future.cause());
}
}
});
}
return futureList;
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelFuture in project pinot by linkedin.
the class NettyTCPClientConnection method connect.
/**
* Open a connection
*/
@Override
public boolean connect() {
try {
checkTransition(State.CONNECTED);
//Connect synchronously. At the end of this line, _channel should have been set
TimerContext t = MetricsHelper.startTimer();
ChannelFuture f = _bootstrap.connect(_server.getHostname(), _server.getPort()).sync();
/**
* Waiting for future alone does not guarantee that _channel is set. _channel is set
* only when the channelActive() async callback runs. So we should also wait for it.
*/
f.get();
_channelSet.await();
t.stop();
_connState = State.CONNECTED;
_clientMetric.addConnectStats(t.getLatencyMs());
return true;
} catch (Exception ie) {
if (ie instanceof ConnectException && ie.getMessage() != null && ie.getMessage().startsWith("Connection refused")) {
// Most common case when a server is down. Don't print the entire stack and fill the logs.
LOGGER.error("Could not connect to server {}:{} connId:{}", _server, ie.getMessage(), getConnId());
} else {
LOGGER.error("Got exception when connecting to server {} connId {}", _server, ie, getConnId());
}
}
return false;
}
Aggregations