use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelFutureListener in project cdap by caskdata.
the class HttpRequestRouter method channelRead.
@Override
public void channelRead(final ChannelHandlerContext ctx, final Object msg) throws Exception {
try {
final Channel inboundChannel = ctx.channel();
ChannelFutureListener writeCompletedListener = getFailureResponseListener(inboundChannel);
if (msg instanceof HttpRequest) {
inflightRequests++;
if (inflightRequests != 1) {
// At the end of the first response, we'll respond to all the other requests as well
return;
}
// Disable read until sending of this request object is completed successfully
// This is for handling the initial connection delay
inboundChannel.config().setAutoRead(false);
writeCompletedListener = new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
if (future.isSuccess()) {
inboundChannel.config().setAutoRead(true);
} else {
getFailureResponseListener(inboundChannel).operationComplete(future);
}
}
};
HttpRequest request = (HttpRequest) msg;
currentMessageSender = getMessageSender(inboundChannel, getDiscoverable(request, (InetSocketAddress) inboundChannel.localAddress()));
}
if (inflightRequests == 1 && currentMessageSender != null) {
ReferenceCountUtil.retain(msg);
currentMessageSender.send(msg, writeCompletedListener);
}
} finally {
ReferenceCountUtil.release(msg);
}
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelFutureListener in project elephant by yanghuijava.
the class RemotingUtil method closeChannel.
public static void closeChannel(Channel channel) {
final String addrRemote = RemotingHelper.parseChannelRemoteAddr(channel);
channel.close().addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
log.info("closeChannel: close the connection to remote address[{}] result: {}", addrRemote, future.isSuccess());
}
});
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelFutureListener in project modules-extra by CubeEngine.
the class WebSocketRequestHandler method doHandshake.
public void doHandshake(ChannelHandlerContext ctx, FullHttpRequest message) {
WebSocketServerHandshakerFactory handshakerFactory = new WebSocketServerHandshakerFactory("ws://" + message.headers().get(HOST) + "/" + WEBSOCKET_ROUTE, null, false);
this.handshaker = handshakerFactory.newHandshaker(message);
if (handshaker == null) {
this.log.info("client is incompatible!");
WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(ctx.channel());
return;
}
this.log.debug("handshaking now...");
this.handshaker.handshake(ctx.channel(), message).addListener((ChannelFutureListener) future -> {
if (future.isSuccess()) {
log.debug("Success!");
} else {
log.debug("Failed!");
}
});
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelFutureListener in project rocketmq by apache.
the class Broker2Client method checkProducerTransactionState.
public void checkProducerTransactionState(final Channel channel, final CheckTransactionStateRequestHeader requestHeader, final SelectMappedBufferResult selectMappedBufferResult) {
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.CHECK_TRANSACTION_STATE, requestHeader);
request.markOnewayRPC();
try {
FileRegion fileRegion = new OneMessageTransfer(request.encodeHeader(selectMappedBufferResult.getSize()), selectMappedBufferResult);
channel.writeAndFlush(fileRegion).addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
selectMappedBufferResult.release();
if (!future.isSuccess()) {
log.error("invokeProducer failed,", future.cause());
}
}
});
} catch (Throwable e) {
log.error("invokeProducer exception", e);
selectMappedBufferResult.release();
}
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelFutureListener in project rocketmq by apache.
the class NettyRemotingAbstract method invokeOnewayImpl.
public void invokeOnewayImpl(final Channel channel, final RemotingCommand request, final long timeoutMillis) throws InterruptedException, RemotingTooMuchRequestException, RemotingTimeoutException, RemotingSendRequestException {
request.markOnewayRPC();
boolean acquired = this.semaphoreOneway.tryAcquire(timeoutMillis, TimeUnit.MILLISECONDS);
if (acquired) {
final SemaphoreReleaseOnlyOnce once = new SemaphoreReleaseOnlyOnce(this.semaphoreOneway);
try {
channel.writeAndFlush(request).addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture f) throws Exception {
once.release();
if (!f.isSuccess()) {
log.warn("send a request command to channel <" + channel.remoteAddress() + "> failed.");
}
}
});
} catch (Exception e) {
once.release();
log.warn("write send a request command to channel <" + channel.remoteAddress() + "> failed.");
throw new RemotingSendRequestException(RemotingHelper.parseChannelRemoteAddr(channel), e);
}
} else {
if (timeoutMillis <= 0) {
throw new RemotingTooMuchRequestException("invokeOnewayImpl invoke too fast");
} else {
String info = String.format("invokeOnewayImpl tryAcquire semaphore timeout, %dms, waiting thread nums: %d semaphoreAsyncValue: %d", timeoutMillis, this.semaphoreOneway.getQueueLength(), this.semaphoreOneway.availablePermits());
log.warn(info);
throw new RemotingTimeoutException(info);
}
}
}
Aggregations