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