use of org.apache.flink.shaded.netty4.io.netty.util.concurrent.Future in project incubator-pulsar by apache.
the class ConsumerImpl method sendAcknowledge.
private CompletableFuture<Void> sendAcknowledge(MessageId messageId, AckType ackType, Map<String, Long> properties) {
MessageIdImpl msgId = (MessageIdImpl) messageId;
final ByteBuf cmd = Commands.newAck(consumerId, msgId.getLedgerId(), msgId.getEntryId(), ackType, null, properties);
// There's no actual response from ack messages
final CompletableFuture<Void> ackFuture = new CompletableFuture<Void>();
if (isConnected()) {
cnx().ctx().writeAndFlush(cmd).addListener(new GenericFutureListener<Future<Void>>() {
@Override
public void operationComplete(Future<Void> future) throws Exception {
if (future.isSuccess()) {
if (ackType == AckType.Individual) {
unAckedMessageTracker.remove(msgId);
// increment counter by 1 for non-batch msg
if (!(messageId instanceof BatchMessageIdImpl)) {
stats.incrementNumAcksSent(1);
}
} else if (ackType == AckType.Cumulative) {
stats.incrementNumAcksSent(unAckedMessageTracker.removeMessagesTill(msgId));
}
if (log.isDebugEnabled()) {
log.debug("[{}] [{}] [{}] Successfully acknowledged message - {}, acktype {}", subscription, topic, consumerName, messageId, ackType);
}
ackFuture.complete(null);
} else {
stats.incrementNumAcksFailed();
ackFuture.completeExceptionally(new PulsarClientException(future.cause()));
}
}
});
} else {
stats.incrementNumAcksFailed();
ackFuture.completeExceptionally(new PulsarClientException("Not connected to broker. State: " + getState()));
}
return ackFuture;
}
use of org.apache.flink.shaded.netty4.io.netty.util.concurrent.Future in project incubator-pulsar by apache.
the class ConsumerImpl method internalGetLastMessageIdAsync.
private void internalGetLastMessageIdAsync(final Backoff backoff, final AtomicLong remainingTime, CompletableFuture<MessageId> future) {
ClientCnx cnx = cnx();
if (isConnected() && cnx != null) {
if (!Commands.peerSupportsGetLastMessageId(cnx.getRemoteEndpointProtocolVersion())) {
future.completeExceptionally(new PulsarClientException.NotSupportedException("GetLastMessageId Not supported for ProtocolVersion: " + cnx.getRemoteEndpointProtocolVersion()));
}
long requestId = client.newRequestId();
ByteBuf getLastIdCmd = Commands.newGetLastMessageId(consumerId, requestId);
log.info("[{}][{}] Get topic last message Id", topic, subscription);
cnx.sendGetLastMessageId(getLastIdCmd, requestId).thenAccept((result) -> {
log.info("[{}][{}] Successfully getLastMessageId {}:{}", topic, subscription, result.getLedgerId(), result.getEntryId());
future.complete(new MessageIdImpl(result.getLedgerId(), result.getEntryId(), result.getPartition()));
}).exceptionally(e -> {
log.error("[{}][{}] Failed getLastMessageId command", topic, subscription);
future.completeExceptionally(e.getCause());
return null;
});
} else {
long nextDelay = Math.min(backoff.next(), remainingTime.get());
if (nextDelay <= 0) {
future.completeExceptionally(new PulsarClientException.TimeoutException("Could not getLastMessageId within configured timeout."));
return;
}
((ScheduledExecutorService) listenerExecutor).schedule(() -> {
log.warn("[{}] [{}] Could not get connection while getLastMessageId -- Will try again in {} ms", topic, getHandlerName(), nextDelay);
remainingTime.addAndGet(-nextDelay);
internalGetLastMessageIdAsync(backoff, remainingTime, future);
}, nextDelay, TimeUnit.MILLISECONDS);
}
}
use of org.apache.flink.shaded.netty4.io.netty.util.concurrent.Future in project UnderNet by itsMatoosh.
the class Client method connect.
/**
* Connects the client to a node.
*/
public void connect(Node node) {
if (status == InterfaceStatus.STOPPING) {
logger.error("Can't connect to nodes, while the client is stopping!");
return;
}
if (status != InterfaceStatus.STARTED) {
EventManager.callEvent(new ClientStatusEvent(this, InterfaceStatus.STARTED));
}
logger.info("Connecting to node: " + node.address);
// Making sure the list of client futures exists.
if (closeFutures == null) {
closeFutures = new ArrayList<>();
}
// Starting the client.
Bootstrap clientBootstrap = new Bootstrap();
// Assigning the channel to the client event loop group.
clientBootstrap.group(workerEventLoopGroup);
// Using the non blocking io.
clientBootstrap.channel(NioSocketChannel.class);
// Making sure the connection is sending the keep alive signal.
clientBootstrap.option(ChannelOption.SO_KEEPALIVE, true);
clientBootstrap.handler(new ClientChannelInitializer(this));
// Connecting
// Connecting to the node.
ChannelFuture future = clientBootstrap.connect(node.address);
ChannelFuture closeFuture = future.channel().closeFuture();
closeFuture.addListener(new GenericFutureListener<Future<? super Void>>() {
@Override
public void operationComplete(Future<? super Void> future) throws Exception {
// Removing the future from future list.
closeFutures.remove(future);
if (closeFutures.size() == 0) {
// Stopping the worker group.
EventManager.callEvent(new ClientStatusEvent(Client.this, InterfaceStatus.STOPPED));
}
}
});
closeFutures.add(closeFuture);
}
use of org.apache.flink.shaded.netty4.io.netty.util.concurrent.Future in project drill by axbaretto.
the class WebSessionResourcesTest method testCloseWithListener.
/**
* Validates successful {@link WebSessionResources#close()} with valid CloseFuture and {@link TestClosedListener}
* getting invoked which is added to the close future.
* @throws Exception
*/
@Test
public void testCloseWithListener() throws Exception {
try {
// Assign latch, executor and closeListener for this test case
GenericFutureListener<Future<Void>> closeListener = new TestClosedListener();
latch = new CountDownLatch(1);
executor = TransportCheck.createEventLoopGroup(1, "Test-Thread").next();
ChannelPromise closeFuture = new DefaultChannelPromise(null, executor);
// create WebSessionResources with above ChannelPromise to notify listener
webSessionResources = new WebSessionResources(mock(BufferAllocator.class), mock(SocketAddress.class), mock(UserSession.class), closeFuture);
// Add the Test Listener to close future
assertTrue(!listenerComplete);
closeFuture.addListener(closeListener);
// Close the WebSessionResources
webSessionResources.close();
// Verify the states
verify(webSessionResources.getAllocator()).close();
verify(webSessionResources.getSession()).close();
assertTrue(webSessionResources.getCloseFuture() == null);
// Since listener will be invoked so test should not wait forever
latch.await();
assertTrue(listenerComplete);
} catch (Exception e) {
fail();
} finally {
listenerComplete = false;
executor.shutdownGracefully();
}
}
use of org.apache.flink.shaded.netty4.io.netty.util.concurrent.Future in project reactor-netty by reactor.
the class DefaultLoopResources method disposeLater.
@Override
public Mono<Void> disposeLater() {
return Mono.defer(() -> {
EventLoopGroup cacheNativeClientGroup = cacheNativeClientLoops.get();
EventLoopGroup cacheNativeSelectGroup = cacheNativeSelectLoops.get();
EventLoopGroup cacheNativeServerGroup = cacheNativeServerLoops.get();
if (running.compareAndSet(true, false)) {
clientLoops.shutdownGracefully();
serverSelectLoops.shutdownGracefully();
serverLoops.shutdownGracefully();
if (cacheNativeClientGroup != null) {
cacheNativeClientGroup.shutdownGracefully();
}
if (cacheNativeSelectGroup != null) {
cacheNativeSelectGroup.shutdownGracefully();
}
if (cacheNativeServerGroup != null) {
cacheNativeServerGroup.shutdownGracefully();
}
}
Mono<?> clMono = FutureMono.from((Future) clientLoops.terminationFuture());
Mono<?> sslMono = FutureMono.from((Future) serverSelectLoops.terminationFuture());
Mono<?> slMono = FutureMono.from((Future) serverLoops.terminationFuture());
Mono<?> cnclMono = Mono.empty();
if (cacheNativeClientGroup != null) {
cnclMono = FutureMono.from((Future) cacheNativeClientGroup.terminationFuture());
}
Mono<?> cnslMono = Mono.empty();
if (cacheNativeSelectGroup != null) {
cnslMono = FutureMono.from((Future) cacheNativeSelectGroup.terminationFuture());
}
Mono<?> cnsrvlMono = Mono.empty();
if (cacheNativeServerGroup != null) {
cnsrvlMono = FutureMono.from((Future) cacheNativeServerGroup.terminationFuture());
}
return Mono.when(clMono, sslMono, slMono, cnclMono, cnslMono, cnsrvlMono);
});
}
Aggregations