25 lines
863 B
Java
25 lines
863 B
Java
void main() throws Exception {
|
|
try (var subscriptions = new FileSubscriptions()) {
|
|
var controlMailbox = "consoleOut/inbox";
|
|
String textMailbox = null;
|
|
subscriptions.subscribe(controlMailbox);
|
|
|
|
while (true) {
|
|
var incoming = subscriptions.take();
|
|
var message = incoming.message();
|
|
|
|
if (incoming.mailbox().equals(controlMailbox)
|
|
&& message.type().equals("TOPIC")) {
|
|
if (textMailbox != null)
|
|
subscriptions.unsubscribe(textMailbox);
|
|
|
|
textMailbox = message.value();
|
|
subscriptions.subscribe(textMailbox);
|
|
IO.println("ConsoleOut now listens to " + textMailbox);
|
|
} else if (message.type().equals("TEXT")) {
|
|
IO.println(message.value());
|
|
}
|
|
}
|
|
}
|
|
}
|