use of org.apache.flink.shaded.netty4.io.netty.channel.nio.NioEventLoopGroup in project carbondata by apache.
the class DictionaryClient method startClient.
/**
* start dictionary client
*
* @param address
* @param port
*/
public void startClient(String address, int port) {
LOGGER.audit("Starting client on " + address + " " + port);
long start = System.currentTimeMillis();
// Create an Event with 1 thread.
workerGroup = new NioEventLoopGroup(1);
Bootstrap clientBootstrap = new Bootstrap();
clientBootstrap.group(workerGroup).channel(NioSocketChannel.class).handler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
// Based on length provided at header, it collects all packets
pipeline.addLast("LengthDecoder", new LengthFieldBasedFrameDecoder(1048576, 0, 2, 0, 2));
pipeline.addLast("DictionaryClientHandler", dictionaryClientHandler);
}
});
clientBootstrap.connect(new InetSocketAddress(address, port));
LOGGER.info("Dictionary client Started, Total time spent : " + (System.currentTimeMillis() - start));
}
use of org.apache.flink.shaded.netty4.io.netty.channel.nio.NioEventLoopGroup in project intellij-community by JetBrains.
the class ExternalJavacManager method start.
public void start(int listenPort) {
final ServerBootstrap bootstrap = new ServerBootstrap().group(new NioEventLoopGroup(1, SharedThreadPool.getInstance())).channel(NioServerSocketChannel.class);
bootstrap.childOption(ChannelOption.TCP_NODELAY, true).childOption(ChannelOption.SO_KEEPALIVE, true);
final ChannelHandler compilationRequestsHandler = new CompilationRequestsHandler();
bootstrap.childHandler(new ChannelInitializer() {
@Override
protected void initChannel(Channel channel) throws Exception {
channel.pipeline().addLast(myChannelRegistrar, new ProtobufVarint32FrameDecoder(), new ProtobufDecoder(JavacRemoteProto.Message.getDefaultInstance()), new ProtobufVarint32LengthFieldPrepender(), new ProtobufEncoder(), compilationRequestsHandler);
}
});
try {
final InetAddress loopback = InetAddress.getByName(null);
myChannelRegistrar.add(bootstrap.bind(loopback, listenPort).syncUninterruptibly().channel());
myListenPort = listenPort;
} catch (UnknownHostException e) {
throw new RuntimeException(e);
}
}
use of org.apache.flink.shaded.netty4.io.netty.channel.nio.NioEventLoopGroup in project apn-proxy by apn-proxy.
the class ApnProxyServer method start.
public void start() {
int bossThreadCount = ApnProxyConfig.getConfig().getBossThreadCount();
int workerThreadCount = ApnProxyConfig.getConfig().getWorkerThreadCount();
int port = ApnProxyConfig.getConfig().getPort();
LoggerUtil.info(logger, "ApnProxy Server Listen on: " + port);
ServerBootstrap serverBootStrap = new ServerBootstrap();
serverBootStrap.childOption(ChannelOption.ALLOCATOR, UnpooledByteBufAllocator.DEFAULT);
bossGroup = new NioEventLoopGroup(bossThreadCount);
workerGroup = new NioEventLoopGroup(workerThreadCount);
try {
serverBootStrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).localAddress(port).childHandler(new ApnProxyServerChannelInitializer());
serverBootStrap.bind().sync().channel().closeFuture().sync();
} catch (Exception e) {
logger.error(e.getMessage(), e);
} finally {
logger.error("showdown the server");
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
}
use of org.apache.flink.shaded.netty4.io.netty.channel.nio.NioEventLoopGroup in project apn-proxy by apn-proxy.
the class HttpServer method main.
public static void main(String[] args) {
ServerBootstrap serverBootStrap = new ServerBootstrap();
serverBootStrap.childOption(ChannelOption.ALLOCATOR, UnpooledByteBufAllocator.DEFAULT);
try {
serverBootStrap.group(new NioEventLoopGroup(1), new NioEventLoopGroup(2)).channel(NioServerSocketChannel.class).localAddress(5000).childHandler(new HttpServerChannelInitializer());
serverBootStrap.bind().sync().channel().closeFuture().sync();
} catch (Exception e) {
e.printStackTrace();
} finally {
}
}
use of org.apache.flink.shaded.netty4.io.netty.channel.nio.NioEventLoopGroup in project netty by netty.
the class SslHandlerTest method testAlertProducedAndSend.
private void testAlertProducedAndSend(SslProvider provider) throws Exception {
SelfSignedCertificate ssc = new SelfSignedCertificate();
final SslContext sslServerCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).sslProvider(provider).trustManager(new SimpleTrustManagerFactory() {
@Override
protected void engineInit(KeyStore keyStore) {
}
@Override
protected void engineInit(ManagerFactoryParameters managerFactoryParameters) {
}
@Override
protected TrustManager[] engineGetTrustManagers() {
return new TrustManager[] { new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
// Fail verification which should produce an alert that is send back to the client.
throw new CertificateException();
}
@Override
public void checkServerTrusted(X509Certificate[] x509Certificates, String s) {
// NOOP
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return EmptyArrays.EMPTY_X509_CERTIFICATES;
}
} };
}
}).clientAuth(ClientAuth.REQUIRE).build();
final SslContext sslClientCtx = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).keyManager(new File(getClass().getResource("test.crt").getFile()), new File(getClass().getResource("test_unencrypted.pem").getFile())).sslProvider(provider).build();
NioEventLoopGroup group = new NioEventLoopGroup();
Channel sc = null;
Channel cc = null;
try {
final Promise<Void> promise = group.next().newPromise();
sc = new ServerBootstrap().group(group).channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
ch.pipeline().addLast(sslServerCtx.newHandler(ch.alloc()));
ch.pipeline().addLast(new ChannelInboundHandlerAdapter() {
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
// Just trigger a close
ctx.close();
}
});
}
}).bind(new InetSocketAddress(0)).syncUninterruptibly().channel();
cc = new Bootstrap().group(group).channel(NioSocketChannel.class).handler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
ch.pipeline().addLast(sslClientCtx.newHandler(ch.alloc()));
ch.pipeline().addLast(new ChannelInboundHandlerAdapter() {
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
if (cause.getCause() instanceof SSLException) {
// We received the alert and so produce an SSLException.
promise.setSuccess(null);
}
}
});
}
}).connect(sc.localAddress()).syncUninterruptibly().channel();
promise.syncUninterruptibly();
} finally {
if (cc != null) {
cc.close().syncUninterruptibly();
}
if (sc != null) {
sc.close().syncUninterruptibly();
}
group.shutdownGracefully();
ReferenceCountUtil.release(sslServerCtx);
ReferenceCountUtil.release(sslClientCtx);
}
}
Aggregations