use of io.vertx.core.impl.future.PromiseInternal in project vert.x by eclipse.
the class Http2ConnectionBase method close.
@Override
public Future<Void> close() {
PromiseInternal<Void> promise = context.promise();
ChannelPromise pr = chctx.newPromise();
ChannelPromise channelPromise = pr.addListener(promise);
handlerContext.writeAndFlush(Unpooled.EMPTY_BUFFER, pr);
channelPromise.addListener((ChannelFutureListener) future -> shutdown(0L));
return promise.future();
}
use of io.vertx.core.impl.future.PromiseInternal in project vert.x by eclipse.
the class DatagramSocketImpl method listen.
private Future<DatagramSocket> listen(SocketAddress local) {
AddressResolver resolver = context.owner().addressResolver();
PromiseInternal<Void> promise = context.promise();
io.netty.util.concurrent.Future<InetSocketAddress> f1 = resolver.resolveHostname(context.nettyEventLoop(), local.host());
f1.addListener((GenericFutureListener<io.netty.util.concurrent.Future<InetSocketAddress>>) res1 -> {
if (res1.isSuccess()) {
ChannelFuture f2 = channel.bind(new InetSocketAddress(res1.getNow().getAddress(), local.port()));
if (metrics != null) {
f2.addListener((GenericFutureListener<io.netty.util.concurrent.Future<Void>>) res2 -> {
if (res2.isSuccess()) {
metrics.listening(local.host(), localAddress());
}
});
}
f2.addListener(promise);
} else {
promise.fail(res1.cause());
}
});
return promise.future().map(this);
}
use of io.vertx.core.impl.future.PromiseInternal in project vert.x by eclipse.
the class DatagramSocketImpl method send.
@Override
public Future<Void> send(Buffer packet, int port, String host) {
Objects.requireNonNull(packet, "no null packet accepted");
Objects.requireNonNull(host, "no null host accepted");
if (port < 0 || port > 65535) {
throw new IllegalArgumentException("port out of range:" + port);
}
AddressResolver resolver = context.owner().addressResolver();
PromiseInternal<Void> promise = context.promise();
io.netty.util.concurrent.Future<InetSocketAddress> f1 = resolver.resolveHostname(context.nettyEventLoop(), host);
f1.addListener((GenericFutureListener<io.netty.util.concurrent.Future<InetSocketAddress>>) res1 -> {
if (res1.isSuccess()) {
ChannelFuture f2 = channel.writeAndFlush(new DatagramPacket(packet.getByteBuf(), new InetSocketAddress(f1.getNow().getAddress(), port)));
if (metrics != null) {
f2.addListener(fut -> {
if (fut.isSuccess()) {
metrics.bytesWritten(null, SocketAddress.inetSocketAddress(port, host), packet.length());
}
});
}
f2.addListener(promise);
} else {
promise.fail(res1.cause());
}
});
return promise.future();
}
use of io.vertx.core.impl.future.PromiseInternal in project vert.x by eclipse.
the class NetClientImpl method close.
@Override
public void close(Promise<Void> completion) {
ChannelGroupFuture fut = channelGroup.close();
if (metrics != null) {
PromiseInternal<Void> p = (PromiseInternal) Promise.promise();
fut.addListener(p);
p.future().<Void>compose(v -> {
metrics.close();
return Future.succeededFuture();
}).onComplete(completion);
} else {
fut.addListener((PromiseInternal) completion);
}
}
use of io.vertx.core.impl.future.PromiseInternal in project hono by eclipse.
the class CachingKafkaProducerFactoryTest method setUp.
@BeforeEach
void setUp() {
final VertxInternal vertxMock = mock(VertxInternal.class);
final ContextInternal context = VertxMockSupport.mockContextInternal(vertxMock);
final PromiseInternal<Void> promiseInternal = VertxMockSupport.promiseInternal();
when(promiseInternal.future()).thenReturn(Future.succeededFuture());
doAnswer(invocation -> {
return promiseInternal;
}).when(context).promise();
when(vertxMock.getOrCreateContext()).thenReturn(context);
doAnswer(invocation -> {
final Promise<Object> result = Promise.promise();
final Handler<Future<Object>> blockingCode = invocation.getArgument(0);
final Handler<AsyncResult<Object>> resultHandler = invocation.getArgument(1);
result.future().onComplete(resultHandler);
blockingCode.handle(result.future());
return null;
}).when(context).executeBlocking(VertxMockSupport.anyHandler(), VertxMockSupport.anyHandler());
final BiFunction<String, Map<String, String>, KafkaProducer<String, Buffer>> instanceSupplier = (n, c) -> {
final MockProducer<String, Buffer> mockProducer = new MockProducer<>(true, new StringSerializer(), new BufferSerializer());
return KafkaProducer.create(vertxMock, mockProducer);
};
factory = CachingKafkaProducerFactory.testFactory(vertxMock, instanceSupplier);
configProperties.setProducerConfig(Map.of("bootstrap.servers", "localhost:9092"));
}
Aggregations