Search in sources :

Example 1 with UnknowCommandException

use of pers.cy.iris.commons.exception.UnknowCommandException in project iris by chicc999.

the class DefaultDispatcherHandler method processRequest.

private void processRequest(ChannelHandlerContext ctx, Command command) throws Exception {
    int type = command.getHeader().getType();
    if (Command.HEARTBEAT == type) {
        //双向心跳,无需处理
        return;
    }
    Header header = command.getHeader();
    CommandHandler handler = handlerFactory.getHandler(header.getType());
    if (handler == null) {
        throw new UnknowCommandException("处理" + header.getTypeString() + "的handler不存在");
    }
    try {
        HandlerTask task = new HandlerTask(ctx, command, handler);
        ExecutorService commandExecutor = handler.getExecutorService(command);
        if (commandExecutor == null) {
            // 如果没用指定处理该命令专用的线程池,则在普通业务线程池执行
            this.serviceExecutor.submit(task);
        } else {
            commandExecutor.submit(task);
        }
    } catch (RejectedExecutionException e) {
        throw new ServiceTooBusyException("too many requests and thread pool is busy, reject request %d from %s ", e);
    }
}
Also used : ServiceTooBusyException(pers.cy.iris.commons.exception.ServiceTooBusyException) Header(pers.cy.iris.commons.network.protocol.Header) HandlerTask(pers.cy.iris.commons.network.HandlerTask) ExecutorService(java.util.concurrent.ExecutorService) UnknowCommandException(pers.cy.iris.commons.exception.UnknowCommandException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Aggregations

ExecutorService (java.util.concurrent.ExecutorService)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 ServiceTooBusyException (pers.cy.iris.commons.exception.ServiceTooBusyException)1 UnknowCommandException (pers.cy.iris.commons.exception.UnknowCommandException)1 HandlerTask (pers.cy.iris.commons.network.HandlerTask)1 Header (pers.cy.iris.commons.network.protocol.Header)1