当前位置: 首页>>代码示例>>Java>>正文


Java IdleStatus类代码示例

本文整理汇总了Java中org.apache.mina.common.IdleStatus的典型用法代码示例。如果您正苦于以下问题:Java IdleStatus类的具体用法?Java IdleStatus怎么用?Java IdleStatus使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


IdleStatus类属于org.apache.mina.common包,在下文中一共展示了IdleStatus类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sessionOpened

import org.apache.mina.common.IdleStatus; //导入依赖的package包/类
@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(CHARSET);
       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.setIdleTime(IdleStatus.READER_IDLE, idleTime);
       }
   }
 
开发者ID:coodeer,项目名称:g3server,代码行数:19,代码来源:ConnectionHandler.java

示例2: sessionIdle

import org.apache.mina.common.IdleStatus; //导入依赖的package包/类
@Override
public void sessionIdle(NextFilter nextFilter, IoSession session, IdleStatus status) throws Exception {
    try {
        if (status == IdleStatus.WRITER_IDLE) {
            nioLogger.log(PROTOCOL, session, "CougarProtocolCodecFilter: sending KEEP_ALIVE");
            session.write(KEEP_ALIVE);
            heartbeatsSent.incrementAndGet();
        } else {
            nioLogger.log(PROTOCOL, session, "CougarProtocolCodecFilter: KEEP_ALIVE timeout closing session");
            session.close();
            heartbeatsMissed.incrementAndGet();
        }
    } finally {
        nextFilter.sessionIdle(session, status);
    }
}
 
开发者ID:betfair,项目名称:cougar,代码行数:17,代码来源:CougarProtocol3.java

示例3: sessionOpened

import org.apache.mina.common.IdleStatus; //导入依赖的package包/类
@Override
public void sessionOpened(final IoSession session) throws Exception {
	
    // Start of IP checking
    final String address = session.getRemoteAddress().toString().split(":")[0];
    final short port = Short.parseShort(session.getServiceAddress().toString().split(":")[1]);
    
    if (LoginServer.isShutdown()) {
        session.close();
        return;
    }

    // IV used to decrypt packets from client.
    final byte ivRecv[] = new byte[]{(byte) Randomizer.nextInt(255), (byte) Randomizer.nextInt(255), (byte) Randomizer.nextInt(255), (byte) Randomizer.nextInt(255)};
    
    // IV used to encrypt packets for client.
    final byte ivSend[] = new byte[]{(byte) Randomizer.nextInt(255), (byte) Randomizer.nextInt(255), (byte) Randomizer.nextInt(255), (byte) Randomizer.nextInt(255)};

    MapleClient client = new MapleClient(
            new MapleAESOFB(skey, ivSend, (short) (0xFFFF - ServerConstants.MAPLE_VERSION)),
            new MapleAESOFB(skey, ivRecv, ServerConstants.MAPLE_VERSION), session);
    client.setChannel(-1);

    MaplePacketDecoder.DecoderState decoderState = new MaplePacketDecoder.DecoderState();
    session.setAttribute(MaplePacketDecoder.DECODER_STATE_KEY, decoderState);
    
    session.write(LoginPacket.getHello(ServerConstants.MAPLE_VERSION, ivSend, ivRecv));
    session.setAttribute(MapleClient.CLIENT_KEY, client);
    session.setIdleTime(IdleStatus.READER_IDLE, 60);
    session.setIdleTime(IdleStatus.WRITER_IDLE, 60);

    System.out.println("Connection Established " + address + ":"+port);
}
 
开发者ID:ergothvs,项目名称:Lucid2.0,代码行数:34,代码来源:MapleServerHandler.java

示例4: sessionIdle

import org.apache.mina.common.IdleStatus; //导入依赖的package包/类
@Override
public void sessionIdle(final IoSession session, final IdleStatus status) throws Exception {
    final MapleClient client = (MapleClient) session.getAttribute(MapleClient.CLIENT_KEY);

    if (client != null) {
        // client.sendPing();
    }
    super.sessionIdle(session, status);
}
 
