本文整理匯總了Java中org.apache.mina.core.session.IdleStatus.BOTH_IDLE屬性的典型用法代碼示例。如果您正苦於以下問題:Java IdleStatus.BOTH_IDLE屬性的具體用法?Java IdleStatus.BOTH_IDLE怎麽用?Java IdleStatus.BOTH_IDLE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類org.apache.mina.core.session.IdleStatus
的用法示例。
在下文中一共展示了IdleStatus.BOTH_IDLE屬性的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
public static void main(String[] args) throws IOException {
IoAcceptor acceptor = new NioSocketAcceptor();
// acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, IDELTIMEOUT);
acceptor.getFilterChain().addLast("logger", new LoggingFilter());
acceptor.getFilterChain().addLast("myfliter", new MyFilter());
acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new CommandCodecFactory("UTF-8")));
KeepAliveMessageFactoryImpl kamfi = new KeepAliveMessageFactoryImpl();
KeepAliveFilter kaf = new KeepAliveFilter(kamfi, IdleStatus.BOTH_IDLE);
/** 是否回發 */
kaf.setForwardEvent(true);
acceptor.getFilterChain().addLast("heart", kaf);
acceptor.setHandler(new CalculatorHandler());
acceptor.bind(new InetSocketAddress(PORT));
log.debug("socket通信服務端已啟動,端口是" + PORT);
}
示例2: 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));
}
}
示例3: 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);
}
}
}
示例4: 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);
}
}
示例5: initConnector
private void initConnector(InetSocketAddress isa, TransportConfig config) {
// create connector
ioConnector = new NioSocketConnector(1);
ioConnector.setConnectTimeoutMillis(config.getConnectTimeout());
SocketSessionConfig sessionConfig = ioConnector.getSessionConfig();
sessionConfig.setTcpNoDelay(true);
sessionConfig.setReceiveBufferSize(8 * 1024);
sessionConfig.setSendBufferSize(8 * 1024);
DefaultIoFilterChainBuilder chainBuilder = ioConnector.getFilterChain();
final TransportProtocolEncoder encoder = new TransportProtocolEncoder();
final TransportProtocolDecoder decoder = new TransportProtocolDecoder();
encoder.setMaxObjectSize(config.getMaxSize());
decoder.setMaxObjectSize(config.getMaxSize());
// add filter
chainBuilder.addLast("codec", new ProtocolCodecFilter(encoder, decoder));
// add keep alive filter
ActiveKeepAliveMessageFactory messageFactory = new ActiveKeepAliveMessageFactory(config.getSerializeType());
KeepAliveFilter kaFilter = new KeepAliveFilter(messageFactory, IdleStatus.BOTH_IDLE);
kaFilter.setRequestInterval(config.getHeartbeatIntervalSeconds());
kaFilter.setForwardEvent(true);
chainBuilder.addLast("keepAlive", kaFilter);
// set handler
ioConnector.setHandler(new MinaIoHandler());
ioConnector.setDefaultRemoteAddress(isa);
}
示例6: bind
@Override
public MinaAcceptance bind() {
// This socket acceptor will handle incoming connections
acceptor = new NioSocketAcceptor(transportConfig.getNioProcessorCount());
acceptor.setReuseAddress(true);
acceptor.setBacklog(128);
SocketSessionConfig sessionConfig = acceptor.getSessionConfig();
sessionConfig.setTcpNoDelay(true);
// set read buffer size
sessionConfig.setReceiveBufferSize(16 * 1024);
sessionConfig.setSendBufferSize(16 * 1024);
// get filter chain builder
DefaultIoFilterChainBuilder chainBuilder = acceptor.getFilterChain();
// add message codec filter
final TransportProtocolEncoder encoder = new TransportProtocolEncoder();
final TransportProtocolDecoder decoder = new TransportProtocolDecoder();
encoder.setMaxObjectSize(transportConfig.getMaxSize());
decoder.setMaxObjectSize(transportConfig.getMaxSize());
chainBuilder.addLast("codec", new ProtocolCodecFilter(encoder, decoder));
// add keep alive filter
KeepAliveFilter kaFilter = new KeepAliveFilter(new PassiveKeepAliveMessageFactory(), IdleStatus.BOTH_IDLE);
kaFilter.setRequestInterval(transportConfig.getHeartbeatIntervalSeconds());
kaFilter.setForwardEvent(true);
chainBuilder.addLast("keepAlive", kaFilter);
// add business handler
acceptor.setHandler(new MinaIoHandler());
try {
acceptor.bind(serviceAddress);
int processorCount = transportConfig.getBusinessProcessorCount();
if (processorCount > 0) {
NamedThreadFactory threadFactory = new NamedThreadFactory("Mina-BusinssProcessor");
executorService = Executors.newFixedThreadPool(processorCount, threadFactory);
}
} catch (Exception e) {
throw new RuntimeException("can't bind service on " + serviceAddress, e);
}
LOG.info("mina acceptance bind on {}", serviceAddress);
return this;
}