Example #1
0
    public SessionListener(Session session) {
      m_session = session;

      System.out.println(
          "PubClient: connected "
              + session.getLocalAddress()
              + " -> "
              + session.getRemoteAddress());

      final ByteBuffer buf = ByteBuffer.allocateDirect(5);
      buf.putInt(5);
      buf.put((byte) 0);
      buf.position(0);
      session.sendData(buf);
    }
Example #2
0
 public ServerListener(Session session) {
   m_session = session;
   m_stream =
       new StreamDefragger(4) {
         protected int validateHeader(ByteBuffer header) {
           return header.getInt();
         }
       };
   System.out.println("Connection accepted from " + session.getRemoteAddress());
 }
Example #3
0
    public void onDataReceived(RetainableByteBuffer data) {
      if (data.remaining() == 0) throw new AssertionError();

      RetainableByteBuffer msg = m_stream.getNext(data);

      msg.getInt(); /* skip message length */
      final int testType = msg.getInt();
      switch (testType) {
        case 1:
          m_session.replaceListener(new Test1Listener(m_session, m_stream));
          break;

        case 2:
          m_session.replaceListener(new Test2Listener(m_session, m_stream));
          break;

        default:
          throw new AssertionError();
      }
    }
Example #4
0
 public void onConnectionClosed() {
   System.out.println("PubClient: connection closed.");
   if (m_thread != null) {
     try {
       m_thread.join();
     } catch (final InterruptedException ex) {
       ex.printStackTrace();
     }
     m_thread = null;
   }
   m_session.getCollider().stop();
 }
Example #5
0
    public void run() {
      final ByteBuffer buf = ByteBuffer.allocateDirect(m_messageLength);
      buf.putInt(m_messageLength);
      buf.putInt(m_messages);
      for (int idx = 8; idx < m_messageLength; idx++) buf.put((byte) idx);
      buf.position(0);

      m_startTime = System.nanoTime();
      for (int idx = 0; idx < m_messages; idx++) m_session.sendData(buf);
      final long endTime = System.nanoTime();

      // m_session.closeConnection();

      System.out.println(
          "PubClient: sent "
              + m_messages
              + " messages at "
              + Util.formatDelay(m_startTime, endTime));
    }
Example #6
0
 public void onConnectionClosed() {
   if (m_testsDone.incrementAndGet() == 2) m_session.getCollider().stop();
 }