private void uploadFile(final AsyncFile file, final String address, final Handler<AsyncResult<Void>> doneHandler) {
uploadFile(file, 0, address, doneHandler);
}
private void uploadFile(final AsyncFile file, final long position, final String address, final Handler<AsyncResult<Void>> doneHandler) {
Buffer buffer = new Buffer(4096);
file.read(buffer, 0, position, 4096, new Handler<AsyncResult<Buffer>>() {
@Override
public void handle(AsyncResult<Buffer> result) {
if (result.failed()) {
new DefaultFutureResult<Void>(result.cause()).setHandler(doneHandler);
} else {
final Buffer buffer = result.result();
vertx.eventBus().sendWithTimeout(address, buffer, 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")) {
if (buffer.length() > 0) {
uploadFile(file, position+buffer.length(), address, doneHandler);
} else {
new DefaultFutureResult<Void>((Void) null).setHandler(doneHandler);
}
}
}