當前位置: 首頁>>代碼示例>>Java>>正文


Java IdleStatus.READER_IDLE屬性代碼示例

本文整理匯總了Java中org.apache.mina.core.session.IdleStatus.READER_IDLE屬性的典型用法代碼示例。如果您正苦於以下問題:Java IdleStatus.READER_IDLE屬性的具體用法?Java IdleStatus.READER_IDLE怎麽用?Java IdleStatus.READER_IDLE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在org.apache.mina.core.session.IdleStatus的用法示例。


在下文中一共展示了IdleStatus.READER_IDLE屬性的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: sessionIdle

@Override
public void sessionIdle(IoSession session, IdleStatus status) throws Exception {
    com.lts.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));
    }
}
 
開發者ID:WenZuHuai,項目名稱:light-task-scheduler,代碼行數:24,代碼來源:MinaHandler.java

示例2: sessionIdle

@Override
public void sessionIdle(IoSession session, IdleStatus status) throws Exception {
	//System.out.println("SERVER: IDLE " + status + " " + session.getAttribute("idle"));
	//System.out.println("Server: " + status + " " + session.getAttribute("idle") + " IIDDDEEEELLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL");
	if (status == IdleStatus.WRITER_IDLE || status == IdleStatus.BOTH_IDLE) {
		session.write(new HBMsg());
	}
	if (status == IdleStatus.READER_IDLE || status == IdleStatus.BOTH_IDLE) {
		Integer idle = (Integer)session.getAttribute("idle");
		if (idle == null) {
			idle = 0;
		}
		++idle;
		session.setAttribute("idle", idle);
		if (idle == 5) {
			//System.out.println("Server: CCCLLLOOOSSSINNNGGGG Session due to inactivity.");
			session.close(true);
		}
	}
}
 
開發者ID:induwarabas,項目名稱:simple-event-loop,代碼行數:20,代碼來源:Server.java

示例3: sessionIdle

@Override
public void sessionIdle(IoSession session, IdleStatus status) throws Exception {
	//System.out.println("CLIENT: IDLE " + status + " " + session.getAttribute("idle"));
	//System.out.println("Client: " + status + " " + session.getAttribute("idle") + " IIDDDEEEELLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL");
	if (status == IdleStatus.WRITER_IDLE) {
		session.write(new HBMsg());
	}
	if (status == IdleStatus.READER_IDLE) {
		Integer idle = (Integer)session.getAttribute("idle");
		if (idle == null) {
			idle = 0;
		}
		++idle;
		session.setAttribute("idle", idle);
		if (idle == 5) {
			//System.out.println("Client: CCCLLLOOOSSSINNNGGGG Session due to inactivity.");
			session.close(true);
		}
	}
}
 
開發者ID:induwarabas,項目名稱:simple-event-loop,代碼行數:20,代碼來源:Client.java

示例4: sessionIdle

/**
 * Handles read timeout.
 */
