Search in sources :

Example 21 with FileRegion

use of io.netty.channel.FileRegion in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class Broker2Client method checkProducerTransactionState.

/**
 * Broker主动回查Producer事务状态,Oneway
 */
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();
    }
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) ChannelFuture(io.netty.channel.ChannelFuture) OneMessageTransfer(org.apache.rocketmq.broker.pagecache.OneMessageTransfer) FileRegion(io.netty.channel.FileRegion) ChannelFutureListener(io.netty.channel.ChannelFutureListener) RemotingSendRequestException(org.apache.rocketmq.remoting.exception.RemotingSendRequestException) RemotingTimeoutException(org.apache.rocketmq.remoting.exception.RemotingTimeoutException)

Aggregations

FileRegion (io.netty.channel.FileRegion)21 ByteBuf (io.netty.buffer.ByteBuf)10 ChannelFuture (io.netty.channel.ChannelFuture)10 ChannelFutureListener (io.netty.channel.ChannelFutureListener)8 RemotingCommand (org.apache.rocketmq.remoting.protocol.RemotingCommand)8 RemotingCommandException (org.apache.rocketmq.remoting.exception.RemotingCommandException)6 DefaultFileRegion (io.netty.channel.DefaultFileRegion)5 IOException (java.io.IOException)5 WritableByteChannel (java.nio.channels.WritableByteChannel)4 OneMessageTransfer (org.apache.rocketmq.broker.pagecache.OneMessageTransfer)4 Channel (io.netty.channel.Channel)3 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)3 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)3 File (java.io.File)3 FileOutputStream (java.io.FileOutputStream)2 RandomAccessFile (java.io.RandomAccessFile)2 Random (java.util.Random)2 ConsumerGroupInfo (org.apache.rocketmq.broker.client.ConsumerGroupInfo)2 ConsumerFilterData (org.apache.rocketmq.broker.filter.ConsumerFilterData)2 ExpressionForRetryMessageFilter (org.apache.rocketmq.broker.filter.ExpressionForRetryMessageFilter)2