Archived
0

Zond:fix: стабилизация работы модуля в целом

This commit is contained in:
2017-07-23 00:30:42 +03:00
parent 883c4f1257
commit a4f1d78c2e
13 changed files with 92 additions and 30 deletions

View File

@@ -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/' }

View File

@@ -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();

View File

@@ -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) {

View File

@@ -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;

View File

@@ -12,6 +12,7 @@ public interface IBridge {
void startReconnect();
boolean isNeedReconnect();
void setNeedReconnect(boolean value);
void sendCorrectShutdownPacket();
void stopReconnect();
void startPing();
void stopPing();

View File

@@ -1,5 +1,5 @@
group = 'asys'
version = '0.5-SNAPSHOT'
version = '0.6-SNAPSHOT'
task jar(type: Jar, overwrite: true) {
// не собирать jar

View File

@@ -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) {
}
}

View File

@@ -1,5 +1,5 @@
group = 'asys'
version = '0.7.12-SNAPSHOT'
version = '0.7.13-SNAPSHOT'
apply plugin: 'application'

View File

@@ -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() {
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;
}
}

View File

@@ -94,6 +94,9 @@ public class PipeInputStream extends InputStream {
public void open() {
closed = false;
lastWritePos = 0;
lastReadPos = 0;
wallPos = buffer.length-1;
}
@Override

View File

@@ -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.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,10 +110,10 @@ 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) {
if (!pingMonitor.isCorrectShutdown()) {
if (System.currentTimeMillis() <= deadTime && !flagManualKill) {
Shell.getInstance().getOutput().println("[!] Premature end process.");
_try++;
if (_try < 2) {
@@ -120,12 +122,17 @@ public class ZondCommandHandler implements CommandHandler {
} else if (flagForceRestartProcess) {
_try = 0;
flagForceRestartProcess = false;
} else if (code != 0 && code != -99) {
} else if (code != 0 && code != -99 && !flagManualKill) {
Shell.getInstance().getOutput().println("[!] Try start process again...");
_try = 0;
} else {
break;
}
} else {
flagForceRestartProcess = false;
_try = 0;
break;
}
} while (_try < 2);
if (_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();
}

View File

@@ -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();
}

View File

@@ -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();
}
}