Search in sources :

Example 1 with BuiltInServer

use of org.jetbrains.io.BuiltInServer 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();
}
Also used : ProtobufEncoder(io.netty.handler.codec.protobuf.ProtobufEncoder) OioEventLoopGroup(io.netty.channel.oio.OioEventLoopGroup) InetSocketAddress(java.net.InetSocketAddress) Channel(io.netty.channel.Channel) ProtobufDecoder(io.netty.handler.codec.protobuf.ProtobufDecoder) ProtobufVarint32LengthFieldPrepender(io.netty.handler.codec.protobuf.ProtobufVarint32LengthFieldPrepender) BuiltInServer(org.jetbrains.io.BuiltInServer) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) IOException(java.io.IOException) ExecutionException(com.intellij.execution.ExecutionException) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) EventLoopGroup(io.netty.channel.EventLoopGroup) OioEventLoopGroup(io.netty.channel.oio.OioEventLoopGroup) ChannelInitializer(io.netty.channel.ChannelInitializer) ProtobufVarint32FrameDecoder(io.netty.handler.codec.protobuf.ProtobufVarint32FrameDecoder) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Example 2 with BuiltInServer

use of org.jetbrains.io.BuiltInServer 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);
    });
}
Also used : OioEventLoopGroup(io.netty.channel.oio.OioEventLoopGroup) BuiltInServer(org.jetbrains.io.BuiltInServer)

Example 3 with BuiltInServer

use of org.jetbrains.io.BuiltInServer in project intellij-community by JetBrains.

the class SocketLock method dispose.

public void dispose() {
    log("enter: dispose()");
    BuiltInServer server = myServer;
    if (server == null)
        return;
    try {
        Disposer.dispose(server);
    } finally {
        try {
            underLocks(() -> {
                FileUtil.delete(new File(myConfigPath, PORT_FILE));
                FileUtil.delete(new File(mySystemPath, PORT_FILE));
                FileUtil.delete(new File(mySystemPath, TOKEN_FILE));
                return null;
            });
        } catch (Exception e) {
            Logger.getInstance(SocketLock.class).warn(e);
        }
    }
}
Also used : BuiltInServer(org.jetbrains.io.BuiltInServer) ConnectException(java.net.ConnectException)

Aggregations

BuiltInServer (org.jetbrains.io.BuiltInServer)3 OioEventLoopGroup (io.netty.channel.oio.OioEventLoopGroup)2 ExecutionException (com.intellij.execution.ExecutionException)1 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)1 Channel (io.netty.channel.Channel)1 ChannelInitializer (io.netty.channel.ChannelInitializer)1 EventLoopGroup (io.netty.channel.EventLoopGroup)1 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)1 ProtobufDecoder (io.netty.handler.codec.protobuf.ProtobufDecoder)1 ProtobufEncoder (io.netty.handler.codec.protobuf.ProtobufEncoder)1 ProtobufVarint32FrameDecoder (io.netty.handler.codec.protobuf.ProtobufVarint32FrameDecoder)1 ProtobufVarint32LengthFieldPrepender (io.netty.handler.codec.protobuf.ProtobufVarint32LengthFieldPrepender)1 IOException (java.io.IOException)1 ConnectException (java.net.ConnectException)1 InetSocketAddress (java.net.InetSocketAddress)1