mirror of
https://github.com/apache/maven-mvnd.git
synced 2025-09-26 05:58:27 +00:00
Fix the readInputLoop so that messages are all delivered and processed in the main thread
This commit is contained in:
@@ -129,6 +129,14 @@ public class DaemonClientConnection implements Closeable {
|
||||
}
|
||||
}
|
||||
|
||||
public void enqueue(Message message) {
|
||||
try {
|
||||
queue.put(message);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected void doReceive() {
|
||||
try {
|
||||
while (running.get()) {
|
||||
|
@@ -199,7 +199,8 @@ public class DefaultClient implements Client {
|
||||
|
||||
final DaemonConnector connector = new DaemonConnector(parameters, registry);
|
||||
try (DaemonClientConnection daemon = connector.connect(output)) {
|
||||
output.setDeamonDispatch(daemon::dispatch);
|
||||
output.setDaemonDispatch(daemon::dispatch);
|
||||
output.setDaemonReceive(daemon::enqueue);
|
||||
output.accept(Message.buildStatus("Connected to daemon"));
|
||||
|
||||
daemon.dispatch(new Message.BuildRequest(
|
||||
|
@@ -24,7 +24,9 @@ import org.jboss.fuse.mvnd.common.Message;
|
||||
*/
|
||||
public interface ClientOutput extends AutoCloseable {
|
||||
|
||||
void setDeamonDispatch(Consumer<Message> sink);
|
||||
void setDaemonDispatch(Consumer<Message> sink);
|
||||
|
||||
void setDaemonReceive(Consumer<Message> sink);
|
||||
|
||||
void accept(Message message);
|
||||
|
||||
|
@@ -69,6 +69,8 @@ public class TerminalOutput implements ClientOutput {
|
||||
|
||||
/** A sink for sending messages back to the daemon */
|
||||
private volatile Consumer<Message> daemonDispatch;
|
||||
/** A sink for queuing messages to the main queue */
|
||||
private volatile Consumer<Message> daemonReceive;
|
||||
|
||||
/*
|
||||
* The following non-final fields are read/written from the main thread only.
|
||||
@@ -131,10 +133,15 @@ public class TerminalOutput implements ClientOutput {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDeamonDispatch(Consumer<Message> daemonDispatch) {
|
||||
public void setDaemonDispatch(Consumer<Message> daemonDispatch) {
|
||||
this.daemonDispatch = daemonDispatch;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDaemonReceive(Consumer<Message> daemonReceive) {
|
||||
this.daemonReceive = daemonReceive;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(Message entry) {
|
||||
assert "main".equals(Thread.currentThread().getName());
|
||||
@@ -356,7 +363,7 @@ public class TerminalOutput implements ClientOutput {
|
||||
break;
|
||||
}
|
||||
if (c == '+' || c == '-' || c == CTRL_L || c == CTRL_M || c == CTRL_B) {
|
||||
accept(Message.keyboardInput((char) c));
|
||||
daemonReceive.accept(Message.keyboardInput((char) c));
|
||||
}
|
||||
readInput.readLock().unlock();
|
||||
}
|
||||
|
@@ -32,10 +32,14 @@ public class TestClientOutput implements ClientOutput {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDeamonDispatch(Consumer<Message> daemonDispatch) {
|
||||
public void setDaemonDispatch(Consumer<Message> daemonDispatch) {
|
||||
this.daemonDispatch = daemonDispatch;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDaemonReceive(Consumer<Message> sink) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(Message message) {
|
||||
messages.add(message);
|
||||
|
Reference in New Issue
Block a user