本文整理匯總了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));
}
}
示例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);
}
}
}
示例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);
}
}
}
示例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"));
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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
}
}
示例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);
}
}
示例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);
}