HeartbeatInitializer.java
982 字节
package com.crossoverjie.netty.action.init;
import com.crossoverjie.netty.action.handle.HeartBeatSimpleHandle;
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.handler.codec.LineBasedFrameDecoder;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.timeout.IdleStateHandler;
/**
* Function:
*
* @author crossoverJie
* Date: 17/05/2018 18:51
* @since JDK 1.8
*/
public class HeartbeatInitializer extends ChannelInitializer<Channel> {
@Override
protected void initChannel(Channel ch) throws Exception {
ch.pipeline()
//五秒没有收到消息 将IdleStateHandler 添加到 ChannelPipeline 中
.addLast(new IdleStateHandler(5, 0, 0))
//.addLast(new HeartbeatDecoder())
.addLast(new LineBasedFrameDecoder(1024))
.addLast(new StringDecoder())
.addLast(new HeartBeatSimpleHandle());
}
}