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' group = 'asys'
version = '0.8.1-SNAPSHOT' version = '0.8.2-SNAPSHOT'
repositories { repositories {
maven { url 'https://hub.spigotmc.org/nexus/content/groups/public/' } maven { url 'https://hub.spigotmc.org/nexus/content/groups/public/' }

View File

@@ -25,6 +25,7 @@ public class BridgePlugin extends JavaPlugin {
@Override @Override
public void onDisable() { public void onDisable() {
this.bridgeBukkit.sendCorrectShutdownPacket();
this.bridgeBukkit.setNeedReconnect(false); this.bridgeBukkit.setNeedReconnect(false);
this.bridgeBukkit.stopPing(); this.bridgeBukkit.stopPing();
this.bridgeBukkit.stopReconnect(); this.bridgeBukkit.stopReconnect();

View File

@@ -5,8 +5,8 @@
package asys.bridge.client; package asys.bridge.client;
import asys.bridge.bukkit.TaskTicker; import asys.bridge.bukkit.TaskTicker;
import asys.mcsmanager.packets.CS_CorrectShutdown;
import asys.mcsmanager.packets.CS_Ping; import asys.mcsmanager.packets.CS_Ping;
import io.netty.channel.Channel;
public abstract class AbstractBridge implements IBridge { public abstract class AbstractBridge implements IBridge {
private Client client; private Client client;
@@ -39,6 +39,13 @@ public abstract class AbstractBridge implements IBridge {
this.needReconnect = value; this.needReconnect = value;
} }
@Override
public void sendCorrectShutdownPacket() {
if (client != null && client.isConnected()) {
client.sendPacket(new CS_CorrectShutdown());
}
}
@Override @Override
public void stopReconnect() { public void stopReconnect() {
if (connectTicker != null) { 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( private static final BiMap<Integer, Class<? extends Packet>> knownPackets = ImmutableBiMap.of(
3, CS_Ping.class, 3, CS_Ping.class,
5, SC_Command.class 5, SC_Command.class,
6, CS_CorrectShutdown.class
); );
private IBridge bridge; private IBridge bridge;

View File

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

View File

@@ -1,5 +1,5 @@
group = 'asys' group = 'asys'
version = '0.5-SNAPSHOT' version = '0.6-SNAPSHOT'
task jar(type: Jar, overwrite: true) { task jar(type: Jar, overwrite: true) {
// не собирать jar // не собирать 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' group = 'asys'
version = '0.7.12-SNAPSHOT' version = '0.7.13-SNAPSHOT'
apply plugin: 'application' apply plugin: 'application'

View File

@@ -7,6 +7,7 @@ public class PingMonitor {
private final long delayStart; private final long delayStart;
private long lastPingTime; private long lastPingTime;
private Thread threadPingMon; private Thread threadPingMon;
private boolean correctShutdown = false;
public PingMonitor(long delayStart) { public PingMonitor(long delayStart) {
this.delayStart = delayStart; this.delayStart = delayStart;
@@ -14,6 +15,7 @@ public class PingMonitor {
public void start(final Runnable callback) { public void start(final Runnable callback) {
this.threadPingMon = new Thread(() -> { this.threadPingMon = new Thread(() -> {
correctShutdown = false;
try { try {
Thread.sleep(delayStart); Thread.sleep(delayStart);
} catch (InterruptedException e) { } catch (InterruptedException e) {
@@ -40,12 +42,21 @@ public class PingMonitor {
} }
public void stop() { public void stop() {
if (threadPingMon != null) {
threadPingMon.interrupt(); threadPingMon.interrupt();
threadPingMon = null; threadPingMon = null;
} }
}
public void checkPing() { public void checkPing() {
lastPingTime = System.currentTimeMillis(); 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() { public void open() {
closed = false; closed = false;
lastWritePos = 0;
lastReadPos = 0;
wallPos = buffer.length-1;
} }
@Override @Override

View File

@@ -24,6 +24,7 @@ public class ZondCommandHandler implements CommandHandler {
private PipeInputStream proxyStdIn; private PipeInputStream proxyStdIn;
private PingMonitor pingMonitor; private PingMonitor pingMonitor;
private boolean flagForceRestartProcess = false; private boolean flagForceRestartProcess = false;
private boolean flagManualKill = false;
ZondCommandHandler(PipeInputStream proxyStdIn) { ZondCommandHandler(PipeInputStream proxyStdIn) {
this.proxyStdIn = proxyStdIn; this.proxyStdIn = proxyStdIn;
@@ -41,16 +42,14 @@ public class ZondCommandHandler implements CommandHandler {
private void internalCommand(String line) { private void internalCommand(String line) {
if (line.equalsIgnoreCase("exit") || line.equalsIgnoreCase("quit")) { if (line.equalsIgnoreCase("exit") || line.equalsIgnoreCase("quit")) {
if (watchdog != null) { flagManualKill = true;
server.shutdown(); killProcess();
watchdog.destroyProcess();
threadExec.interrupt();
}
Connector.getInstance().shutdown(); Connector.getInstance().shutdown();
Shell.getInstance().shutdown(); Shell.getInstance().shutdown();
} else if (line.equalsIgnoreCase("start")) { } else if (line.equalsIgnoreCase("start")) {
startProcess(); startProcess();
} else if (line.equalsIgnoreCase("kill")) { } else if (line.equalsIgnoreCase("kill")) {
flagManualKill = true;
killProcess(); killProcess();
} else if (line.equalsIgnoreCase("connect")) { } else if (line.equalsIgnoreCase("connect")) {
Connector.getInstance().startReconnect(); Connector.getInstance().startReconnect();
@@ -73,11 +72,14 @@ public class ZondCommandHandler implements CommandHandler {
} }
private void startProcess() { private void startProcess() {
if (watchdog == null || !watchdog.isWatching()) {
if (watchdog == null) { if (watchdog == null) {
watchdog = new ZondExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT, proxyStdIn); watchdog = new ZondExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT, proxyStdIn);
executor.setWatchdog(watchdog); executor.setWatchdog(watchdog);
}
final long delay = Config.getInstance().getLong("pingmonitor.delay"); final long delay = Config.getInstance().getLong("pingmonitor.delay");
pingMonitor = new PingMonitor(delay); pingMonitor = new PingMonitor(delay);
flagManualKill = false;
Runnable task = () -> { Runnable task = () -> {
short _try = 0; short _try = 0;
@@ -108,10 +110,10 @@ public class ZondCommandHandler implements CommandHandler {
server.shutdown(); server.shutdown();
pingMonitor.stop(); pingMonitor.stop();
server = null; server = null;
watchdog = null;
Shell.getInstance().getOutput().println("Process finished. Code: " + code); 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."); Shell.getInstance().getOutput().println("[!] Premature end process.");
_try++; _try++;
if (_try < 2) { if (_try < 2) {
@@ -120,12 +122,17 @@ public class ZondCommandHandler implements CommandHandler {
} else if (flagForceRestartProcess) { } else if (flagForceRestartProcess) {
_try = 0; _try = 0;
flagForceRestartProcess = false; flagForceRestartProcess = false;
} else if (code != 0 && code != -99) { } else if (code != 0 && code != -99 && !flagManualKill) {
Shell.getInstance().getOutput().println("[!] Try start process again..."); Shell.getInstance().getOutput().println("[!] Try start process again...");
_try = 0; _try = 0;
} else { } else {
break; break;
} }
} else {
flagForceRestartProcess = false;
_try = 0;
break;
}
} while (_try < 2); } while (_try < 2);
if (_try == 2) { if (_try == 2) {
@@ -138,8 +145,9 @@ public class ZondCommandHandler implements CommandHandler {
} }
private void killProcess() { private void killProcess() {
if (watchdog != null) { if (watchdog != null && watchdog.isWatching()) {
server.shutdown(); server.shutdown();
pingMonitor.stop();
watchdog.destroyProcess(); watchdog.destroyProcess();
threadExec.interrupt(); threadExec.interrupt();
} }

View File

@@ -12,6 +12,11 @@ public class ZondExecuteWatchdog extends ExecuteWatchdog {
public ZondExecuteWatchdog(long timeout, PipeInputStream inputStream) { public ZondExecuteWatchdog(long timeout, PipeInputStream inputStream) {
super(timeout); super(timeout);
this.inputStream = inputStream; this.inputStream = inputStream;
}
@Override
public synchronized void start(Process processToMonitor) {
super.start(processToMonitor);
inputStream.open(); inputStream.open();
} }

View File

@@ -27,11 +27,13 @@ public class ServerPacketHandler extends ChannelInboundHandlerAdapter implements
this.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,
6, CS_CorrectShutdown.class
); );
knownHandlers = ImmutableMap.of( knownHandlers = ImmutableMap.of(
CS_Ping.class, this, 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) { public void handle(Packet packet, ChannelHandlerContext context) {
if (packet instanceof CS_Ping) { if (packet instanceof CS_Ping) {
handleCSPing((CS_Ping) packet); handleCSPing((CS_Ping) packet);
} else if (packet instanceof CS_CorrectShutdown) {
handleCSCorrectShutdown();
} }
} }
@@ -58,4 +62,8 @@ public class ServerPacketHandler extends ChannelInboundHandlerAdapter implements
pingMonitor.checkPing(); pingMonitor.checkPing();
Connector.getInstance().sendPacket(packet); Connector.getInstance().sendPacket(packet);
} }
private void handleCSCorrectShutdown() {
pingMonitor.correctShutdown();
}
} }