本文整理汇总了Java中org.vertx.java.core.AsyncResultHandler类的典型用法代码示例。如果您正苦于以下问题:Java AsyncResultHandler类的具体用法?Java AsyncResultHandler怎么用?Java AsyncResultHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AsyncResultHandler类属于org.vertx.java.core包,在下文中一共展示了AsyncResultHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getInfo
import org.vertx.java.core.AsyncResultHandler; //导入依赖的package包/类
@Override
public void getInfo(final String fileId, final AsyncResultHandler<FileInfos> handler) {
final JsonObject query = new JsonObject().putString(mapping.getString("file", "file"), fileId);
mongo.findOne(collection, query, keys, new Handler<Message<JsonObject>>() {
@Override
public void handle(Message<JsonObject> event) {
if ("ok".equals(event.body().getString("status"))) {
JsonObject res = event.body().getObject("result");
if (res != null) {
final FileInfos fi = new FileInfos();
fi.setApplication(application);
fi.setId(fileId);
fi.setName(res.getString(mapping.getString("title", "title")));
fi.setOwner(res.getObject("owner", new JsonObject()).getString("userId"));
handler.handle(new DefaultAsyncResult<>(fi));
} else {
handler.handle(new DefaultAsyncResult<>((FileInfos) null));
}
} else {
handler.handle(new DefaultAsyncResult<FileInfos>(
new StorageException(event.body().getString("message"))));
}
}
});
}
示例2: getResidualRepositorySize
import org.vertx.java.core.AsyncResultHandler; //导入依赖的package包/类
private void getResidualRepositorySize(final Handler<Long> handler) {
storage.stats(new AsyncResultHandler<BucketStats>() {
@Override
public void handle(AsyncResult<BucketStats> event) {
Long residualRepositorySize = 0L;
if (event.succeeded()) {
final Long sizeUsed = event.result().getStorageSize();
final Long residualRepository = ShareBigFilesController.this.maxRepositoryQuota - sizeUsed;
residualRepositorySize = (residualRepository < 0) ? 0L : residualRepository;
} else {
log.error("Can't get the repository stats : ", event.cause());
}
handler.handle(residualRepositorySize);
}
});
}
示例3: testDeployment
import org.vertx.java.core.AsyncResultHandler; //导入依赖的package包/类
@Test
public void testDeployment() throws InterruptedException {
JsonObject config = createBaseConfig();
config.putString(CONF_KEY_LOCAL_ADDRESS, LOCAL_ADDRESS);
container.deployWorkerVerticle(Activator.class.getName(), config, 3, false,
new AsyncResultHandler<String>() {
@Override
public void handle(final AsyncResult<String> ar) {
if (ar.succeeded()) {
initActivator(ar.result());
} else {
m_logger.error("Failed to deploy verticle: {}", ar.cause());
Assert.fail();
}
}
}
);
vertx.setPeriodic(1500L, this); // Generate events once every 500 ms
}
示例4: handle
import org.vertx.java.core.AsyncResultHandler; //导入依赖的package包/类
@Override
public void handle(final Long timerId) {
final FileSystem fs = m_fileSystem;
final List<Path> paths = m_paths; // file paths
for (final Path path : paths) {
m_logger.trace("Inspecting file: {}", path);
// Check that file exists before proceeding further...
if (Files.exists(path)) {
fs.props(path.toString(), new AsyncResultHandler<FileProps>() {
@Override
public void handle(final AsyncResult<FileProps> ar) {
handleFileProps(ar, path);
}
});
}
}
}
示例5: testSqlView
import org.vertx.java.core.AsyncResultHandler; //导入依赖的package包/类
@Test
public void testSqlView() throws ResourceException {
vertx.eventBus().registerLocalHandler(FILTER_DEST_ADDRESS, this);
JsonObject config = createBaseConfig();
config.mergeIn(loadSqlConfig(config));
// Update interval (how often to read the database)
config.putNumber(CONF_KEY_UPDATE_INTERVAL, 500L);
m_logger.info("Update interval: {}", config.getLong(CONF_KEY_UPDATE_INTERVAL));
container.deployWorkerVerticle(Sql.class.getName(), config, 1, false,
new AsyncResultHandler<String>() {
@Override
public void handle(final AsyncResult<String> ar) {
if (ar.failed()) {
m_logger.error("Failed to deploy verticle", ar.cause());
Assert.fail();
}
}
});
}
示例6: execOutputCommand
import org.vertx.java.core.AsyncResultHandler; //导入依赖的package包/类
private void execOutputCommand(final JsonObject config) {
container.deployVerticle(Command.class.getName(), config, 1,
new AsyncResultHandler<String>() {
@Override
public void handle(final AsyncResult<String> ar) {
if (ar.succeeded()) {
// Emit event
JsonObject event = EventCreator.create("Command");
vertx.eventBus().publish(EVENT_SRC_ADDRESS, event);
//
// Stop test
//
VertxAssert.testComplete();
} else {
m_logger.error("Failed to deploy verticle", ar.cause());
Assert.fail();
}
}
});
}
示例7: testCommand
import org.vertx.java.core.AsyncResultHandler; //导入依赖的package包/类
@Test
public void testCommand() throws InterruptedException {
JsonObject config = new JsonObject();
config.putValue(CONF_KEY_HOME_PATH, ".");
config.putValue(CONF_KEY_CONF_PATH, ".");
config.putValue(CONF_KEY_DATA_PATH, ".");
config.putValue(CONF_KEY_TMP_PATH, ".");
config.putValue(CONF_KEY_LOCAL_ADDRESS, LOCAL_ADDRESS);
container.deployWorkerVerticle(Activator.class.getName(), config, 1, false,
new AsyncResultHandler<String>() {
@Override
public void handle(final AsyncResult<String> ar) {
if (ar.failed()) {
Assert.fail("Failed to deploy verticle: " + ar.cause());
} else {
initActivator(ar.result());
}
}
});
}
示例8: testActivator
import org.vertx.java.core.AsyncResultHandler; //导入依赖的package包/类
@Test
public void testActivator() {
JsonObject config = createBaseConfig();
container.deployWorkerVerticle(Activator.class.getName(), config, 1, false,
new AsyncResultHandler<String>() {
@Override
public void handle(final AsyncResult<String> ar) {
if (ar.succeeded()) {
// Stop test
VertxAssert.testComplete();
} else {
m_logger.error("Failed to deploy verticle", ar.cause());
Assert.fail();
}
}
});
}
示例9: run
import org.vertx.java.core.AsyncResultHandler; //导入依赖的package包/类
@Override
public void run(AsyncResultHandler<T> handler) {
ObjectWrapper<Integer> count = new ObjectWrapper<>(0);
FunctionWrapper<Runnable> visitor = new FunctionWrapper<>();
visitor.wrap(() -> task.accept(result -> {
if (result.failed()) {
count.setObject(count.getObject() + 1);
if (count.getObject() > times) {
handler.handle(DefaultAsyncResult.fail(result));
return;
}
visitor.f().run();
return;
}
handler.handle(DefaultAsyncResult.succeed(result.result()));
}));
visitor.f().run();
}
示例10: retryExample
import org.vertx.java.core.AsyncResultHandler; //导入依赖的package包/类
public void retryExample(AsyncResultHandler<String> handler) {
Async.retry()
.<String>task(taskHandler -> {
someAsyncMethodThatTakesAHandler(taskHandler);
})
.times(5)
.run(result -> {
if (result.failed()) {
handler.handle(DefaultAsyncResult.fail(result));
return;
}
String resultValue = result.result();
doSomethingWithTheResults(resultValue);
handler.handle(DefaultAsyncResult.succeed(resultValue));
});
}
示例11: waterfallExample
import org.vertx.java.core.AsyncResultHandler; //导入依赖的package包/类
public void waterfallExample(AsyncResultHandler<Integer> handler) {
Async.waterfall()
.<String>task(taskHandler -> {
String result = getSomeResult();
taskHandler.handle(DefaultAsyncResult.succeed(result));
})
.<Integer>task((result, taskHandler) -> {
someAsyncMethodThatTakesAResultAndHandler(result, taskHandler);
})
.run(result -> {
if (result.failed()) {
handler.handle(DefaultAsyncResult.fail(result.cause()));
return;
}
Integer resultValue = result.result();
doSomethingWithTheResults(resultValue);
handler.handle(DefaultAsyncResult.succeed(resultValue));
});
}
示例12: seriesExample
import org.vertx.java.core.AsyncResultHandler; //导入依赖的package包/类
public void seriesExample(AsyncResultHandler<List<String>> handler) {
Async.<String>series()
.task(taskHandler -> {
String result = getSomeResult();
taskHandler.handle(DefaultAsyncResult.succeed(result));
})
.task(taskHandler -> {
someAsyncMethodThatTakesAHandler(taskHandler);
})
.run(result -> {
if (result.failed()) {
handler.handle(DefaultAsyncResult.fail(result));
return;
}
List<String> resultList = result.result();
doSomethingWithTheResults(resultList);
handler.handle(DefaultAsyncResult.succeed(resultList));
});
}
示例13: start
import org.vertx.java.core.AsyncResultHandler; //导入依赖的package包/类
@Override
public void start(final Future<Void> startedResult) {
container.deployVerticle("net.zyclonite.vertx.NetSocketVerticle", new AsyncResultHandler<String>() {
public void handle(AsyncResult<String> deployResult) {
if (deployResult.succeeded()) {
startedResult.setResult(null);
} else {
startedResult.setFailure(deployResult.cause());
}
}
});
container.deployVerticle("net.zyclonite.vertx.HttpVerticle");
container.deployVerticle("net.zyclonite.vertx.WebSocketVerticle");
container.deployVerticle("JavaScriptVerticle.js");
container.deployVerticle("ClosureVerticle.clj");
}
示例14: read
import org.vertx.java.core.AsyncResultHandler; //导入依赖的package包/类
@Override
public void read(String src, final Handler<ImageFile> handler) {
String [] path = parsePath(src);
if (path == null || path.length != 2) {
handler.handle(null);
return;
}
client.readFile(path[1], path[0], new AsyncResultHandler<StorageObject>() {
@Override
public void handle(AsyncResult<StorageObject> event) {
if (event.succeeded()) {
StorageObject f = event.result();
handler.handle(new ImageFile(
f.getBuffer().getBytes(),
f.getFilename(),
f.getContentType()
));
} else {
handler.handle(null);
}
}
});
}
示例15: write
import org.vertx.java.core.AsyncResultHandler; //导入依赖的package包/类
@Override
public void write(String dest, ImageFile img, final Handler<String> handler) {
String [] path = parsePath(dest);
if (path == null || path.length < 1) {
handler.handle(null);
return;
}
StorageObject o;
if (path.length == 2 && path[1] != null && !path[1].trim().isEmpty()) {
o = new StorageObject(path[1], new Buffer(img.getData()),
img.getFilename(), img.getContentType());
} else {
o = new StorageObject(new Buffer(img.getData()),
img.getFilename(), img.getContentType());
}
client.writeFile(o, path[0], new AsyncResultHandler<String>() {
@Override
public void handle(AsyncResult<String> event) {
if (event.succeeded()) {
handler.handle(event.result());
} else {
handler.handle(null);
}
}
});
}