@Override
public void sessionIdle(IoSession session, IdleStatus status) {
    if (status == IdleStatus.READER_IDLE) {
        throw new StreamIoException(new SocketTimeoutException("Read timeout"));
    }
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:9,代碼來源:StreamIoHandler.java

示例5: sessionIdle

@Override
public void sessionIdle(NextFilter nextFilter, IoSession session, IdleStatus status) throws Exception {
    if (status == interestedIdleStatus) {
        if (!session.containsAttribute(WAITING_FOR_RESPONSE)) {
            Object pingMessage = messageFactory.getRequest(session);
            if (pingMessage != null) {
                nextFilter.filterWrite(session, new DefaultWriteRequest(pingMessage));

                // If policy is OFF, there's no need to wait for
                // the response.
                if (getRequestTimeoutHandler() != KeepAliveRequestTimeoutHandler.DEAF_SPEAKER) {
                    markStatus(session);
                    if (interestedIdleStatus == IdleStatus.BOTH_IDLE) {
                        session.setAttribute(IGNORE_READER_IDLE_ONCE);
                    }
                } else {
                    resetStatus(session);
                }
            }
        } else {
            handlePingTimeout(session);
        }
    } else if (status == IdleStatus.READER_IDLE) {
        if (session.removeAttribute(IGNORE_READER_IDLE_ONCE) == null) {
            if (session.containsAttribute(WAITING_FOR_RESPONSE)) {
                handlePingTimeout(session);
            }
        }
    }

    if (forwardEvent) {
        nextFilter.sessionIdle(session, status);
    }
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:34,代碼來源:KeepAliveFilter.java

示例6: sessionIdle

@Override
public void sessionIdle(IoSession session, IdleStatus status) {
	// Close the connection if reader is idle.
	if (status == IdleStatus.READER_IDLE) {
		session.close(true);
	}
}
 
開發者ID:East196,項目名稱:maker,代碼行數:7,代碼來源:NetCatProtocolHandler.java

示例7: sessionIdle

/** {@inheritDoc} */
@Override
public void sessionIdle(IoSession session, IdleStatus status) throws Exception {
    // @see http://issues.opennms.org/browse/NMS-5311
    if (getConversation().hasBanner() && status == IdleStatus.READER_IDLE) {
        LogUtils.infof(this, "Session went idle without receiving banner. Setting service detection to false.");
        getFuture().setServiceDetected(false);
        session.close(true);
    }
}
 
開發者ID:qoswork,項目名稱:opennmszh,代碼行數:10,代碼來源:BaseDetectorHandler.java

示例8: sessionIdle

@Override
public void sessionIdle(IoSession session, IdleStatus status) {
    if (status == IdleStatus.READER_IDLE) {
        session.close(false);
        m_channelMapper.remove(session);
        //TODO send a notification to messaging part to remove the bining clientID-ConnConfig
    }
}
 
開發者ID:milliondreams,項目名稱:moquette-mqtt,代碼行數:8,代碼來源:MinaMQTTHandler.java

示例9: run

@Override
    public void run() {
        IoConnector connector = new NioSocketConnector();
        connector.setConnectTimeoutMillis(CONNECT_TIMEOUT);//設置連接超時時間(毫秒數)
        connector.getFilterChain().addLast("logger", new LoggingFilter());
        connector.getFilterChain().addLast("codec", new ProtocolCodecFilter(new CommandCodecFactory("UTF-8")));

        KeepAliveMessageFactoryImpl kamfi = new KeepAliveMessageFactoryImpl();
        KeepAliveFilter kaf = new KeepAliveFilter(kamfi, IdleStatus.READER_IDLE, KeepAliveRequestTimeoutHandler.CLOSE);
        /** 是否回發 */
        kaf.setForwardEvent(true);
        connector.getFilterChain().addLast("heart", kaf);

        connector.setHandler(new CalculatorClientHander());
        ConnectFuture connectFuture = connector.connect(new InetSocketAddress(IP, PORT));
        //等待建立連接
        connectFuture.awaitUninterruptibly();

        if(!connectFuture.isConnected()){
            log.debug("連接失敗");
            return ;
        }
        log.debug("連接成功");

        IoSession session = connectFuture.getSession();

//        try {
//            Cmd1003 cmd1003 = (Cmd1003) CommandFactory.createCommand(CidConst.C1003);
//            cmd1003.getReqMsg().setCpu(0.3f);
//            cmd1003.getReqMsg().setDisk(0.24f);
//            cmd1003.getReqMsg().setMemory(0.41f);
//            session.write(cmd1003);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }


        //關閉
        if (session != null) {
            if (session.isConnected()) {
                session.getCloseFuture().awaitUninterruptibly();
            }
            connector.dispose(true);
        }
    }
 
開發者ID:Keybo1013,項目名稱:mina,代碼行數:45,代碼來源:CalculatorClient.java

示例10: KeepAliveFilter

/**
 * Creates a new instance with the default properties.
 * The default property values are:
 * <ul>
 * <li><tt>interestedIdleStatus</tt> - {@link IdleStatus#READER_IDLE}</li>
 * <li><tt>policy</tt> = {@link KeepAliveRequestTimeoutHandler#CLOSE}</li>
 * <li><tt>keepAliveRequestInterval</tt> - 60 (seconds)</li>
 * <li><tt>keepAliveRequestTimeout</tt> - 30 (seconds)</li>
 * </ul>
 */
public KeepAliveFilter(KeepAliveMessageFactory messageFactory) {
    this(messageFactory, IdleStatus.READER_IDLE, KeepAliveRequestTimeoutHandler.CLOSE);
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:13,代碼來源:KeepAliveFilter.java


注:本文中的org.apache.mina.core.session.IdleStatus.READER_IDLE屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。