Zond:fix: стабилизация работы модуля в целом
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
group = 'asys'
|
||||
version = '0.8.1-SNAPSHOT'
|
||||
version = '0.8.2-SNAPSHOT'
|
||||
|
||||
repositories {
|
||||
maven { url 'https://hub.spigotmc.org/nexus/content/groups/public/' }
|
||||
|
||||
@@ -25,6 +25,7 @@ public class BridgePlugin extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
this.bridgeBukkit.sendCorrectShutdownPacket();
|
||||
this.bridgeBukkit.setNeedReconnect(false);
|
||||
this.bridgeBukkit.stopPing();
|
||||
this.bridgeBukkit.stopReconnect();
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
package asys.bridge.client;
|
||||
|
||||
import asys.bridge.bukkit.TaskTicker;
|
||||
import asys.mcsmanager.packets.CS_CorrectShutdown;
|
||||
import asys.mcsmanager.packets.CS_Ping;
|
||||
import io.netty.channel.Channel;
|
||||
|
||||
public abstract class AbstractBridge implements IBridge {
|
||||
private Client client;
|
||||
@@ -39,6 +39,13 @@ public abstract class AbstractBridge implements IBridge {
|
||||
this.needReconnect = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendCorrectShutdownPacket() {
|
||||
if (client != null && client.isConnected()) {
|
||||
client.sendPacket(new CS_CorrectShutdown());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopReconnect() {
|
||||
if (connectTicker != null) {
|
||||
|
||||
@@ -21,7 +21,8 @@ public class ClientPacketHandler extends ChannelInboundHandlerAdapter implements
|
||||
|
||||
private static final BiMap<Integer, Class<? extends Packet>> knownPackets = ImmutableBiMap.of(
|
||||
3, CS_Ping.class,
|
||||
5, SC_Command.class
|
||||
5, SC_Command.class,
|
||||
6, CS_CorrectShutdown.class
|
||||
);
|
||||
private IBridge bridge;
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ public interface IBridge {
|
||||
void startReconnect();
|
||||
boolean isNeedReconnect();
|
||||
void setNeedReconnect(boolean value);
|
||||
void sendCorrectShutdownPacket();
|
||||
void stopReconnect();
|
||||
void startPing();
|
||||
void stopPing();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
group = 'asys'
|
||||
version = '0.5-SNAPSHOT'
|
||||
version = '0.6-SNAPSHOT'
|
||||
|
||||
task jar(type: Jar, overwrite: true) {
|
||||
// не собирать jar
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* DmitriyMX <dimon550@gmail.com>
|
||||
* 2017-07-22
|
||||
*/
|
||||
package asys.mcsmanager.packets;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class CS_CorrectShutdown extends Packet {
|
||||
@Override
|
||||
public void readSelfData(ByteBuf buffer) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeSelfData(ByteBuf buffer) {
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
group = 'asys'
|
||||
version = '0.7.12-SNAPSHOT'
|
||||
version = '0.7.13-SNAPSHOT'
|
||||
|
||||
apply plugin: 'application'
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ public class PingMonitor {
|
||||
private final long delayStart;
|
||||
private long lastPingTime;
|
||||
private Thread threadPingMon;
|
||||
private boolean correctShutdown = false;
|
||||
|
||||
public PingMonitor(long delayStart) {
|
||||
this.delayStart = delayStart;
|
||||
@@ -14,6 +15,7 @@ public class PingMonitor {
|
||||
|
||||
public void start(final Runnable callback) {
|
||||
this.threadPingMon = new Thread(() -> {
|
||||
correctShutdown = false;
|
||||
try {
|
||||
Thread.sleep(delayStart);
|
||||
} catch (InterruptedException e) {
|
||||
@@ -40,12 +42,21 @@ public class PingMonitor {
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
threadPingMon.interrupt();
|
||||
threadPingMon = null;
|
||||
if (threadPingMon != null) {
|
||||
threadPingMon.interrupt();
|
||||
threadPingMon = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void checkPing() {
|
||||
lastPingTime = System.currentTimeMillis();
|
||||
Shell.getInstance().getOutput().println("[D] check ping: " + lastPingTime);
|
||||
}
|
||||
|
||||
public void correctShutdown() {
|
||||
correctShutdown = true;
|
||||
}
|
||||
|
||||
public boolean isCorrectShutdown() {
|
||||
return correctShutdown;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,6 +94,9 @@ public class PipeInputStream extends InputStream {
|
||||
|
||||
public void open() {
|
||||
closed = false;
|
||||
lastWritePos = 0;
|
||||
lastReadPos = 0;
|
||||
wallPos = buffer.length-1;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -24,6 +24,7 @@ public class ZondCommandHandler implements CommandHandler {
|
||||
private PipeInputStream proxyStdIn;
|
||||
private PingMonitor pingMonitor;
|
||||
private boolean flagForceRestartProcess = false;
|
||||
private boolean flagManualKill = false;
|
||||
|
||||
ZondCommandHandler(PipeInputStream proxyStdIn) {
|
||||
this.proxyStdIn = proxyStdIn;
|
||||
@@ -41,16 +42,14 @@ public class ZondCommandHandler implements CommandHandler {
|
||||
|
||||
private void internalCommand(String line) {
|
||||
if (line.equalsIgnoreCase("exit") || line.equalsIgnoreCase("quit")) {
|
||||
if (watchdog != null) {
|
||||
server.shutdown();
|
||||
watchdog.destroyProcess();
|
||||
threadExec.interrupt();
|
||||
}
|
||||
flagManualKill = true;
|
||||
killProcess();
|
||||
Connector.getInstance().shutdown();
|
||||
Shell.getInstance().shutdown();
|
||||
} else if (line.equalsIgnoreCase("start")) {
|
||||
startProcess();
|
||||
} else if (line.equalsIgnoreCase("kill")) {
|
||||
flagManualKill = true;
|
||||
killProcess();
|
||||
} else if (line.equalsIgnoreCase("connect")) {
|
||||
Connector.getInstance().startReconnect();
|
||||
@@ -73,11 +72,14 @@ public class ZondCommandHandler implements CommandHandler {
|
||||
}
|
||||
|
||||
private void startProcess() {
|
||||
if (watchdog == null) {
|
||||
watchdog = new ZondExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT, proxyStdIn);
|
||||
executor.setWatchdog(watchdog);
|
||||
if (watchdog == null || !watchdog.isWatching()) {
|
||||
if (watchdog == null) {
|
||||
watchdog = new ZondExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT, proxyStdIn);
|
||||
executor.setWatchdog(watchdog);
|
||||
}
|
||||
final long delay = Config.getInstance().getLong("pingmonitor.delay");
|
||||
pingMonitor = new PingMonitor(delay);
|
||||
flagManualKill = false;
|
||||
|
||||
Runnable task = () -> {
|
||||
short _try = 0;
|
||||
@@ -108,22 +110,27 @@ public class ZondCommandHandler implements CommandHandler {
|
||||
server.shutdown();
|
||||
pingMonitor.stop();
|
||||
server = null;
|
||||
watchdog = null;
|
||||
Shell.getInstance().getOutput().println("Process finished. Code: " + code);
|
||||
|
||||
if (System.currentTimeMillis() <= deadTime) {
|
||||
Shell.getInstance().getOutput().println("[!] Premature end process.");
|
||||
_try++;
|
||||
if (_try < 2) {
|
||||
if (!pingMonitor.isCorrectShutdown()) {
|
||||
if (System.currentTimeMillis() <= deadTime && !flagManualKill) {
|
||||
Shell.getInstance().getOutput().println("[!] Premature end process.");
|
||||
_try++;
|
||||
if (_try < 2) {
|
||||
Shell.getInstance().getOutput().println("[!] Try start process again...");
|
||||
}
|
||||
} else if (flagForceRestartProcess) {
|
||||
_try = 0;
|
||||
flagForceRestartProcess = false;
|
||||
} else if (code != 0 && code != -99 && !flagManualKill) {
|
||||
Shell.getInstance().getOutput().println("[!] Try start process again...");
|
||||
_try = 0;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} else if (flagForceRestartProcess) {
|
||||
_try = 0;
|
||||
flagForceRestartProcess = false;
|
||||
} else if (code != 0 && code != -99) {
|
||||
Shell.getInstance().getOutput().println("[!] Try start process again...");
|
||||
_try = 0;
|
||||
} else {
|
||||
flagForceRestartProcess = false;
|
||||
_try = 0;
|
||||
break;
|
||||
}
|
||||
} while (_try < 2);
|
||||
@@ -138,8 +145,9 @@ public class ZondCommandHandler implements CommandHandler {
|
||||
}
|
||||
|
||||
private void killProcess() {
|
||||
if (watchdog != null) {
|
||||
if (watchdog != null && watchdog.isWatching()) {
|
||||
server.shutdown();
|
||||
pingMonitor.stop();
|
||||
watchdog.destroyProcess();
|
||||
threadExec.interrupt();
|
||||
}
|
||||
|
||||
@@ -12,6 +12,11 @@ public class ZondExecuteWatchdog extends ExecuteWatchdog {
|
||||
public ZondExecuteWatchdog(long timeout, PipeInputStream inputStream) {
|
||||
super(timeout);
|
||||
this.inputStream = inputStream;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void start(Process processToMonitor) {
|
||||
super.start(processToMonitor);
|
||||
inputStream.open();
|
||||
}
|
||||
|
||||
|
||||
@@ -27,11 +27,13 @@ public class ServerPacketHandler extends ChannelInboundHandlerAdapter implements
|
||||
this.pingMonitor = pingMonitor;
|
||||
knownPackets = ImmutableBiMap.of(
|
||||
3, CS_Ping.class,
|
||||
5, SC_Command.class
|
||||
5, SC_Command.class,
|
||||
6, CS_CorrectShutdown.class
|
||||
);
|
||||
knownHandlers = ImmutableMap.of(
|
||||
CS_Ping.class, this,
|
||||
CS_ConsoleMessage.class, this
|
||||
CS_ConsoleMessage.class, this,
|
||||
CS_CorrectShutdown.class, this
|
||||
);
|
||||
}
|
||||
|
||||
@@ -51,6 +53,8 @@ public class ServerPacketHandler extends ChannelInboundHandlerAdapter implements
|
||||
public void handle(Packet packet, ChannelHandlerContext context) {
|
||||
if (packet instanceof CS_Ping) {
|
||||
handleCSPing((CS_Ping) packet);
|
||||
} else if (packet instanceof CS_CorrectShutdown) {
|
||||
handleCSCorrectShutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,4 +62,8 @@ public class ServerPacketHandler extends ChannelInboundHandlerAdapter implements
|
||||
pingMonitor.checkPing();
|
||||
Connector.getInstance().sendPacket(packet);
|
||||
}
|
||||
|
||||
private void handleCSCorrectShutdown() {
|
||||
pingMonitor.correctShutdown();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user