All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.feingto.iot.common.handler.DefaultSimpleChannelHandler Maven / Gradle / Ivy

There is a newer version: 2.3.3.RELEASE
Show newest version
package com.feingto.iot.common.handler;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

/**
 * 通道Inbound处理器抽象
 *
 * @author longfei
 */
public abstract class DefaultSimpleChannelHandler extends SimpleChannelInboundHandler {
    public abstract void handleMessage(ChannelHandlerContext ctx, T msg) throws Exception;

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, T msg) throws Exception {
        handleMessage(ctx, msg);
    }

    /**
     * 当Channel上的某个读操作完成时被调用
     */
    @Override
    public void channelReadComplete(ChannelHandlerContext ctx) {
        ctx.flush();
    }

    /**
     * 处理过程中ChannelPipeline中发生错误时被调用
     */
    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
        cause.printStackTrace();
        ctx.close();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy