com.witjit.game.server.communication.handler.IdleChannelHandler.java Source code

Java tutorial

Introduction

Here is the source code for com.witjit.game.server.communication.handler.IdleChannelHandler.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.witjit.game.server.communication.handler;

import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.timeout.IdleState;
import io.netty.handler.timeout.IdleStateEvent;

/**
 *
 * @author Administrator
 */
public class IdleChannelHandler extends ChannelDuplexHandler {
    /**
     * 
     * @param ctx
     * @param evt
     * @throws Exception 
     */
    @Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
        if (evt instanceof IdleStateEvent) {
            IdleStateEvent e = (IdleStateEvent) evt;
            if (e.state() == IdleState.READER_IDLE) {
                ctx.close();
            }
        }
    }
}