Fix the readInputLoop so that messages are all delivered and processed in the main thread

This commit is contained in:
Guillaume Nodet
2020-11-12 00:18:06 +01:00
parent e397627376
commit d44e3201e0
5 changed files with 27 additions and 5 deletions

View File

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

View File

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