Avoid possible class loading deadlock

This commit is contained in:
Guillaume Nodet
2021-02-12 09:25:34 +01:00
parent e2a419a870
commit 28de1df47d
4 changed files with 11 additions and 11 deletions

View File

@@ -55,10 +55,6 @@ public abstract class Message {
public static final int TRANSFER_SUCCEEDED = 21; public static final int TRANSFER_SUCCEEDED = 21;
public static final int TRANSFER_FAILED = 22; public static final int TRANSFER_FAILED = 22;
public static final BareMessage KEEP_ALIVE_SINGLETON = new BareMessage(KEEP_ALIVE);
public static final BareMessage STOP_SINGLETON = new BareMessage(STOP);
public static final BareMessage CANCEL_BUILD_SINGLETON = new BareMessage(CANCEL_BUILD);
final int type; final int type;
Message(int type) { Message(int type) {
@@ -588,6 +584,10 @@ public abstract class Message {
public static class BareMessage extends Message { public static class BareMessage extends Message {
public static final BareMessage KEEP_ALIVE_SINGLETON = new BareMessage(KEEP_ALIVE);
public static final BareMessage STOP_SINGLETON = new BareMessage(STOP);
public static final BareMessage CANCEL_BUILD_SINGLETON = new BareMessage(CANCEL_BUILD);
private BareMessage(int type) { private BareMessage(int type) {
super(type); super(type);
} }

View File

@@ -152,12 +152,12 @@ public class TerminalOutput implements ClientOutput {
terminal.enterRawMode(); terminal.enterRawMode();
Thread mainThread = Thread.currentThread(); Thread mainThread = Thread.currentThread();
daemonDispatch = m -> { daemonDispatch = m -> {
if (m == Message.CANCEL_BUILD_SINGLETON) { if (m == Message.BareMessage.CANCEL_BUILD_SINGLETON) {
mainThread.interrupt(); mainThread.interrupt();
} }
}; };
this.previousIntHandler = terminal.handle(Terminal.Signal.INT, this.previousIntHandler = terminal.handle(Terminal.Signal.INT,
sig -> daemonDispatch.accept(Message.CANCEL_BUILD_SINGLETON)); sig -> daemonDispatch.accept(Message.BareMessage.CANCEL_BUILD_SINGLETON));
this.display = new Display(terminal, false); this.display = new Display(terminal, false);
this.log = logFile == null ? new MessageCollector() : new FileLog(logFile); this.log = logFile == null ? new MessageCollector() : new FileLog(logFile);
if (!dumb) { if (!dumb) {

View File

@@ -103,12 +103,12 @@ public class ClientDispatcher extends BuildEventListener {
public void finish(int exitCode) throws Exception { public void finish(int exitCode) throws Exception {
queue.add(new Message.BuildFinished(exitCode)); queue.add(new Message.BuildFinished(exitCode));
queue.add(Message.STOP_SINGLETON); queue.add(Message.BareMessage.STOP_SINGLETON);
} }
public void fail(Throwable t) throws Exception { public void fail(Throwable t) throws Exception {
queue.add(new BuildException(t)); queue.add(new BuildException(t));
queue.add(Message.STOP_SINGLETON); queue.add(Message.BareMessage.STOP_SINGLETON);
} }
public void log(String msg) { public void log(String msg) {

View File

@@ -440,7 +440,7 @@ public class Server implements AutoCloseable, Runnable {
if (flushed) { if (flushed) {
m = sendQueue.poll(keepAliveMs, TimeUnit.MILLISECONDS); m = sendQueue.poll(keepAliveMs, TimeUnit.MILLISECONDS);
if (m == null) { if (m == null) {
m = Message.KEEP_ALIVE_SINGLETON; m = Message.BareMessage.KEEP_ALIVE_SINGLETON;
} }
flushed = false; flushed = false;
} else { } else {
@@ -451,7 +451,7 @@ public class Server implements AutoCloseable, Runnable {
continue; continue;
} }
} }
if (m == Message.STOP_SINGLETON) { if (m == Message.BareMessage.STOP_SINGLETON) {
connection.flush(); connection.flush();
LOGGER.info("No more message to dispatch"); LOGGER.info("No more message to dispatch");
return; return;
@@ -472,7 +472,7 @@ public class Server implements AutoCloseable, Runnable {
break; break;
} }
LOGGER.info("Received message: {}", message); LOGGER.info("Received message: {}", message);
if (message == Message.CANCEL_BUILD_SINGLETON) { if (message == Message.BareMessage.CANCEL_BUILD_SINGLETON) {
updateState(DaemonState.Canceled); updateState(DaemonState.Canceled);
return; return;
} else { } else {