开发者ID:ergothvs,项目名称:Lucid2.0,代码行数:10,代码来源:MapleServerHandler.java

示例5: sessionOpened

import org.apache.mina.common.IdleStatus; //导入依赖的package包/类
@Override
public void sessionOpened(final IoSession session) throws Exception {
    //log.info("IoSession with {} opened", session.getRemoteAddress());
    if (channel > -1) {
        if (ChannelServer.getInstance(channel).isShutdown()) {
            session.close();
            return;
        }
    }
    final byte[] key = {
        (byte) 0x13, (byte) 0x00, (byte) 0x00, (byte) 0x00,
        (byte) 0x08, (byte) 0x00, (byte) 0x00, (byte) 0x00,
        (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00,
        (byte) 0xB4, (byte) 0x00, (byte) 0x00, (byte) 0x00,
        (byte) 0x1B, (byte) 0x00, (byte) 0x00, (byte) 0x00,
        (byte) 0x0F, (byte) 0x00, (byte) 0x00, (byte) 0x00,
        (byte) 0x33, (byte) 0x00, (byte) 0x00, (byte) 0x00,
        (byte) 0x52, (byte) 0x00, (byte) 0x00, (byte) 0x00
    };
    final byte[] ivRecv = {(byte) 70, (byte) 114, (byte) 122, (byte) 82};
    final byte[] ivSend = {(byte) 82, (byte) 48, (byte) 120, (byte) 115};
    ivRecv[3] = (byte) (Math.random() * 255.0d);
    ivSend[3] = (byte) (Math.random() * 255.0d);
    final MapleAESOFB sendCypher = new MapleAESOFB(key, ivSend, (short) (0xFFFF - MAPLE_VERSION));
    final MapleAESOFB recvCypher = new MapleAESOFB(key, ivRecv, MAPLE_VERSION);
    final MapleClient client = new MapleClient(sendCypher, recvCypher, session);
    client.setChannel(channel);
    session.write(MaplePacketCreator.getHello(MAPLE_VERSION, ivSend, ivRecv, false));
    session.setAttribute(MapleClient.CLIENT_KEY, client);
    session.setIdleTime(IdleStatus.READER_IDLE, 30);
    session.setIdleTime(IdleStatus.WRITER_IDLE, 30);
}
 
开发者ID:NoetherEmmy,项目名称:intransigentms,代码行数:33,代码来源:MapleServerHandler.java

示例6: sessionIdle

import org.apache.mina.common.IdleStatus; //导入依赖的package包/类
@Override
public void sessionIdle(final IoSession session, final IdleStatus status) throws Exception {
    final MapleClient client = (MapleClient) session.getAttribute(MapleClient.CLIENT_KEY);
    /*
    if (client != null && client.getPlayer() != null) {
        System.out.println("Player " + client.getPlayer().getName() + " went idle.");
    }
    */
    if (client != null) client.sendPing();
    super.sessionIdle(session, status);
}
 
开发者ID:NoetherEmmy,项目名称:intransigentms,代码行数:12,代码来源:MapleServerHandler.java

示例7: sessionOpened

import org.apache.mina.common.IdleStatus; //导入依赖的package包/类
@Override
public void sessionOpened(IoSession session) throws Exception
{
    log.log(Level.FINE,"session opened!");
	
	session.setIdleTime(IdleStatus.BOTH_IDLE, 60);
}
 
开发者ID:voodoodyne,项目名称:subetha,代码行数:8,代码来源:PostfixTcpTableService.java

示例8: sessionIdle

import org.apache.mina.common.IdleStatus; //导入依赖的package包/类
@Override
public void sessionIdle(IoSession session, IdleStatus status) throws Exception
{
    log.log(Level.FINE,"Closing idle connection with status {0}", status);
	
	session.close();
}
 
开发者ID:voodoodyne,项目名称:subetha,代码行数:8,代码来源:PostfixTcpTableService.java

示例9: sessionIdle

import org.apache.mina.common.IdleStatus; //导入依赖的package包/类
/**
* 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 = JiveGlobals.getBooleanProperty("xmpp.client.idle.ping", true);
      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(serverName);
		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);
        }

        connection.deliver(pingRequest);
          }
      }
  }
 
开发者ID:coodeer,项目名称:g3server,代码行数:49,代码来源:ClientConnectionHandler.java

示例10: sessionIdle

import org.apache.mina.common.IdleStatus; //导入依赖的package包/类
public void sessionIdle(IoSession session, IdleStatus status) throws Exception
{
    if (IdleStatus.WRITER_IDLE.equals(status))
    {
        ((ProtocolEngine) session.getAttachment()).writerIdle();
    }
    else if (IdleStatus.READER_IDLE.equals(status))
    {
        ((ProtocolEngine) session.getAttachment()).readerIdle();
    }
}
 
开发者ID:wso2,项目名称:andes,代码行数:12,代码来源:MinaNetworkHandler.java

示例11: sessionOpened

import org.apache.mina.common.IdleStatus; //导入依赖的package包/类
@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.
       XMLLightweightParser parser = new XMLLightweightParser(CHARSET);
       session.setAttribute(XML_PARSER, parser);
       // Create a new NIOConnection for the new session
       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
       int idleTime = getMaxIdleTime();
       if (idleTime > 0) {
           session.setIdleTime(IdleStatus.READER_IDLE, idleTime);
       }
   }
 
开发者ID:igniterealtime,项目名称:Openfire-connectionmanager,代码行数:16,代码来源:ConnectionHandler.java

示例12: sessionIdle

import org.apache.mina.common.IdleStatus; //导入依赖的package包/类
@Override
public void sessionIdle(IoSession session, IdleStatus status) throws Exception {
       // Get the connection for this session
       Connection connection = (Connection) session.getAttribute(CONNECTION);
       // Close idle connection
       if (Log.isDebugEnabled()) {
           Log.debug("Closing connection that has been idle: " + connection);
       }
       connection.close();
   }
 
开发者ID:igniterealtime,项目名称:Openfire-connectionmanager,代码行数:11,代码来源:ConnectionHandler.java

示例13: sessionIdle

import org.apache.mina.common.IdleStatus; //导入依赖的package包/类
@Override
public void sessionIdle(final IoSession session, final IdleStatus status) throws Exception {
    MapleClient client = (MapleClient) session.getAttribute(MapleClient.CLIENT_KEY);

    if (client != null) {
        client.sendPing();
    }
    super.sessionIdle(session, status);
}
 
开发者ID:skorch37,项目名称:Asteria,代码行数:10,代码来源:MapleServerHandler.java

示例14: sessionCreated

import org.apache.mina.common.IdleStatus; //导入依赖的package包/类
@Override
public void sessionCreated(NextFilter nextFilter, IoSession session) throws Exception {
    session.setIdleTime(IdleStatus.READER_IDLE, timeout);
    session.setIdleTime(IdleStatus.WRITER_IDLE, interval);
    nextFilter.sessionCreated(session);

    nioLogger.log(SESSION, session, "CougarProtocolCodecFilter: Created session at %s from %s", session.getCreationTime(), session.getRemoteAddress());
    sessionsCreated.incrementAndGet();
    lastSessionFrom = session.getRemoteAddress().toString();
}
 
开发者ID:betfair,项目名称:cougar,代码行数:11,代码来源:CougarProtocol3.java

示例15: sessionIdle

import org.apache.mina.common.IdleStatus; //导入依赖的package包/类
public void sessionIdle (IoSession session, IdleStatus status)
  throws Exception
{
  if (status == READER_IDLE && linkFor (session) == null)
  {
    warn ("Disconnecting incoming federation connection from " + 
          hostIdFor (session) + 
          " due to failure to send connect request", this);
    
    session.close ();
  }
}
 
开发者ID:luv,项目名称:avis_zmqprx,代码行数:13,代码来源:Acceptor.java


注:本文中的org.apache.mina.common.IdleStatus类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。