org.apache.mina.core.session.IdleStatus Java Examples

The following examples show how to use org.apache.mina.core.session.IdleStatus. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GameHandler.java    From gameserver with Apache License 2.0 6 votes vote down vote up
@Override
public void sessionIdle(IoSession session, IdleStatus status)
		throws Exception {
	if ( StatClient.getIntance().isStatEnabled() ) {
		SessionKey userSessionKey = (SessionKey)session.getAttribute(Constant.SESSION_KEY);
		if ( userSessionKey != null ) {
			User user = GameContext.getInstance().findLocalUserBySessionKey(userSessionKey);
			if ( user != null ) {
				GameContext.getInstance().deregisterUserBySessionKey(userSessionKey);
				logger.debug("User {} session is idle too much time. Close it.", user.getRoleName());
				
				StatClient.getIntance().sendDataToStatServer(user, StatAction.LogoutIdle);
			}
		}
	}
	try {
		session.close(false);
		//do cleaning
	} catch (Throwable e) {
	}
}
 
Example #2
Source File: IoSessionEvent.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Static method which effectively delivers the specified event to the next filter
 * <code>nextFilter</code> on the <code>session</code>.
 * 
 * @param nextFilter the next filter
 * @param session the session on which the event occured
 * @param type the event type
 * @param status the idle status should only be non null only if the event type is 
 * {@link IoSessionEventType#IDLE} 
 */
private static void deliverEvent(final NextFilter nextFilter, final IoSession session,
        final IoSessionEventType type, final IdleStatus status) {
    switch (type) {
    case CREATED:
        nextFilter.sessionCreated(session);
        break;
    case OPENED:
        nextFilter.sessionOpened(session);
        break;
    case IDLE:
        nextFilter.sessionIdle(session, status);
        break;
    case CLOSED:
        nextFilter.sessionClosed(session);
        break;
    }
}
 
Example #3
Source File: MessageClient.java    From gameserver with Apache License 2.0 6 votes vote down vote up
/**
 * When a session is idle for configed seconds, it will send a heart-beat
 * message to remote.
 */
@Override
public void sessionIdle(IoSession session, IdleStatus status)
		throws Exception {
	try {
		/*
		if (logger.isDebugEnabled()) {
			logger.debug("session has been idle for a while. Send a heartbeat message.");
		}
		*/
		sendMessageToServer(HEART_BEAT_MSG);
		Stat.getInstance().messageHearbeatSent++;
	} finally {
	}
}
 
Example #4
Source File: ConnectionHandler.java    From Openfire with Apache License 2.0 6 votes vote down vote up
@Override
public void sessionOpened(IoSession session) throws Exception {
    // Create a new XML parser for the new connection. The parser will be used by the XMPPDecoder filter.
    final XMLLightweightParser parser = new XMLLightweightParser(StandardCharsets.UTF_8);
    session.setAttribute(XML_PARSER, parser);
    // Create a new NIOConnection for the new session
    final NIOConnection connection = createNIOConnection(session);
    session.setAttribute(CONNECTION, connection);
    session.setAttribute(HANDLER, createStanzaHandler(connection));
    // Set the max time a connection can be idle before closing it. This amount of seconds
    // is divided in two, as Openfire will ping idle clients first (at 50% of the max idle time)
    // before disconnecting them (at 100% of the max idle time). This prevents Openfire from
    // removing connections without warning.
    final int idleTime = getMaxIdleTime() / 2;
    if (idleTime > 0) {
        session.getConfig().setIdleTime(IdleStatus.READER_IDLE, idleTime);
    }
}
 
Example #5
Source File: NetManager.java    From GameServer with Apache License 2.0 6 votes vote down vote up
public  void startListner(IoHandler iohandler,int listenPort) throws Exception{
	acceptor = new NioSocketAcceptor();
	acceptor.setBacklog(100);
	acceptor.setReuseAddress(true);
	acceptor.setHandler(iohandler);
	
       DefaultIoFilterChainBuilder chain = acceptor.getFilterChain();
       IoFilter protocol = new ProtocolCodecFilter(new GameProtocolcodecFactory());
       chain.addLast("codec", protocol);
	threadpool = new OrderedThreadPoolExecutor(500);
	threadpool.setThreadFactory(new ServerThreadFactory("OrderedThreadPool"));
	chain.addLast("threadPool", new ExecutorFilter(threadpool));
	
	int recsize = 5120;
	int sendsize = 40480;                                                                                         
	int timeout = 10;
	SocketSessionConfig sc = acceptor.getSessionConfig();
	sc.setReuseAddress(true);// 设置每一个非主监听连接的端口可以重用
	sc.setReceiveBufferSize(recsize);// 设置输入缓冲区的大小
	sc.setSendBufferSize(sendsize);// 设置输出缓冲区的大小
	sc.setTcpNoDelay(true);// flush函数的调用 设置为非延迟发送,为true则不组装成大包发送,收到东西马上发出   
	sc.setSoLinger(0);
	sc.setIdleTime(IdleStatus.READER_IDLE, timeout);
	acceptor.bind(new InetSocketAddress(listenPort));
}
 
Example #6
Source File: SocketConnectorSupplier.java    From sumk with Apache License 2.0 6 votes vote down vote up
private synchronized SocketConnector create() {
	if (connector != null && !connector.isDisposing() && !connector.isDisposed()) {
		return connector;
	}
	try {
		NioSocketConnector con = new NioSocketConnector(
				AppInfo.getInt("sumk.rpc.client.poolsize", Runtime.getRuntime().availableProcessors() + 1));
		con.setConnectTimeoutMillis(AppInfo.getInt("sumk.rpc.connect.timeout", 5000));
		con.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, AppInfo.getInt(Const.SOA_SESSION_IDLE, 600));
		con.setHandler(createClientHandler());
		con.getFilterChain().addLast("codec", new ProtocolCodecFilter(IOC.get(SumkCodecFactory.class)));
		if (AppInfo.getBoolean("sumk.rpc.client.threadpool.enable", true)) {
			con.getFilterChain().addLast("threadpool", new ExecutorFilter(SoaExcutors.getClientThreadPool()));
		}
		this.connector = con;
		return con;
	} catch (Exception e) {
		Logs.rpc().error(e.getMessage(), e);
		throw new SumkException(5423654, "create connector error", e);
	}
}
 
