forked from SteamWar/SteamWar
Implement proper stop and not sleep on BauCommand.stop
This commit is contained in:
@@ -80,7 +80,7 @@ public class Subserver {
|
|||||||
static void shutdown() {
|
static void shutdown() {
|
||||||
while (!serverList.isEmpty()) {
|
while (!serverList.isEmpty()) {
|
||||||
Subserver server = serverList.get(0);
|
Subserver server = serverList.get(0);
|
||||||
server.stop();
|
server.sleep();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,7 +138,7 @@ public class Subserver {
|
|||||||
writer.println(command);
|
writer.println(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop() {
|
public void sleep() {
|
||||||
try {
|
try {
|
||||||
long pid = process.pid();
|
long pid = process.pid();
|
||||||
if (checkpoint) {
|
if (checkpoint) {
|
||||||
@@ -152,9 +152,32 @@ public class Subserver {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (!process.waitFor(1, TimeUnit.MINUTES)) {
|
if (!process.waitFor(1, TimeUnit.MINUTES)) {
|
||||||
|
forceStop();
|
||||||
|
}
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
logger.log(Level.SEVERE, "Subserver stop interrupted!", e);
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stop() {
|
||||||
|
try {
|
||||||
|
process.destroy();
|
||||||
|
if (!process.waitFor(1, TimeUnit.MINUTES)) {
|
||||||
|
forceStop();
|
||||||
|
} else if (thread.isAlive()) {
|
||||||
|
thread.join();
|
||||||
|
}
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
logger.log(Level.SEVERE, "Subserver stop interrupted!", e);
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void forceStop() {
|
||||||
|
try {
|
||||||
logger.log(Level.SEVERE, () -> serverName + " did not stop correctly, forcibly stopping!");
|
logger.log(Level.SEVERE, () -> serverName + " did not stop correctly, forcibly stopping!");
|
||||||
process.destroyForcibly();
|
process.destroyForcibly();
|
||||||
}
|
|
||||||
|
|
||||||
if (thread.isAlive()) thread.join();
|
if (thread.isAlive()) thread.join();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
@@ -196,7 +219,7 @@ public class Subserver {
|
|||||||
protected void register() {
|
protected void register() {
|
||||||
if (Persistent.getInstance().getProxy().getServer(serverName).isPresent()) {
|
if (Persistent.getInstance().getProxy().getServer(serverName).isPresent()) {
|
||||||
SecurityException e = new SecurityException("Server already registered: " + serverName);
|
SecurityException e = new SecurityException("Server already registered: " + serverName);
|
||||||
stop();
|
sleep();
|
||||||
failureCallback.accept(e);
|
failureCallback.accept(e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -213,7 +213,7 @@ public class ServerStarter {
|
|||||||
if (startingBau(owner)) return false;
|
if (startingBau(owner)) return false;
|
||||||
|
|
||||||
Bauserver subserver = Bauserver.get(owner.getUniqueId());
|
Bauserver subserver = Bauserver.get(owner.getUniqueId());
|
||||||
if (subserver != null && subserver.isStarted()) subserver.stop();
|
if (subserver != null && subserver.isStarted()) subserver.sleep();
|
||||||
|
|
||||||
return !startingBau(owner);
|
return !startingBau(owner);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user