本文整理汇总了Java中org.vertx.java.core.eventbus.EventBus.send方法的典型用法代码示例。如果您正苦于以下问题:Java EventBus.send方法的具体用法?Java EventBus.send怎么用?Java EventBus.send使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.vertx.java.core.eventbus.EventBus
的用法示例。
在下文中一共展示了EventBus.send方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: gridfsReadFile
import org.vertx.java.core.eventbus.EventBus; //导入方法依赖的package包/类
public static void gridfsReadFile(String id, final EventBus eb,
final String gridfsAddress, final Handler<Buffer> handler) {
JsonObject find = new JsonObject();
find.putString("action", "findone");
find.putObject("query", new JsonObject("{ \"_id\": \"" + id + "\"}"));
byte [] header = null;
try {
header = find.toString().getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
handler.handle(new Buffer());
}
if (header != null) {
Buffer buf = new Buffer(header);
buf.appendInt(header.length);
eb.send(gridfsAddress, buf, new Handler<Message>() {
@Override
public void handle(Message res) {
if (res.body() instanceof Buffer) {
handler.handle((Buffer) res.body());
} else {
handler.handle(null);
}
}
});
}
}
示例2: gridfsCopyFile
import org.vertx.java.core.eventbus.EventBus; //导入方法依赖的package包/类
public static void gridfsCopyFile(String id, EventBus eb, String gridfsAddress,
final Handler<JsonObject> handler) {
JsonObject find = new JsonObject();
find.putString("action", "copy");
find.putObject("query", new JsonObject("{ \"_id\": \"" + id + "\"}"));
byte [] header = null;
try {
header = find.toString().getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
handler.handle(new JsonObject().putString("status", "error"));
}
if (header != null) {
Buffer buf = new Buffer(header);
buf.appendInt(header.length);
eb.send(gridfsAddress, buf, new Handler<Message<JsonObject>>() {
@Override
public void handle(Message<JsonObject> res) {
handler.handle(res.body());
}
});
}
}
示例3: call
import org.vertx.java.core.eventbus.EventBus; //导入方法依赖的package包/类
public static void call(
final EventBus eventBus,
final String address,
final AbstractCommand command) {
eventBus.send(address, command.toJson());
}
示例4: gridfsWriteBuffer
import org.vertx.java.core.eventbus.EventBus; //导入方法依赖的package包/类
private static void gridfsWriteBuffer(String id, Buffer buff, Long maxSize,
final Handler<JsonObject> handler, EventBus eb, String contentType,
String filename, final JsonObject m, final String gridfsAddress) {
JsonObject save = new JsonObject();
save.putString("action", "save");
save.putString("content-type", contentType);
save.putString("filename", filename);
if (id != null && !id.trim().isEmpty()) {
save.putString("_id", id);
}
final JsonObject metadata = (m != null) ? m : new JsonObject()
.putString("content-type", contentType)
.putString("filename", filename);
if (metadata.getLong("size", 0l).equals(0l)) {
metadata.putNumber("size", buff.length());
}
if (maxSize != null && maxSize < metadata.getLong("size", 0l)) {
handler.handle(new JsonObject().putString("status", "error")
.putString("message", "file.too.large"));
return;
}
byte [] header = null;
try {
header = save.toString().getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
JsonObject json = new JsonObject().putString("status", "error")
.putString("message", e.getMessage());
handler.handle(json);
}
if (header != null) {
buff.appendBytes(header).appendInt(header.length);
eb.send(gridfsAddress, buff, new Handler<Message<JsonObject>>() {
@Override
public void handle(Message<JsonObject> message) {
handler.handle(message.body()
.putObject("metadata", metadata));
}
});
}
}
示例5: gridfsRemoveFiles
import org.vertx.java.core.eventbus.EventBus; //导入方法依赖的package包/类
public static void gridfsRemoveFiles(JsonArray ids, EventBus eb, String gridfsAddress,
final Handler<JsonObject> handler) {
JsonObject find = new JsonObject();
find.putString("action", "remove");
JsonObject query = new JsonObject();
if (ids != null && ids.size() == 1) {
query.putString("_id", ids.<String>get(0));
} else {
query.putObject("_id", new JsonObject().putArray("$in", ids));
}
find.putObject("query", query);
byte [] header = null;
try {
header = find.toString().getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
handler.handle(new JsonObject().putString("status", "error"));
}
if (header != null) {
Buffer buf = new Buffer(header);
buf.appendInt(header.length);
eb.send(gridfsAddress, buf, new Handler<Message<JsonObject>>() {
@Override
public void handle(Message<JsonObject> res) {
if (handler != null) {
handler.handle(res.body());
}
}
});
}
}
示例6: sendStartup
import org.vertx.java.core.eventbus.EventBus; //导入方法依赖的package包/类
public static void sendStartup(final JsonObject app, JsonArray actions, final EventBus eb, final String address, final Vertx vertx,
final Handler<Message<JsonObject>> handler) throws IOException {
if (actions == null || actions.size() == 0) {
actions = loadSecuredActions(vertx);
}
JsonObject jo = new JsonObject();
jo.putObject("application", app)
.putArray("actions", actions);
eb.send(address, jo, new Handler<Message<JsonObject>>() {
public void handle(final Message<JsonObject> appEvent) {
if("error".equals(appEvent.body().getString("status"))){
log.error("Error registering application " + app.getString("name"));
if(handler != null) handler.handle(appEvent);
return;
}
final JsonArray widgetsArray = loadWidgets(app.getString("name"), vertx);
if(widgetsArray.size() == 0){
if(handler != null) handler.handle(appEvent);
return;
}
final JsonObject widgets = new JsonObject().putArray("widgets", widgetsArray);
eb.send(address+".widgets", widgets, new Handler<Message<JsonObject>>() {
public void handle(Message<JsonObject> event) {
if("error".equals(event.body().getString("status"))){
log.error("Error registering widgets for application " + app.getString("name"));
} else {
log.info("Successfully registered widgets for application " + app.getString("name"));
}
if(handler != null) handler.handle(appEvent);
}
});
}
});
}