Example #7
Source File: MinaHandler.java    From light-task-scheduler with Apache License 2.0 6 votes vote down vote up
@Override
public void sessionIdle(IoSession session, IdleStatus status) throws Exception {
    com.github.ltsopensource.remoting.Channel channel = new MinaChannel(session);

    final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(channel);

    if (IdleStatus.BOTH_IDLE == status) {
        LOGGER.info("{}: IDLE [{}]", sideType, remoteAddress);
        RemotingHelper.closeChannel(channel);
    }

    if (remoting.getChannelEventListener() != null) {
        RemotingEventType remotingEventType = null;
        if (IdleStatus.BOTH_IDLE == status) {
            remotingEventType = RemotingEventType.ALL_IDLE;
        } else if (IdleStatus.READER_IDLE == status) {
            remotingEventType = RemotingEventType.READER_IDLE;
        } else if (IdleStatus.WRITER_IDLE == status) {
            remotingEventType = RemotingEventType.WRITER_IDLE;
        }
        remoting.putRemotingEvent(new RemotingEvent(remotingEventType,
                remoteAddress, channel));
    }
}
 
Example #8
Source File: MinaTimeServer.java    From frameworkAggregate with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws IOException {

		IoAcceptor acceptor = new NioSocketAcceptor();
		// 这个过滤器用来记录所有的信息,比如创建session(会话),接收消息,发送消息,关闭会话等
		acceptor.getFilterChain().addLast("logger", new LoggingFilter());
		// 用来转换二进制或协议的专用数据到消息对象中
		acceptor.getFilterChain().addLast("codec",
				new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName("UTF-8"))));

		// 实时处理客户端的连接和请求
		acceptor.setHandler(new TimeServerHandler());
		acceptor.getSessionConfig().setReadBufferSize(2048);
		// 方法将定时调用一次会话,保持空闲状态。来设定时间间隔。
		acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 10);
		acceptor.bind(new InetSocketAddress(PORT));
	}
 
