Search in sources :

Example 1 with RequestTask

use of org.apache.rocketmq.remoting.netty.RequestTask in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class PullMessageProcessor method executeRequestWhenWakeup.

public void executeRequestWhenWakeup(final Channel channel, final RemotingCommand request) throws RemotingCommandException {
    Runnable run = new Runnable() {

        @Override
        public void run() {
            try {
                final RemotingCommand response = PullMessageProcessor.this.processRequest(channel, request, false);
                if (response != null) {
                    response.setOpaque(request.getOpaque());
                    response.markResponseType();
                    try {
                        channel.writeAndFlush(response).addListener(new ChannelFutureListener() {

                            @Override
                            public void operationComplete(ChannelFuture future) throws Exception {
                                if (!future.isSuccess()) {
                                    LOG.error("ProcessRequestWrapper response to {} failed", future.channel().remoteAddress(), future.cause());
                                    LOG.error(request.toString());
                                    LOG.error(response.toString());
                                }
                            }
                        });
                    } catch (Throwable e) {
                        LOG.error("ProcessRequestWrapper process request over, but response failed", e);
                        LOG.error(request.toString());
                        LOG.error(response.toString());
                    }
                }
            } catch (RemotingCommandException e1) {
                LOG.error("ExecuteRequestWhenWakeup run", e1);
            }
        }
    };
    this.brokerController.getPullMessageExecutor().submit(new RequestTask(run, channel, request));
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) ChannelFuture(io.netty.channel.ChannelFuture) RequestTask(org.apache.rocketmq.remoting.netty.RequestTask) RemotingCommandException(org.apache.rocketmq.remoting.exception.RemotingCommandException) ChannelFutureListener(io.netty.channel.ChannelFutureListener) RemotingCommandException(org.apache.rocketmq.remoting.exception.RemotingCommandException)

Example 2 with RequestTask

use of org.apache.rocketmq.remoting.netty.RequestTask in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class BrokerController method headSlowTimeMills.

public long headSlowTimeMills(BlockingQueue<Runnable> q) {
    long slowTimeMills = 0;
    final Runnable peek = q.peek();
    if (peek != null) {
        RequestTask rt = BrokerFastFailure.castRunnable(peek);
        slowTimeMills = rt == null ? 0 : this.messageStore.now() - rt.getCreateTimestamp();
    }
    if (slowTimeMills < 0)
        slowTimeMills = 0;
    return slowTimeMills;
}
Also used : RequestTask(org.apache.rocketmq.remoting.netty.RequestTask)

Example 3 with RequestTask

use of org.apache.rocketmq.remoting.netty.RequestTask in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class BrokerFastFailure method cleanExpiredRequest.

private void cleanExpiredRequest() {
    while (this.brokerController.getMessageStore().isOSPageCacheBusy()) {
        try {
            if (!this.brokerController.getSendThreadPoolQueue().isEmpty()) {
                final Runnable runnable = this.brokerController.getSendThreadPoolQueue().poll(0, TimeUnit.SECONDS);
                if (null == runnable) {
                    break;
                }
                final RequestTask rt = castRunnable(runnable);
                rt.returnResponse(RemotingSysResponseCode.SYSTEM_BUSY, String.format("[PCBUSY_CLEAN_QUEUE]broker busy, start flow control for a while, period in queue: %sms, size of queue: %d", System.currentTimeMillis() - rt.getCreateTimestamp(), this.brokerController.getSendThreadPoolQueue().size()));
            } else {
                break;
            }
        } catch (Throwable ignored) {
        }
    }
    while (true) {
        try {
            if (!this.brokerController.getSendThreadPoolQueue().isEmpty()) {
                final Runnable runnable = this.brokerController.getSendThreadPoolQueue().peek();
                if (null == runnable) {
                    break;
                }
                final RequestTask rt = castRunnable(runnable);
                if (rt == null || rt.isStopRun()) {
                    break;
                }
                final long behind = System.currentTimeMillis() - rt.getCreateTimestamp();
                if (behind >= this.brokerController.getBrokerConfig().getWaitTimeMillsInSendQueue()) {
                    if (this.brokerController.getSendThreadPoolQueue().remove(runnable)) {
                        rt.setStopRun(true);
                        rt.returnResponse(RemotingSysResponseCode.SYSTEM_BUSY, String.format("[TIMEOUT_CLEAN_QUEUE]broker busy, start flow control for a while, period in queue: %sms, size of queue: %d", behind, this.brokerController.getSendThreadPoolQueue().size()));
                    }
                } else {
                    break;
                }
            } else {
                break;
            }
        } catch (Throwable ignored) {
        }
    }
}
Also used : RequestTask(org.apache.rocketmq.remoting.netty.RequestTask)

