move built-in server to platform-impl — prepare to merge SocketLock

This commit is contained in:
Vladimir Krivosheev
2015-05-26 14:28:08 +02:00
parent ded8373cb6
commit fec0ee32a5
10 changed files with 37 additions and 24 deletions
@@ -14,6 +14,7 @@ import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.io.BuiltInServer;
import org.jetbrains.io.SubServer;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
@@ -97,6 +98,7 @@ public class BuiltInServerManagerImpl extends BuiltInServerManager {
try {
server = BuiltInServer.start(workerCount, defaultPort, PORTS_COUNT, true);
bindCustomPorts(server);
}
catch (Throwable e) {
LOG.info(e);
@@ -127,4 +129,19 @@ public class BuiltInServerManagerImpl extends BuiltInServerManager {
public Disposable getServerDisposable() {
return server;
}
private static void bindCustomPorts(@NotNull BuiltInServer server) {
if (ApplicationManager.getApplication().isUnitTestMode()) {
return;
}
for (CustomPortServerManager customPortServerManager : CustomPortServerManager.EP_NAME.getExtensions()) {
try {
new SubServer(customPortServerManager, server).bind(customPortServerManager.getPort());
}
catch (Throwable e) {
LOG.error(e);
}
}
}
}
@@ -34,7 +34,7 @@ import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.Map;
final class SubServer implements CustomPortServerManager.CustomPortService, Disposable {
public final class SubServer implements CustomPortServerManager.CustomPortService, Disposable {
private ChannelRegistrar channelRegistrar;
private final CustomPortServerManager user;
+1
View File
@@ -41,5 +41,6 @@
<orderEntry type="module" module-name="diff-api" />
<orderEntry type="module" module-name="built-in-server" scope="RUNTIME" />
<orderEntry type="library" name="imgscalr" level="project" />
<orderEntry type="module" module-name="built-in-server-api" />
</component>
</module>
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,6 @@
package org.jetbrains.io;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.util.net.NetUtils;
@@ -24,7 +23,6 @@ import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.ide.CustomPortServerManager;
import org.jetbrains.ide.PooledThreadExecutor;
import java.io.IOException;
@@ -55,10 +53,7 @@ public class BuiltInServer implements Disposable {
ChannelRegistrar channelRegistrar = new ChannelRegistrar();
ServerBootstrap bootstrap = NettyUtil.nioServerBootstrap(eventLoopGroup);
configureChildHandler(bootstrap, channelRegistrar);
int port = bind(firstPort, portsCount, tryAnyPort, bootstrap, channelRegistrar);
BuiltInServer server = new BuiltInServer(eventLoopGroup, port);
bindCustomPorts(server);
return server;
return new BuiltInServer(eventLoopGroup, bind(firstPort, portsCount, tryAnyPort, bootstrap, channelRegistrar));
}
public int getPort() {
@@ -75,21 +70,6 @@ public class BuiltInServer implements Disposable {
});
}
private static void bindCustomPorts(@NotNull BuiltInServer server) {
if (ApplicationManager.getApplication().isUnitTestMode()) {
return;
}
for (CustomPortServerManager customPortServerManager : CustomPortServerManager.EP_NAME.getExtensions()) {
try {
new SubServer(customPortServerManager, server).bind(customPortServerManager.getPort());
}
catch (Throwable e) {
LOG.error(e);
}
}
}
private static int bind(int firstPort, int portsCount, boolean tryAnyPort, @NotNull ServerBootstrap bootstrap, @NotNull ChannelRegistrar channelRegistrar) throws Throwable {
InetAddress loopbackAddress = NetUtils.getLoopbackAddress();
for (int i = 0; i < portsCount; i++) {
@@ -1,3 +1,18 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.io;
import io.netty.channel.*;
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.