Example #9
Source File: MinaTimeServer.java    From java-tutorial with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws IOException {
    // 创建服务器端的监听器对象
    IoAcceptor acceptor = new NioSocketAcceptor();
    // 增加日志过滤器:用于日志存储
    acceptor.getFilterChain().addLast("logger", new LoggingFilter());
    // 增加消息编码过滤器,采用UTF-8编码
    acceptor.getFilterChain().addLast("codec",
            new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName("UTF-8"))));
    // 设置具体的事物逻辑处理器
    acceptor.setHandler(new TimeServerHandler());
    // 设置IoSession的一些属性
    acceptor.getSessionConfig().setReadBufferSize(2048);
    acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 10);
    // 设置服务器监听的端口
    acceptor.bind(new InetSocketAddress(PORT));
}
 
Example #10
Source File: ITCHMulticastTCPHandlerAdapter.java    From sailfish-core with Apache License 2.0 6 votes vote down vote up
private IMessage onLogon(IMessage iMessage, IoSession session) {
    handleMessage(iMessage, true, true, session.getRemoteAddress().toString());

    IMessage loginResponse = msgFactory.createMessage(LOGIN_RESPONSE, iMessage.getNamespace());
    if (iMessage.getField("Username") != null && iMessage.getField("Password") != null) {
        loginResponse.addField(STATUS, toShort('A'));
    } else {
        loginResponse.addField(STATUS, toShort('e'));
    }
    @SuppressWarnings("serial")
    Map<String, String> params = new HashMap<String, String>(){{
        put(ITCHMessageHelper.FIELD_MARKET_DATA_GROUP_NAME, String.valueOf(mdGroup));
        put(ITCHMessageHelper.FIELD_SEQUENCE_NUMBER_NAME, String.valueOf(0));
    }};
    loginResponse = itchHandler.prepareMessageToEncode(loginResponse, params);
    session.write(loginResponse);
    handleMessage(loginResponse, false, true, session.getRemoteAddress().toString());

    session.getConfig().setIdleTime(IdleStatus.READER_IDLE, sessionIdleTimeout);

    return loginResponse;
}
 
Example #11
Source File: MapleServerHandler.java    From mapleLemon with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void sessionIdle(IoSession session, IdleStatus status) throws Exception {
    MapleClient client = (MapleClient) session.getAttribute(MapleClient.CLIENT_KEY);
    if (client != null) {
        //client.sendPing();
    }
    super.sessionIdle(session, status);
}
 
Example #12
Source File: MTGGameRoomServer.java    From MtgDesktopCompanion with GNU General Public License v3.0 5 votes vote down vote up
public MTGGameRoomServer() throws IOException {

		super();
		acceptor = new NioSocketAcceptor();
		acceptor.setHandler(adapter);
		acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new ObjectSerializationCodecFactory()));
		acceptor.getSessionConfig().setReadBufferSize(getInt("BUFFER-SIZE"));
		acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE,getInt("IDLE-TIME"));
	}
 
Example #13
Source File: LoginServer.java    From mapleLemon with GNU General Public License v2.0 5 votes vote down vote up
public static void run_startup_configurations() {
    userLimit = ServerProperties.getProperty("userlimit", 140);
    serverName = ServerProperties.getProperty("serverName", "MapleStory");
    flag = ServerProperties.getProperty("flag", (byte) 3);
    adminOnly = Boolean.parseBoolean(ServerProperties.getProperty("admin", "false"));
    maxCharacters = ServerProperties.getProperty("maxCharacters", 30);
    autoReg = Boolean.parseBoolean(ServerProperties.getProperty("autoReg", "false"));
    checkMacs = Boolean.parseBoolean(ServerProperties.getProperty("checkMacs", "false"));
    port = Short.parseShort(ServerProperties.getProperty("world.port", String.valueOf(DEFAULT_PORT)));

    IoBuffer.setUseDirectBuffer(false);
    IoBuffer.setAllocator(new SimpleBufferAllocator());

    acceptor = new NioSocketAcceptor();
    acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new MapleCodecFactory()));
    acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 30);

    try {
        acceptor.setHandler(new MapleServerHandler(MapleServerHandler.LOGIN_SERVER));
        acceptor.bind(new InetSocketAddress(port));
        ((SocketSessionConfig) acceptor.getSessionConfig()).setTcpNoDelay(true);

        FileoutputUtil.log("\"登入\"伺服器正在监听" + port + "端口\r\n");
    } catch (IOException e) {
        System.err.println("无法绑定" + port + "端口: " + e);
    }
}
 
