![JAR search and dependency download from the Maven repository](/logo.png)
crash.commands.vertx.bus.groovy Maven / Gradle / Ivy
package crash.commands.vertx
import org.crsh.cli.Argument
import org.crsh.cli.Command
import org.crsh.cli.Option
import org.crsh.cli.Required
import org.crsh.cli.Usage
import org.vertx.java.core.Handler
import org.vertx.java.core.eventbus.EventBus
import org.vertx.java.core.eventbus.Message
import org.vertx.mods.Format
import org.vertx.mods.VertxCommand
import java.util.concurrent.atomic.AtomicReference
@Usage("interact with the vert.x event bus")
public class bus extends VertxCommand {
@Usage("send a message on the bus")
@Command
public void send(
@Usage("the address to send to")
@Argument(name = "address")
@Required String address,
@Usage("the message format")
@Option(names = ["f","format"])
Format format,
@Usage("wait for a reply and publish it on the console")
@Option(names= ["r","reply"])
Boolean reply,
@Usage("the message")
@Argument(name = "message", unquote = false)
@Required List parts) {
String value = join(parts);
EventBus bus = getVertx().eventBus();
if (reply) {
final AtomicReference responseRef = new AtomicReference(null);
def replyHandler = new Handler>() {
void handle(Message message) {
synchronized (responseRef) {
responseRef.set(message);
responseRef.notifyAll();
}
}
}
(format?:Format.STRING).send(bus, address, value, replyHandler);
synchronized (responseRef) {
if (responseRef.get() == null) {
try {
responseRef.wait();
}
catch (InterruptedException cancelled) {
}
}
}
if (responseRef.get() != null) {
Message
© 2015 - 2025 Weber Informatics LLC | Privacy Policy