use of io.vertx.core.Context in project vert.x by eclipse.
the class DnsResolverProvider method close.
@Override
public void close(Handler<Void> doneHandler) {
Context context = vertx.getOrCreateContext();
ResolverRegistration[] registrations = this.resolvers.toArray(new ResolverRegistration[this.resolvers.size()]);
if (registrations.length == 0) {
context.runOnContext(doneHandler);
return;
}
AtomicInteger count = new AtomicInteger(registrations.length);
for (ResolverRegistration registration : registrations) {
Runnable task = () -> {
registration.resolver.close();
if (count.decrementAndGet() == 0) {
context.runOnContext(doneHandler);
}
};
if (registration.executor.inEventLoop()) {
task.run();
} else {
registration.executor.execute(task);
}
}
}
use of io.vertx.core.Context in project vert.x by eclipse.
the class AsynchronousCounter method getAndAdd.
@Override
public void getAndAdd(long value, Handler<AsyncResult<Long>> resultHandler) {
Objects.requireNonNull(resultHandler, "resultHandler");
Context context = vertx.getOrCreateContext();
context.runOnContext(v -> resultHandler.handle(Future.succeededFuture(counter.getAndAdd(value))));
}
use of io.vertx.core.Context in project vert.x by eclipse.
the class AsynchronousCounter method compareAndSet.
@Override
public void compareAndSet(long expected, long value, Handler<AsyncResult<Boolean>> resultHandler) {
Objects.requireNonNull(resultHandler, "resultHandler");
Context context = vertx.getOrCreateContext();
context.runOnContext(v -> resultHandler.handle(Future.succeededFuture(counter.compareAndSet(expected, value))));
}
use of io.vertx.core.Context in project vert.x by eclipse.
the class AsynchronousCounter method get.
@Override
public void get(Handler<AsyncResult<Long>> resultHandler) {
Objects.requireNonNull(resultHandler, "resultHandler");
Context context = vertx.getOrCreateContext();
context.runOnContext(v -> resultHandler.handle(Future.succeededFuture(counter.get())));
}
use of io.vertx.core.Context in project vert.x by eclipse.
the class AsynchronousCounter method addAndGet.
@Override
public void addAndGet(long value, Handler<AsyncResult<Long>> resultHandler) {
Objects.requireNonNull(resultHandler, "resultHandler");
Context context = vertx.getOrCreateContext();
context.runOnContext(v -> resultHandler.handle(Future.succeededFuture(counter.addAndGet(value))));
}
Aggregations