Example 4 with RequestTask

use of org.apache.rocketmq.remoting.netty.RequestTask in project rocketmq by apache.

the class BrokerFastFailure method cleanExpiredRequestInQueue.

void cleanExpiredRequestInQueue(final BlockingQueue<Runnable> blockingQueue, final long maxWaitTimeMillsInQueue) {
    while (true) {
        try {
            if (!blockingQueue.isEmpty()) {
                final Runnable runnable = blockingQueue.peek();
                if (null == runnable) {
                    break;
                }
                final RequestTask rt = castRunnable(runnable);
                if (rt == null || rt.isStopRun()) {
                    break;
                }
                final long behind = System.currentTimeMillis() - rt.getCreateTimestamp();
                if (behind >= maxWaitTimeMillsInQueue) {
                    if (blockingQueue.remove(runnable)) {
                        rt.setStopRun(true);
                        rt.returnResponse(RemotingSysResponseCode.SYSTEM_BUSY, String.format("[TIMEOUT_CLEAN_QUEUE]broker busy, start flow control for a while, period in queue: %sms, size of queue: %d", behind, blockingQueue.size()));
                    }
                } else {
                    break;
                }
            } else {
                break;
            }
        } catch (Throwable ignored) {
        }
    }
}
Also used : RequestTask(org.apache.rocketmq.remoting.netty.RequestTask)

Example 5 with RequestTask

use of org.apache.rocketmq.remoting.netty.RequestTask in project rocketmq by apache.

the class PullMessageProcessor method executeRequestWhenWakeup.

public void executeRequestWhenWakeup(final Channel channel, final RemotingCommand request) throws RemotingCommandException {
    Runnable run = new Runnable() {

        @Override
        public void run() {
            try {
                final RemotingCommand response = PullMessageProcessor.this.processRequest(channel, request, false);
                if (response != null) {
                    response.setOpaque(request.getOpaque());
                    response.markResponseType();
                    try {
                        channel.writeAndFlush(response).addListener(new ChannelFutureListener() {

                            @Override
                            public void operationComplete(ChannelFuture future) throws Exception {
                                if (!future.isSuccess()) {
                                    log.error("processRequestWrapper response to {} failed", future.channel().remoteAddress(), future.cause());
                                    log.error(request.toString());
                                    log.error(response.toString());
                                }
                            }
                        });
                    } catch (Throwable e) {
                        log.error("processRequestWrapper process request over, but response failed", e);
                        log.error(request.toString());
                        log.error(response.toString());
                    }
                }
            } catch (RemotingCommandException e1) {
                log.error("excuteRequestWhenWakeup run", e1);
            }
        }
    };
    this.brokerController.getPullMessageExecutor().submit(new RequestTask(run, channel, request));
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) ChannelFuture(io.netty.channel.ChannelFuture) RequestTask(org.apache.rocketmq.remoting.netty.RequestTask) RemotingCommandException(org.apache.rocketmq.remoting.exception.RemotingCommandException) ChannelFutureListener(io.netty.channel.ChannelFutureListener) RemotingCommandException(org.apache.rocketmq.remoting.exception.RemotingCommandException)

Aggregations

RequestTask (org.apache.rocketmq.remoting.netty.RequestTask)8 ChannelFuture (io.netty.channel.ChannelFuture)2 ChannelFutureListener (io.netty.channel.ChannelFutureListener)2 RemotingCommandException (org.apache.rocketmq.remoting.exception.RemotingCommandException)2 RemotingCommand (org.apache.rocketmq.remoting.protocol.RemotingCommand)2 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 Test (org.junit.Test)1