Example #14
Source File: UdpServer.java    From game-server with MIT License 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void run() {
	synchronized (this) {
		if (!isRunning) {
			DefaultIoFilterChainBuilder chain = acceptor.getFilterChain();
			if (factory == null) {
				factory = new DefaultProtocolCodecFactory();
			}
			factory.getDecoder().setMaxReadSize(minaServerConfig.getMaxReadSize());
			factory.getEncoder().setMaxScheduledWriteMessages(minaServerConfig.getMaxScheduledWriteMessages());
			chain.addLast("codec", new ProtocolCodecFilter(factory));
			threadpool = new OrderedThreadPoolExecutor(minaServerConfig.getOrderedThreadPoolExecutorSize());
			chain.addLast("threadPool", new ExecutorFilter(threadpool));
			if(filters != null){
                   filters.forEach((key, filter)->chain.addLast(key, filter));
			}

			DatagramSessionConfig dc = acceptor.getSessionConfig();
			dc.setReuseAddress(minaServerConfig.isReuseAddress());
			dc.setReceiveBufferSize(minaServerConfig.getReceiveBufferSize());
			dc.setSendBufferSize(minaServerConfig.getSendBufferSize());
			dc.setIdleTime(IdleStatus.READER_IDLE, minaServerConfig.getReaderIdleTime());
			dc.setIdleTime(IdleStatus.WRITER_IDLE, minaServerConfig.getWriterIdleTime());
			dc.setBroadcast(true);
			dc.setCloseOnPortUnreachable(true);

			acceptor.setHandler(ioHandler);
			try {
				acceptor.bind(new InetSocketAddress(minaServerConfig.getPort()));
				LOGGER.warn("已开始监听UDP端口:{}", minaServerConfig.getPort());
			} catch (IOException e) {
				LOGGER.warn("监听UDP端口:{}已被占用", minaServerConfig.getPort());
				LOGGER.error("UDP, 服务异常", e);
			}
		}
	}
}
 
Example #15
Source File: HelloTcpServer.java    From mina-examples with MIT License 5 votes vote down vote up
public static void main(String[] args) throws Exception {
	IoAcceptor acceptor = new NioSocketAcceptor(); //TCP Acceptor
	acceptor.getFilterChain().addLast("logging", new LoggingFilter());
	acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new ObjectSerializationCodecFactory()));
	acceptor.getFilterChain().addLast("mdc", new MdcInjectionFilter());
	acceptor.setHandler(new HelloServerHandler());
	acceptor.getSessionConfig().setReadBufferSize(2048);
	acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 10);
	acceptor.bind(new InetSocketAddress(PORT));
}
 
Example #16
Source File: ClientHandler.java    From sumk with Apache License 2.0 5 votes vote down vote up
@Override
public void sessionIdle(IoSession session, IdleStatus status) throws Exception {
	long time = System.currentTimeMillis() - session.getLastIoTime();
	if (time > AppInfo.getLong(Const.SOA_SESSION_IDLE, 60) * 1000) {
		Log.get("sumk.rpc.client").info("rpc session {} {} for {}ms,closed by this client", session.getId(), status,
				session.getLastIoTime(), time);
		session.closeOnFlush();
	}
}
 
Example #17
Source File: ConnectionHandler.java    From Openfire with Apache License 2.0 5 votes vote down vote up
/**
 * Invoked when a MINA session has been idle for half of the allowed XMPP
 * session idle time as specified by {@link #getMaxIdleTime()}. This method
 * will be invoked each time that such a period passes (even if no IO has
 * occurred in between).
 *
 * Openfire will disconnect a session the second time this method is
 * invoked, if no IO has occurred between the first and second invocation.
 * This allows extensions of this class to use the first invocation to check
 * for livelyness of the MINA session (e.g by polling the remote entity, as
 * {@link ClientConnectionHandler} does).
 *
 * @see IoHandlerAdapter#sessionIdle(IoSession, IdleStatus)
 */
@Override
public void sessionIdle(IoSession session, IdleStatus status) throws Exception {
    if (session.getIdleCount(status) > 1) {
        // Get the connection for this session
        final Connection connection = (Connection) session.getAttribute(CONNECTION);
        if (connection != null) {
            // Close idle connection
            if (Log.isDebugEnabled()) {
                Log.debug("ConnectionHandler: Closing connection that has been idle: " + connection);
            }
            connection.close();
        }
    }
}
 
