예제 #1
0
  @Override
  public void messageReceived(IoSession session, Object message) throws Exception {
    super.messageReceived(session, message);

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

    IoHandler handler = handlers.remove(session);
    handler.sessionClosed(session);
  }
예제 #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);
   }
 }
예제 #4
0
  @Override
  public void sessionOpened(IoSession session) throws Exception {
    super.sessionOpened(session);

    IoHandler handler = new MinaNetworkClientHandler(networkService, eventAdminTracker);
    handlers.put(session, handler);
    handler.sessionOpened(session);
  }
예제 #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);
  }
예제 #6
0
 @Override
 public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
   // TODO Auto-generated method stub
   super.exceptionCaught(session, cause);
 }
예제 #7
0
 @Override
 public void sessionCreated(IoSession ioSession) throws Exception {
   super.sessionCreated(ioSession);
   networkingOptions.apply(ioSession);
 }
예제 #8
0
 @Override
 public void sessionCreated(IoSession session) throws Exception {
   final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(new MinaChannel(session));
   LOGGER.info("{} : sessionCreated {}", sideType, remoteAddress);
   super.sessionCreated(session);
 }
예제 #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);
  }
예제 #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);
 }
예제 #15
0
 @Override
 public void sessionOpened(IoSession session) throws Exception {
   System.out.println("sessionOpened");
   super.sessionOpened(session);
 }
예제 #16
0
 @Override
 public void sessionCreated(IoSession session) throws Exception {
   System.out.println(session.getId() + ":sessionCreated");
   super.sessionCreated(session);
 }
예제 #17
0
 @Override
 public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
   System.out.println("exception");
   session.close(true);
   super.exceptionCaught(session, cause);
 }
예제 #18
0
 @Override
 public void messageSent(IoSession session, Object message) throws Exception {
   super.messageSent(session, message);
   LogUtil.print("messageSent:" + message.toString());
 }