.putString("module", moduleName);
vertx.eventBus().sendWithTimeout(address, message, DEFAULT_REPLY_TIMEOUT, new Handler<AsyncResult<Message<JsonObject>>>() {
@Override
public void handle(AsyncResult<Message<JsonObject>> result) {
if (result.failed()) {
new DefaultFutureResult<Void>(new ClusterException(result.cause())).setHandler(doneHandler);
} else if (result.result().body().getString("status").equals("error")) {
new DefaultFutureResult<Void>(new ClusterException(result.result().body().getString("message"))).setHandler(doneHandler);
} else if (result.result().body().getBoolean("result", false)) {
new DefaultFutureResult<Void>((Void) null).setHandler(doneHandler);
} else {
// If we've made it this far then the module is not already installed on the node.
// First we need to zip up the module from the local platform.
platform.zipModule(moduleName, new Handler<AsyncResult<String>>() {
@Override
public void handle(AsyncResult<String> result) {
if (result.failed()) {
new DefaultFutureResult<Void>(result.cause()).setHandler(doneHandler);
} else {
// now that the module has been zipped, open the zipped file.
final String zipFile = result.result();
vertx.fileSystem().open(zipFile, new Handler<AsyncResult<AsyncFile>>() {
@Override
public void handle(AsyncResult<AsyncFile> result) {
if (result.failed()) {
new DefaultFutureResult<Void>(result.cause()).setHandler(doneHandler);
} else {
// Send a message to the node telling it we're going to upload the module.
final AsyncFile file = result.result();
JsonObject message = new JsonObject()
.putString("action", "upload");
vertx.eventBus().sendWithTimeout(address, message, DEFAULT_REPLY_TIMEOUT, new Handler<AsyncResult<Message<JsonObject>>>() {
@Override
public void handle(AsyncResult<Message<JsonObject>> result) {
if (result.failed()) {
new DefaultFutureResult<Void>(new ClusterException(result.cause())).setHandler(doneHandler);
} else if (result.result().body().getString("status").equals("error")) {
new DefaultFutureResult<Void>(new ClusterException(result.result().body().getString("message"))).setHandler(doneHandler);
} else if (result.result().body().getString("status").equals("ok")) {
final String id = result.result().body().getString("id");
uploadFile(file, id, new Handler<AsyncResult<Void>>() {
@Override
public void handle(AsyncResult<Void> result) {
if (result.failed()) {
new DefaultFutureResult<Void>(result.cause()).setHandler(doneHandler);
} else {
// Now that the file has been uploaded we can tell the node to install the module.
JsonObject message = new JsonObject()
.putString("action", "install")
.putString("type", "module")
.putString("module", moduleName)
.putString("upload", id);
vertx.eventBus().sendWithTimeout(address, message, DEFAULT_REPLY_TIMEOUT, new Handler<AsyncResult<Message<JsonObject>>>() {
@Override
public void handle(AsyncResult<Message<JsonObject>> result) {
if (result.failed()) {
new DefaultFutureResult<Void>(new ClusterException(result.cause())).setHandler(doneHandler);
} else if (result.result().body().getString("status").equals("error")) {
new DefaultFutureResult<Void>(new ClusterException(result.result().body().getString("message"))).setHandler(doneHandler);
} else if (result.result().body().getString("status").equals("ok")) {
new DefaultFutureResult<Void>((Void) null).setHandler(doneHandler);
}
}
});