@Override
  public void messageReceived(IoSession session, Object message) throws Exception {
    super.messageReceived(session, message);

    IoHandler handler = handlers.get(session);
    handler.messageReceived(session, message);
  }
  @Override
  public void sessionClosed(IoSession session) throws Exception {
    super.sessionClosed(session);

    IoHandler handler = handlers.remove(session);
    handler.sessionClosed(session);
  }
Esempio n. 3
0
 @Override
 public void sessionIdle(IoSession session, IdleStatus status) throws Exception {
   super.sessionIdle(session, status);
   // 如果IoSession闲置,则关闭连接
   if (status == IdleStatus.BOTH_IDLE) {
     session.write(HEARTBEATRESPONSE);
   }
 }
  @Override
  public void sessionOpened(IoSession session) throws Exception {
    super.sessionOpened(session);

    IoHandler handler = new MinaNetworkClientHandler(networkService, eventAdminTracker);
    handlers.put(session, handler);
    handler.sessionOpened(session);
  }
Esempio n. 5
0
  /** {@inheritDoc} */
  @Override
  public void sessionOpened(IoSession session) throws Exception {
    SocketSessionConfig ssc = (SocketSessionConfig) session.getConfig();
    ssc.setTcpNoDelay(true);
    // ssc.setReceiveBufferSize(2048);
    // ssc.setSendBufferSize(2048);

    super.sessionOpened(session);
  }
 @Override
 public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
   // TODO Auto-generated method stub
   super.exceptionCaught(session, cause);
 }
Esempio n. 7
0
 @Override
 public void sessionCreated(IoSession ioSession) throws Exception {
   super.sessionCreated(ioSession);
   networkingOptions.apply(ioSession);
 }
 @Override
 public void sessionCreated(IoSession session) throws Exception {
   final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(new MinaChannel(session));
   LOGGER.info("{} : sessionCreated {}", sideType, remoteAddress);
   super.sessionCreated(session);
 }
Esempio n. 9
0
  /** {@inheritDoc} */
  @SuppressWarnings("resource")
  @Override
  public void sessionCreated(IoSession session) throws Exception {

    boolean isClient = session.getRemoteAddress().equals(forward);

    if (log.isDebugEnabled()) {
      log.debug("Is downstream: " + isClient);
      session.getFilterChain().addFirst("protocol", new ProtocolCodecFilter(codecFactory));
    }

    session.getFilterChain().addFirst("proxy", new ProxyFilter(isClient ? "client" : "server"));

    if (true) {

      String fileName =
          System.currentTimeMillis()
              + '_'
              + forward.getHostName()
              + '_'
              + forward.getPort()
              + '_'
              + (isClient ? "DOWNSTREAM" : "UPSTREAM");

      File headersFile = loader.getResource(dumpTo + fileName + ".cap").getFile();
      headersFile.createNewFile();

      File rawFile = loader.getResource(dumpTo + fileName + ".raw").getFile();
      rawFile.createNewFile();

      FileOutputStream headersFos = new FileOutputStream(headersFile);
      WritableByteChannel headers = headersFos.getChannel();

      FileOutputStream rawFos = new FileOutputStream(rawFile);
      WritableByteChannel raw = rawFos.getChannel();

      IoBuffer header = IoBuffer.allocate(1);
      header.put((byte) (isClient ? 0x00 : 0x01));
      header.flip();
      headers.write(header.buf());

      session.getFilterChain().addFirst("dump", new NetworkDumpFilter(headers, raw));
    }

    // session.getFilterChain().addLast("logger", new LoggingFilter() );

    if (!isClient) {
      log.debug("Connecting..");
      IoConnector connector = new NioSocketConnector();
      connector.setHandler(this);
      ConnectFuture future = connector.connect(forward);
      future.awaitUninterruptibly(); // wait for connect, or timeout
      if (future.isConnected()) {
        if (log.isDebugEnabled()) {
          log.debug("Connected: {}", forward);
        }
        IoSession client = future.getSession();
        client.setAttribute(ProxyFilter.FORWARD_KEY, session);
        session.setAttribute(ProxyFilter.FORWARD_KEY, client);
      }
    }
    super.sessionCreated(session);
  }
Esempio n. 10
0
 @Override
 public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
   cause.printStackTrace();
   super.exceptionCaught(session, cause);
 }
 @Override
 public void sessionOpened(IoSession session) throws Exception {
   log.debug("Session Opened.");
   super.sessionOpened(session);
 }
 @Override
 public void sessionIdle(IoSession session, IdleStatus status) throws Exception {
   log.debug("IDLE " + session.getIdleCount(status));
   super.sessionIdle(session, status);
 }
    @Override
    public void sessionCreated(IoSession session) throws Exception {
      super.sessionCreated(session);

      session.getConfig().setIdleTime(IdleStatus.READER_IDLE, 5);
    }
 @Override
 public void sessionCreated(IoSession session) throws Exception {
   super.sessionCreated(session);
   session.getFilterChain().addLast("codec", streamWriteFilter);
 }
Esempio n. 15
0
 @Override
 public void sessionOpened(IoSession session) throws Exception {
   System.out.println("sessionOpened");
   super.sessionOpened(session);
 }
Esempio n. 16
0
 @Override
 public void sessionCreated(IoSession session) throws Exception {
   System.out.println(session.getId() + ":sessionCreated");
   super.sessionCreated(session);
 }
Esempio n. 17
0
 @Override
 public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
   System.out.println("exception");
   session.close(true);
   super.exceptionCaught(session, cause);
 }
Esempio n. 18
0
 @Override
 public void messageSent(IoSession session, Object message) throws Exception {
   super.messageSent(session, message);
   LogUtil.print("messageSent:" + message.toString());
 }