ensure that we customize Netty before use

This commit is contained in:
Vladimir Krivosheev
2015-12-25 16:17:26 +01:00
parent d9f95e9353
commit f2eb2eec9a
3 changed files with 12 additions and 11 deletions
@@ -143,6 +143,7 @@ public final class SocketLock {
myServer = BuiltInServer.start(workerCount, 6942, 50, false, handler);
}
catch (IllegalStateException e) {
Logger.getInstance(SocketLock.class).warn(e);
myServer = BuiltInServer.start(new OioEventLoopGroup(1, new BuiltInServer.BuiltInServerThreadFactory()), true, 6942, 50, false, handler);
}
@@ -20,6 +20,7 @@ import com.intellij.openapi.diagnostic.Logger;
import com.intellij.util.ArrayUtil;
import com.intellij.util.ExceptionUtil;
import com.intellij.util.NotNullProducer;
import com.intellij.util.SystemProperties;
import com.intellij.util.net.NetUtils;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.*;
@@ -29,6 +30,7 @@ import org.jetbrains.annotations.Nullable;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.Random;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;
@@ -41,6 +43,15 @@ public class BuiltInServer implements Disposable {
private final ChannelRegistrar channelRegistrar;
private final boolean isOwnerOfEventLoopGroup;
static {
// IDEA-120811
if (SystemProperties.getBooleanProperty("io.netty.random.id", true)) {
System.setProperty("io.netty.machineId", "9e43d860");
System.setProperty("io.netty.processId", Integer.toString(new Random().nextInt(65535)));
System.setProperty("io.netty.serviceThreadPrefix", "Netty ");
}
}
private BuiltInServer(@NotNull EventLoopGroup eventLoopGroup,
int port,
@NotNull ChannelRegistrar channelRegistrar,
@@ -17,7 +17,6 @@ package org.jetbrains.io;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Condition;
import com.intellij.util.SystemProperties;
import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.BootstrapUtil;
import io.netty.bootstrap.ServerBootstrap;
@@ -46,7 +45,6 @@ import java.net.BindException;
import java.net.ConnectException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.Random;
import java.util.concurrent.TimeUnit;
public final class NettyUtil {
@@ -55,15 +53,6 @@ public final class NettyUtil {
public static final int DEFAULT_CONNECT_ATTEMPT_COUNT = 20;
public static final int MIN_START_TIME = 100;
static {
// IDEA-120811
if (SystemProperties.getBooleanProperty("io.netty.random.id", true)) {
System.setProperty("io.netty.machineId", "9e43d860");
System.setProperty("io.netty.processId", Integer.toString(new Random().nextInt(65535)));
System.setProperty("io.netty.serviceThreadPrefix", "Netty ");
}
}
public static void logAndClose(@NotNull Throwable error, @NotNull Logger log, @NotNull Channel channel) {
// don't report about errors while connecting
// WEB-7727