use of io.netty.channel.ChannelFuture in project redisson by redisson.
the class ConnectionWatchdog method reattachBlockingQueue.
private void reattachBlockingQueue(RedisConnection connection, final CommandData<?, ?> commandData) {
if (commandData == null || !commandData.isBlockingCommand() || commandData.getPromise().isDone()) {
return;
}
ChannelFuture future = connection.send(commandData);
future.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
if (!future.isSuccess()) {
log.error("Can't reconnect blocking queue to new connection. {}", commandData);
}
}
});
}
use of io.netty.channel.ChannelFuture in project redisson by redisson.
the class RedisClient method connectPubSubAsync.
public RFuture<RedisPubSubConnection> connectPubSubAsync() {
final RPromise<RedisPubSubConnection> f = new RedissonPromise<RedisPubSubConnection>();
ChannelFuture channelFuture = bootstrap.connect();
channelFuture.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(final ChannelFuture future) throws Exception {
if (future.isSuccess()) {
final RedisPubSubConnection c = new RedisPubSubConnection(RedisClient.this, future.channel());
bootstrap.group().execute(new Runnable() {
public void run() {
if (!f.trySuccess(c)) {
c.closeAsync();
}
}
});
} else {
bootstrap.group().execute(new Runnable() {
public void run() {
f.tryFailure(future.cause());
}
});
}
}
});
return f;
}
use of io.netty.channel.ChannelFuture in project vert.x by eclipse.
the class ProxyChannelProvider method connect.
@Override
public void connect(VertxInternal vertx, Bootstrap bootstrap, ProxyOptions options, String host, int port, Handler<Channel> channelInitializer, Handler<AsyncResult<Channel>> channelHandler) {
final String proxyHost = options.getHost();
final int proxyPort = options.getPort();
final String proxyUsername = options.getUsername();
final String proxyPassword = options.getPassword();
final ProxyType proxyType = options.getType();
vertx.resolveAddress(proxyHost, dnsRes -> {
if (dnsRes.succeeded()) {
InetAddress address = dnsRes.result();
InetSocketAddress proxyAddr = new InetSocketAddress(address, proxyPort);
ProxyHandler proxy;
switch(proxyType) {
default:
case HTTP:
proxy = proxyUsername != null && proxyPassword != null ? new HttpProxyHandler(proxyAddr, proxyUsername, proxyPassword) : new HttpProxyHandler(proxyAddr);
break;
case SOCKS5:
proxy = proxyUsername != null && proxyPassword != null ? new Socks5ProxyHandler(proxyAddr, proxyUsername, proxyPassword) : new Socks5ProxyHandler(proxyAddr);
break;
case SOCKS4:
proxy = proxyUsername != null ? new Socks4ProxyHandler(proxyAddr, proxyUsername) : new Socks4ProxyHandler(proxyAddr);
break;
}
bootstrap.resolver(NoopAddressResolverGroup.INSTANCE);
InetSocketAddress targetAddress = InetSocketAddress.createUnresolved(host, port);
bootstrap.handler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addFirst("proxy", proxy);
pipeline.addLast(new ChannelInboundHandlerAdapter() {
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
if (evt instanceof ProxyConnectionEvent) {
pipeline.remove(proxy);
pipeline.remove(this);
channelInitializer.handle(ch);
channelHandler.handle(Future.succeededFuture(ch));
}
ctx.fireUserEventTriggered(evt);
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
channelHandler.handle(Future.failedFuture(cause));
}
});
}
});
ChannelFuture future = bootstrap.connect(targetAddress);
future.addListener(res -> {
if (!res.isSuccess()) {
channelHandler.handle(Future.failedFuture(res.cause()));
}
});
} else {
channelHandler.handle(Future.failedFuture(dnsRes.cause()));
}
});
}
use of io.netty.channel.ChannelFuture in project vert.x by eclipse.
the class ChannelProvider method connect.
public void connect(VertxInternal vertx, Bootstrap bootstrap, ProxyOptions options, String host, int port, Handler<Channel> channelInitializer, Handler<AsyncResult<Channel>> channelHandler) {
bootstrap.resolver(vertx.nettyAddressResolverGroup());
bootstrap.handler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel channel) throws Exception {
channelInitializer.handle(channel);
}
});
ChannelFuture fut = bootstrap.connect(host, port);
fut.addListener(res -> {
if (res.isSuccess()) {
channelHandler.handle(Future.succeededFuture(fut.channel()));
} else {
channelHandler.handle(Future.failedFuture(res.cause()));
}
});
}
use of io.netty.channel.ChannelFuture in project vert.x by eclipse.
the class Http2ClientTest method testClearText.
private void testClearText(boolean upgrade) throws Exception {
ServerBootstrap bootstrap = createH2CServer((dec, enc) -> new Http2EventAdapter() {
@Override
public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int streamDependency, short weight, boolean exclusive, int padding, boolean endStream) throws Http2Exception {
enc.writeHeaders(ctx, streamId, new DefaultHttp2Headers().status("200"), 0, true, ctx.newPromise());
ctx.flush();
}
}, upgrade);
ChannelFuture s = bootstrap.bind(DEFAULT_HTTP_HOST, DEFAULT_HTTP_PORT).sync();
try {
client.close();
client = vertx.createHttpClient(clientOptions.setUseAlpn(false).setSsl(false).setHttp2ClearTextUpgrade(upgrade));
client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", resp -> {
assertEquals(HttpVersion.HTTP_2, resp.version());
testComplete();
}).exceptionHandler(this::fail).end();
await();
} finally {
s.channel().close().sync();
}
}
Aggregations