use of org.apache.flink.shaded.netty4.io.netty.bootstrap.Bootstrap in project tutorials-java by Artister.
the class HelloWorldClient method start.
public void start() {
EventLoopGroup group = new NioEventLoopGroup();
Bootstrap bootstrap = new Bootstrap();
bootstrap.group(group).channel(NioSocketChannel.class).handler(new ClientChannelInitializer());
try {
ChannelFuture future = bootstrap.connect(address, port).sync();
future.channel().closeFuture().sync();
} catch (Exception e) {
e.printStackTrace();
} finally {
group.shutdownGracefully();
}
}
use of org.apache.flink.shaded.netty4.io.netty.bootstrap.Bootstrap in project autobahn-java by crossbario.
the class NettyWebSocket method connect.
@Override
public void connect(ITransportHandler transportHandler, TransportOptions options) throws Exception {
if (options == null) {
if (mOptions == null) {
options = new TransportOptions();
} else {
options = new TransportOptions();
options.setAutoPingInterval(mOptions.getAutoPingInterval());
options.setAutoPingTimeout(mOptions.getAutoPingTimeout());
options.setMaxFramePayloadSize(mOptions.getMaxFramePayloadSize());
}
}
URI uri;
uri = new URI(mUri);
int port = validateURIAndGetPort(uri);
String scheme = uri.getScheme();
String host = uri.getHost();
final SslContext sslContext = getSSLContext(scheme);
WebSocketClientHandshaker handshaker = WebSocketClientHandshakerFactory.newHandshaker(uri, WebSocketVersion.V13, mSerializers, true, new DefaultHttpHeaders(), options.getMaxFramePayloadSize());
mHandler = new NettyWebSocketClientHandler(handshaker, this, transportHandler);
EventLoopGroup group = new NioEventLoopGroup();
Bootstrap bootstrap = new Bootstrap();
bootstrap.group(group);
bootstrap.channel(NioSocketChannel.class);
TransportOptions opt = options;
bootstrap.handler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline channelPipeline = ch.pipeline();
if (sslContext != null) {
channelPipeline.addLast(sslContext.newHandler(ch.alloc(), host, port));
}
channelPipeline.addLast(new HttpClientCodec(), new HttpObjectAggregator(8192), WebSocketClientCompressionHandler.INSTANCE, new IdleStateHandler(opt.getAutoPingInterval() + opt.getAutoPingTimeout(), opt.getAutoPingInterval(), 0, TimeUnit.SECONDS), mHandler);
}
});
mChannel = bootstrap.connect(uri.getHost(), port).sync().channel();
mHandler.getHandshakeFuture().sync();
}
use of org.apache.flink.shaded.netty4.io.netty.bootstrap.Bootstrap in project LogHub by fbacchella.
the class ClientFactory method getBootStrap.
@Override
public AbstractBootstrap<Bootstrap, Channel> getBootStrap() {
bootstrap = new Bootstrap();
bootstrap.channelFactory(getInstance());
return bootstrap;
}
use of org.apache.flink.shaded.netty4.io.netty.bootstrap.Bootstrap in project LogHub by fbacchella.
the class TestServer method testSimple.
@Test(timeout = 2000)
public void testSimple() throws InterruptedException {
Properties empty = new Properties(Collections.emptyMap());
BlockingQueue<Event> receiver = new ArrayBlockingQueue<>(1);
TesterReceiver r = new TesterReceiver(receiver, new Pipeline(Collections.emptyList(), "testone", null));
r.configure(empty);
final ChannelFuture[] sent = new ChannelFuture[1];
EventLoopGroup workerGroup = new DefaultEventLoopGroup();
Bootstrap b = new Bootstrap();
b.group(workerGroup);
b.channel(LocalChannel.class);
b.handler(new SimpleChannelInboundHandler<ByteBuf>() {
@Override
public void channelActive(ChannelHandlerContext ctx) {
sent[0] = ctx.writeAndFlush(Unpooled.copiedBuffer("Message\r\n", CharsetUtil.UTF_8));
}
@Override
protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) throws Exception {
}
});
// Start the client.
ChannelFuture f = b.connect(new LocalAddress(TestServer.class.getCanonicalName())).sync();
Thread.sleep(100);
sent[0].sync();
f.channel().close();
// Wait until the connection is closed.
f.channel().closeFuture().sync();
Event e = receiver.poll();
Assert.assertEquals("Message", e.get("message"));
}
use of org.apache.flink.shaded.netty4.io.netty.bootstrap.Bootstrap in project jim-framework by jiangmin168168.
the class RpcClientInvokerManager method connect.
public void connect() {
InetSocketAddress remotePeer = new InetSocketAddress(this.referenceConfig.getHost(), this.referenceConfig.getPort());
Bootstrap b = new Bootstrap();
b.group(eventLoopGroup).channel(NioSocketChannel.class).handler(new RpcClientInitializer()).option(ChannelOption.TCP_NODELAY, true).option(ChannelOption.CONNECT_TIMEOUT_MILLIS, (int) this.referenceConfig.getConnectTimeoutMillis());
ChannelFuture channelFuture = b.connect(remotePeer);
channelFuture.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(final ChannelFuture channelFuture) throws Exception {
if (channelFuture.isSuccess()) {
RpcClientInvoker handler = channelFuture.channel().pipeline().get(RpcClientInvoker.class);
addHandler(handler);
}
}
});
}
Aggregations