Example #18
Source File: HttpServer.java    From game-server with MIT License 5 votes vote down vote up
@Override
public void run() {
	DefaultIoFilterChainBuilder chain = acceptor.getFilterChain();
	chain.addLast("codec", new HttpServerCodecImpl());

	// // 线程队列池
	OrderedThreadPoolExecutor threadpool = new OrderedThreadPoolExecutor(minaServerConfig.getOrderedThreadPoolExecutorSize());
	chain.addLast("threadPool", new ExecutorFilter(threadpool));

	acceptor.setReuseAddress(minaServerConfig.isReuseAddress()); // 允许地址重用

	SocketSessionConfig sc = acceptor.getSessionConfig();
	sc.setReuseAddress(minaServerConfig.isReuseAddress());
	sc.setReceiveBufferSize(minaServerConfig.getMaxReadSize());
	sc.setSendBufferSize(minaServerConfig.getSendBufferSize());
	sc.setTcpNoDelay(minaServerConfig.isTcpNoDelay());
	sc.setSoLinger(minaServerConfig.getSoLinger());
	sc.setIdleTime(IdleStatus.READER_IDLE, minaServerConfig.getReaderIdleTime());
	sc.setIdleTime(IdleStatus.WRITER_IDLE, minaServerConfig.getWriterIdleTime());

	acceptor.setHandler(ioHandler);

	try {
		acceptor.bind(new InetSocketAddress(minaServerConfig.getHttpPort()));
		LOG.warn("已开始监听HTTP端口:{}", minaServerConfig.getHttpPort());
	} catch (IOException e) {
		SysUtil.exit(getClass(), e, "监听HTTP端口:{}已被占用", minaServerConfig.getHttpPort());
	}
}
 
Example #19
Source File: StreamIoHandler.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Initializes streams and timeout settings.
 */
@Override
public void sessionOpened(IoSession session) {
    // Set timeouts
    session.getConfig().setWriteTimeout(writeTimeout);
    session.getConfig().setIdleTime(IdleStatus.READER_IDLE, readTimeout);

    // Create streams
    InputStream in = new IoSessionInputStream();
    OutputStream out = new IoSessionOutputStream(session);
    session.setAttribute(KEY_IN, in);
    session.setAttribute(KEY_OUT, out);
    processStreamIo(session, in, out);
}
 
Example #20
Source File: StreamIoHandler.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Handles read timeout.
 */
@Override
public void sessionIdle(IoSession session, IdleStatus status) {
    if (status == IdleStatus.READER_IDLE) {
        throw new StreamIoException(new SocketTimeoutException("Read timeout"));
    }
}
 
Example #21
Source File: HelloUdpServer.java    From mina-examples with MIT License 5 votes vote down vote up
public static void main(String[] args) throws Exception {
	NioDatagramAcceptor acceptor = new NioDatagramAcceptor();//UDP Acceptor
	acceptor.getFilterChain().addLast("logging", new LoggingFilter());
	acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new ObjectSerializationCodecFactory()));
	acceptor.getFilterChain().addLast("mdc", new MdcInjectionFilter());
	acceptor.setHandler(new HelloServerHandler());
	acceptor.getSessionConfig().setReadBufferSize(2048);
	acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 10);
	DatagramSessionConfig dcfg = acceptor.getSessionConfig();
	dcfg.setReuseAddress(true);
	acceptor.bind(new InetSocketAddress(PORT));
}
 
Example #22
Source File: ClientConnectionHandler.java    From Openfire with Apache License 2.0 5 votes vote down vote up
/**
 * In addition to the functionality provided by the parent class, this
 * method will send XMPP ping requests to the remote entity on every first
 * invocation of this method (which will occur after a period of half the
 * allowed connection idle time has passed, without any IO).
 * 
 * XMPP entities must respond with either an IQ result or an IQ error
 * (feature-unavailable) stanza upon receiving the XMPP ping stanza. Both
 * responses will be received by Openfire and will cause the connection idle
 * count to be reset.
 * 
 * Entities that do not respond to the IQ Ping stanzas can be considered
 * dead, and their connection will be closed by the parent class
 * implementation on the second invocation of this method.
 * 
 * Note that whitespace pings that are sent by XMPP entities will also cause
 * the connection idle count to be reset.
 * 
 * @see ConnectionHandler#sessionIdle(IoSession, IdleStatus)
 */
