use of io.netty.channel.oio.OioEventLoopGroup in project intellij-community by JetBrains.
the class BuildManager method startListening.
private int startListening() throws Exception {
EventLoopGroup group;
BuiltInServer mainServer = StartupUtil.getServer();
boolean isOwnEventLoopGroup = !Registry.is("compiler.shared.event.group", true) || mainServer == null || mainServer.getEventLoopGroup() instanceof OioEventLoopGroup;
if (isOwnEventLoopGroup) {
group = new NioEventLoopGroup(1, ConcurrencyUtil.newNamedThreadFactory("External compiler"));
} else {
group = mainServer.getEventLoopGroup();
}
final ServerBootstrap bootstrap = serverBootstrap(group);
bootstrap.childHandler(new ChannelInitializer() {
@Override
protected void initChannel(@NotNull Channel channel) throws Exception {
channel.pipeline().addLast(myChannelRegistrar, new ProtobufVarint32FrameDecoder(), new ProtobufDecoder(CmdlineRemoteProto.Message.getDefaultInstance()), new ProtobufVarint32LengthFieldPrepender(), new ProtobufEncoder(), myMessageDispatcher);
}
});
Channel serverChannel = bootstrap.bind(InetAddress.getLoopbackAddress(), 0).syncUninterruptibly().channel();
myChannelRegistrar.setServerChannel(serverChannel, isOwnEventLoopGroup);
return ((InetSocketAddress) serverChannel.localAddress()).getPort();
}
use of io.netty.channel.oio.OioEventLoopGroup in project geode by apache.
the class GeodeRedisServer method startRedisServer.
/**
* Helper method to start the server listening for connections. The server is bound to the port
* specified by {@link GeodeRedisServer#serverPort}
*
* @throws IOException
* @throws InterruptedException
*/
private void startRedisServer() throws IOException, InterruptedException {
ThreadFactory selectorThreadFactory = new ThreadFactory() {
private final AtomicInteger counter = new AtomicInteger();
@Override
public Thread newThread(Runnable r) {
Thread t = new Thread(r);
t.setName("GeodeRedisServer-SelectorThread-" + counter.incrementAndGet());
t.setDaemon(true);
return t;
}
};
ThreadFactory workerThreadFactory = new ThreadFactory() {
private final AtomicInteger counter = new AtomicInteger();
@Override
public Thread newThread(Runnable r) {
Thread t = new Thread(r);
t.setName("GeodeRedisServer-WorkerThread-" + counter.incrementAndGet());
return t;
}
};
bossGroup = null;
workerGroup = null;
Class<? extends ServerChannel> socketClass = null;
if (singleThreadPerConnection) {
bossGroup = new OioEventLoopGroup(Integer.MAX_VALUE, selectorThreadFactory);
workerGroup = new OioEventLoopGroup(Integer.MAX_VALUE, workerThreadFactory);
socketClass = OioServerSocketChannel.class;
} else {
bossGroup = new NioEventLoopGroup(this.numSelectorThreads, selectorThreadFactory);
workerGroup = new NioEventLoopGroup(this.numWorkerThreads, workerThreadFactory);
socketClass = NioServerSocketChannel.class;
}
InternalDistributedSystem system = (InternalDistributedSystem) cache.getDistributedSystem();
String pwd = system.getConfig().getRedisPassword();
final byte[] pwdB = Coder.stringToBytes(pwd);
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup).channel(socketClass).childHandler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
if (logger.fineEnabled())
logger.fine("GeodeRedisServer-Connection established with " + ch.remoteAddress());
ChannelPipeline p = ch.pipeline();
p.addLast(ByteToCommandDecoder.class.getSimpleName(), new ByteToCommandDecoder());
p.addLast(ExecutionHandlerContext.class.getSimpleName(), new ExecutionHandlerContext(ch, cache, regionCache, GeodeRedisServer.this, pwdB));
}
}).option(ChannelOption.SO_REUSEADDR, true).option(ChannelOption.SO_RCVBUF, getBufferSize()).childOption(ChannelOption.SO_KEEPALIVE, true).childOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, GeodeRedisServer.connectTimeoutMillis).childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
// Bind and start to accept incoming connections.
ChannelFuture f = b.bind(new InetSocketAddress(getBindAddress(), serverPort)).sync();
if (this.logger.infoEnabled()) {
String logMessage = "GeodeRedisServer started {" + getBindAddress() + ":" + serverPort + "}, Selector threads: " + this.numSelectorThreads;
if (this.singleThreadPerConnection)
logMessage += ", One worker thread per connection";
else
logMessage += ", Worker threads: " + this.numWorkerThreads;
this.logger.info(logMessage);
}
this.serverChannel = f.channel();
}
use of io.netty.channel.oio.OioEventLoopGroup in project intellij-community by JetBrains.
the class BuiltInServerManagerImpl method startServerInPooledThread.
private Future<?> startServerInPooledThread() {
if (!started.compareAndSet(false, true)) {
return null;
}
return ApplicationManager.getApplication().executeOnPooledThread(() -> {
try {
BuiltInServer mainServer = StartupUtil.getServer();
if (mainServer == null || mainServer.getEventLoopGroup() instanceof OioEventLoopGroup) {
server = BuiltInServer.start(1, getDefaultPort(), PORTS_COUNT, false, null);
} else {
server = BuiltInServer.start(mainServer.getEventLoopGroup(), false, getDefaultPort(), PORTS_COUNT, true, null);
}
bindCustomPorts(server);
} catch (Throwable e) {
LOG.info(e);
NOTIFICATION_GROUP.getValue().createNotification("Cannot start internal HTTP server. Git integration, JavaScript debugger and LiveEdit may operate with errors. " + "Please check your firewall settings and restart " + ApplicationNamesInfo.getInstance().getFullProductName(), NotificationType.ERROR).notify(null);
return;
}
LOG.info("built-in server started, port " + server.getPort());
Disposer.register(ApplicationManager.getApplication(), server);
});
}
use of io.netty.channel.oio.OioEventLoopGroup in project android by JetBrains.
the class LocalTestServer method start.
public void start() throws Exception {
ServerBootstrap b = new ServerBootstrap();
myEventLoopGroup = new OioEventLoopGroup();
b.group(myEventLoopGroup).channel(OioServerSocketChannel.class).childHandler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
p.addLast(new HttpServerCodec());
// Note: Netty's decompressor uses jcraft jzlib, which is not exported as a library
// p.addLast(new HttpContentDecompressor());
// big enough to collect a full thread dump
p.addLast(new HttpObjectAggregator(32 * 1024));
p.addLast(new ChannelInboundHandlerAdapter() {
@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
ctx.flush();
}
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
if (!(msg instanceof FullHttpRequest)) {
return;
}
FullHttpResponse response = myResponseSupplier.apply((FullHttpRequest) msg);
response.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/plain");
response.headers().set(HttpHeaderNames.CONTENT_LENGTH, response.content().readableBytes());
ctx.write(response).addListener(ChannelFutureListener.CLOSE);
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
ctx.write(cause.toString()).addListener(ChannelFutureListener.CLOSE);
}
});
}
});
myChannel = b.bind(myPort).sync().channel();
}
use of io.netty.channel.oio.OioEventLoopGroup in project netty by netty.
the class RxtxClient method main.
public static void main(String[] args) throws Exception {
EventLoopGroup group = new OioEventLoopGroup();
try {
Bootstrap b = new Bootstrap();
b.group(group).channel(RxtxChannel.class).handler(new ChannelInitializer<RxtxChannel>() {
@Override
public void initChannel(RxtxChannel ch) throws Exception {
ch.pipeline().addLast(new LineBasedFrameDecoder(32768), new StringEncoder(), new StringDecoder(), new RxtxClientHandler());
}
});
ChannelFuture f = b.connect(new RxtxDeviceAddress(PORT)).sync();
f.channel().closeFuture().sync();
} finally {
group.shutdownGracefully();
}
}
Aggregations