use of org.apache.flink.shaded.netty4.io.netty.bootstrap.ServerBootstrap 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.bootstrap.ServerBootstrap in project intellij-community by JetBrains.
the class SubServer method bind.
public boolean bind(int port) {
if (port == server.getPort() || port == -1) {
return true;
}
if (channelRegistrar == null) {
Disposer.register(server, this);
channelRegistrar = new ChannelRegistrar();
}
ServerBootstrap bootstrap = serverBootstrap(server.getEventLoopGroup());
Map<String, Object> xmlRpcHandlers = user.createXmlRpcHandlers();
if (xmlRpcHandlers == null) {
BuiltInServer.configureChildHandler(bootstrap, channelRegistrar, null);
} else {
final XmlRpcDelegatingHttpRequestHandler handler = new XmlRpcDelegatingHttpRequestHandler(xmlRpcHandlers);
bootstrap.childHandler(new ChannelInitializer() {
@Override
protected void initChannel(Channel channel) throws Exception {
channel.pipeline().addLast(channelRegistrar);
NettyUtil.addHttpServerCodec(channel.pipeline());
channel.pipeline().addLast(handler);
}
});
}
try {
bootstrap.localAddress(user.isAvailableExternally() ? new InetSocketAddress(port) : NetKt.loopbackSocketAddress(port));
channelRegistrar.setServerChannel(bootstrap.bind().syncUninterruptibly().channel(), false);
return true;
} catch (Exception e) {
try {
NettyUtil.log(e, Logger.getInstance(BuiltInServer.class));
} finally {
user.cannotBind(e, port);
}
return false;
}
}
use of org.apache.flink.shaded.netty4.io.netty.bootstrap.ServerBootstrap 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.bootstrap.ServerBootstrap 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.bootstrap.ServerBootstrap 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