Zond: детектирование отсутствия пинга (завис сервер?)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
group = 'asys'
|
||||
version = '0.7.10-SNAPSHOT'
|
||||
version = '0.7.11-SNAPSHOT'
|
||||
|
||||
apply plugin: 'application'
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package asys.zond;
|
||||
|
||||
import asys.zond.shell.Shell;
|
||||
|
||||
public class PingMonitor {
|
||||
private static final long STEP_PING = 5000;
|
||||
private final long delayStart;
|
||||
@@ -23,8 +25,6 @@ public class PingMonitor {
|
||||
if ((currentTimeMillis - lastPingTime) >= (2*STEP_PING)) { // если пропущено два пинга
|
||||
callback.run(); // запускаем код завершения процесса
|
||||
return; // завершаем поток
|
||||
} else {
|
||||
lastPingTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -43,4 +43,9 @@ public class PingMonitor {
|
||||
threadPingMon.interrupt();
|
||||
threadPingMon = null;
|
||||
}
|
||||
|
||||
public void checkPing() {
|
||||
lastPingTime = System.currentTimeMillis();
|
||||
Shell.getInstance().getOutput().println("[D] check ping: " + lastPingTime);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ public class ZondCommandHandler implements CommandHandler {
|
||||
private Server server;
|
||||
private PipeInputStream proxyStdIn;
|
||||
private PingMonitor pingMonitor;
|
||||
private boolean flagForceRestartProcess = false;
|
||||
|
||||
ZondCommandHandler(PipeInputStream proxyStdIn) {
|
||||
this.proxyStdIn = proxyStdIn;
|
||||
@@ -50,11 +51,7 @@ public class ZondCommandHandler implements CommandHandler {
|
||||
} else if (line.equalsIgnoreCase("start")) {
|
||||
startProcess();
|
||||
} else if (line.equalsIgnoreCase("kill")) {
|
||||
if (watchdog != null) {
|
||||
server.shutdown();
|
||||
watchdog.destroyProcess();
|
||||
threadExec.interrupt();
|
||||
}
|
||||
killProcess();
|
||||
} else if (line.equalsIgnoreCase("connect")) {
|
||||
Connector.getInstance().startReconnect();
|
||||
} else if (line.equalsIgnoreCase("disconnect")) {
|
||||
@@ -91,9 +88,15 @@ public class ZondCommandHandler implements CommandHandler {
|
||||
|
||||
try {
|
||||
server = new Server();
|
||||
server.setPingMonitor(pingMonitor);
|
||||
server.start(Config.getInstance().getInt("bridge.port"));
|
||||
|
||||
pingMonitor.start(() -> {});
|
||||
pingMonitor.start(() -> {
|
||||
Shell.getInstance().getOutput().println("[!] Process - zobie?");
|
||||
Shell.getInstance().getOutput().println("[!] Force shutdown process.");
|
||||
flagForceRestartProcess = true;
|
||||
killProcess();
|
||||
});
|
||||
code = executor.execute(commandLine);
|
||||
} catch (ExecuteException ignore) {
|
||||
} catch (IOException e) {
|
||||
@@ -113,6 +116,9 @@ public class ZondCommandHandler implements CommandHandler {
|
||||
if (_try < 2) {
|
||||
Shell.getInstance().getOutput().println("[!] Try start process again...");
|
||||
}
|
||||
} else if (flagForceRestartProcess) {
|
||||
_try = 0;
|
||||
flagForceRestartProcess = false;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
@@ -126,4 +132,12 @@ public class ZondCommandHandler implements CommandHandler {
|
||||
threadExec.start();
|
||||
}
|
||||
}
|
||||
|
||||
private void killProcess() {
|
||||
if (watchdog != null) {
|
||||
server.shutdown();
|
||||
watchdog.destroyProcess();
|
||||
threadExec.interrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ package asys.zond.proxy.server;
|
||||
import asys.mcsmanager.packets.codec.PacketDecoder;
|
||||
import asys.mcsmanager.packets.codec.PacketEncoder;
|
||||
import asys.mcsmanager.packets.codec.PacketHandler;
|
||||
import asys.zond.PingMonitor;
|
||||
import io.netty.bootstrap.ServerBootstrap;
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import io.netty.channel.ChannelInitializer;
|
||||
@@ -17,6 +18,7 @@ import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||
|
||||
public class Server {
|
||||
private EventLoopGroup bossGroup, workerGroup;
|
||||
private PingMonitor pingMonitor;
|
||||
|
||||
public void start(int port) {
|
||||
bossGroup = new NioEventLoopGroup(1);
|
||||
@@ -49,9 +51,13 @@ public class Server {
|
||||
new PacketEncoder(),
|
||||
new PacketDecoder(),
|
||||
new PacketHandler(),
|
||||
new ServerPacketHandler()
|
||||
new ServerPacketHandler(pingMonitor)
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void setPingMonitor(PingMonitor pingMonitor) {
|
||||
this.pingMonitor = pingMonitor;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
package asys.zond.proxy.server;
|
||||
|
||||
import asys.mcsmanager.packets.*;
|
||||
import asys.zond.PingMonitor;
|
||||
import asys.zond.proxy.client.Connector;
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.ImmutableBiMap;
|
||||
@@ -20,8 +21,10 @@ import static asys.mcsmanager.packets.codec.Params.KNOWN_PACKETS;
|
||||
public class ServerPacketHandler extends ChannelInboundHandlerAdapter implements IPacketHandler {
|
||||
private final BiMap<Integer, Class<? extends Packet>> knownPackets;
|
||||
private final Map<Class<? extends Packet>, IPacketHandler> knownHandlers;
|
||||
private final PingMonitor pingMonitor;
|
||||
|
||||
ServerPacketHandler() {
|
||||
ServerPacketHandler(PingMonitor pingMonitor) {
|
||||
this.pingMonitor = pingMonitor;
|
||||
knownPackets = ImmutableBiMap.of(
|
||||
3, CS_Ping.class,
|
||||
5, SC_Command.class
|
||||
@@ -52,6 +55,7 @@ public class ServerPacketHandler extends ChannelInboundHandlerAdapter implements
|
||||
}
|
||||
|
||||
private void handleCSPing(CS_Ping packet) {
|
||||
pingMonitor.checkPing();
|
||||
Connector.getInstance().sendPacket(packet);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user