Compare commits
3 Commits
c84f11cd8f
...
0b19a75d7b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0b19a75d7b | ||
|
|
2caa383f06 | ||
|
|
912ae30ff0 |
3
.gitignore
vendored
3
.gitignore
vendored
@ -35,4 +35,5 @@ build/
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
||||
.DS_Store
|
||||
/.idea/encodings.xml
|
||||
|
||||
2
pom.xml
2
pom.xml
@ -103,7 +103,7 @@
|
||||
<arg>--gc=G1</arg>
|
||||
<arg>--enable-url-protocols=https</arg>
|
||||
<arg>-H:IncludeResources="simplelogger.properties"</arg>
|
||||
<arg>--initialize-at-build-time=org.slf4j.simple.SimpleLogger,org.slf4j.simple.SimpleLoggerFactory</arg>
|
||||
<arg>--initialize-at-build-time=org.slf4j.simple.SimpleLogger,org.slf4j.simple.SimpleLoggerFactory,org.slf4j.simple.SimpleLoggerConfiguration</arg>
|
||||
<arg>-H:ReflectionConfigurationFiles=src/main/resources/reflect-config.json</arg>
|
||||
</buildArgs>
|
||||
<metadataRepository>
|
||||
|
||||
@ -5,6 +5,8 @@ import cn.hutool.http.HttpResponse;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.ServerSocket;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
|
||||
@ -25,4 +27,15 @@ public class CustomUtil {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static int _findIdlePort(int port) {
|
||||
for(int i=port; i<65535; i++){
|
||||
try(ServerSocket ignored = new ServerSocket(i)){
|
||||
ignored.close();
|
||||
return i;
|
||||
}catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,6 +54,8 @@ public class storageNode {
|
||||
counter = 0;
|
||||
promises = new HashMap<>();
|
||||
|
||||
int real_port = CustomUtil._findIdlePort(26321);
|
||||
|
||||
channelFuture = new ServerBootstrap()
|
||||
.channel(NioServerSocketChannel.class)
|
||||
.group(new NioEventLoopGroup())
|
||||
@ -64,12 +66,25 @@ public class storageNode {
|
||||
channel.pipeline().addLast(new MessageCodec());
|
||||
channel.pipeline().addLast(new MyChannelInboundHandlerAdapter(tempQueue));
|
||||
}
|
||||
})
|
||||
.bind(26321);
|
||||
}).bind(real_port);
|
||||
log.info("listening on port {}", real_port);
|
||||
|
||||
try(Socket socket = new Socket()){
|
||||
socket.connect(new InetSocketAddress("lionwebsite.xyz", 26322));
|
||||
} catch (Exception ignored) {}
|
||||
int i;
|
||||
for(i=0; i<=20; i++) {
|
||||
try (Socket socket = new Socket()) {
|
||||
socket.setSoTimeout(3000);
|
||||
log.info("wake up main server on port {}", 26322 + i);
|
||||
socket.connect(new InetSocketAddress("lionwebsite.xyz", 26322 + i));
|
||||
byte[] bytes = socket.getInputStream().readAllBytes();
|
||||
if(bytes.length > 0 && new String(bytes).equals("lionwebsite")) {
|
||||
break;
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
if (i==20) {
|
||||
log.info("server connect failed");
|
||||
}
|
||||
downloadCheckService = new DownloadCheckService(queue, promises);
|
||||
checkThreadPool = Executors.newScheduledThreadPool(1);
|
||||
checkThreadPool.scheduleAtFixedRate(this::mainThread, 5, 5, TimeUnit.SECONDS);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user