@Override
public void sessionIdle(IoSession session, IdleStatus status) throws Exception {
    super.sessionIdle(session, status);
    
    final boolean doPing = ConnectionSettings.Client.KEEP_ALIVE_PING_PROPERTY.getValue();
    if (doPing && session.getIdleCount(status) == 1) {
        final ClientStanzaHandler handler = (ClientStanzaHandler) session.getAttribute(HANDLER);
        final JID entity = handler.getAddress();
        
        if (entity != null) {
            // Ping the connection to see if it is alive.
            final IQ pingRequest = new IQ(Type.get);
            pingRequest.setChildElement("ping",
                    IQPingHandler.NAMESPACE);
            pingRequest.setFrom( XMPPServer.getInstance().getServerInfo().getXMPPDomain() );
            pingRequest.setTo(entity); 
            
            // Get the connection for this session
            final Connection connection = (Connection) session.getAttribute(CONNECTION);

            if (Log.isDebugEnabled()) {
                Log.debug("ConnectionHandler: Pinging connection that has been idle: " + connection);
            }

            // OF-1497: Ensure that data sent to the client is processed through LocalClientSession, to avoid
            // synchronisation issues with stanza counts related to Stream Management (XEP-0198)!
            LocalClientSession ofSession = (LocalClientSession) SessionManager.getInstance().getSession( entity );
            if (ofSession == null) {
                Log.warn( "Trying to ping a MINA connection that's idle, but has no corresponding Openfire session. MINA Connection: " + connection );
            } else {
                ofSession.deliver( pingRequest );
            }
        }
    }
}
 
Example #23
Source File: ExecutorFilter.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public final void sessionIdle(NextFilter nextFilter, IoSession session, IdleStatus status) {
    if (eventTypes.contains(IoEventType.SESSION_IDLE)) {
        IoFilterEvent event = new IoFilterEvent(nextFilter, IoEventType.SESSION_IDLE, session, status);
        fireEvent(event);
    } else {
        nextFilter.sessionIdle(session, status);
    }
}
 
Example #24
Source File: BlacklistFilter.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void sessionIdle(NextFilter nextFilter, IoSession session, IdleStatus status) throws Exception {
    if (!isBlocked(session)) {
        // forward if not blocked
        nextFilter.sessionIdle(session, status);
    } else {
        blockSession(session);
    }
}
 
Example #25
Source File: DefaultIoFilterChain.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
private void callNextSessionIdle(Entry entry, IoSession session, IdleStatus status) {
    try {
        IoFilter filter = entry.getFilter();
        NextFilter nextFilter = entry.getNextFilter();
        filter.sessionIdle(nextFilter, session, status);
    } catch (Throwable e) {
        fireExceptionCaught(e);
    }
}
 
Example #26
Source File: Tcp.java    From jlogstash-input-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void sessionIdle(IoSession session, IdleStatus status)
		throws Exception {
	// TODO Auto-generated method stub
	logger.info("IDLE : " + session.getIdleCount(status) + ">now : "
			+ new Date());
}
 
Example #27
Source File: ServerHandler.java    From sumk with Apache License 2.0 5 votes vote down vote up
@Override
public void sessionIdle(IoSession session, IdleStatus status) {
	long time = System.currentTimeMillis() - session.getLastIoTime();
	if (time > AppInfo.getLong(Const.SOA_SESSION_IDLE, 60) * 1000) {
		log.info("rpc session {} {} for {}ms,closed by this server", session.getId(), status,
				session.getLastIoTime(), time);
		session.closeOnFlush();
	}
}
 
Example #28
Source File: ModbusMaster.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected synchronized void handleSessionCreated ( final IoSession session ) throws Exception
{
    super.handleSessionCreated ( session );
    final int timeout = this.readTimeout / 1000;
    session.getConfig ().setIdleTime ( IdleStatus.READER_IDLE, timeout );
    logger.debug ( "Setting timeout to {} seconds", timeout );
}
 
Example #29
Source File: StreamBaseDevice.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void sessionCreated ( final IoSession session ) throws Exception
{
    logger.debug ( "Session created" );

    // set for session
    session.getConfig ().setIdleTime ( IdleStatus.BOTH_IDLE, (int) ( this.timeoutTime / 1000 ) );
}
 
Example #30
Source File: AbstractConnectionDevice.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
protected synchronized void handleSessionIdle ( final IoSession session, final IdleStatus status ) throws Exception
{
    logger.warn ( "Got idle: {} / {}", status, session );

    checkSession ( session );

    disconnect ();
}