public int onMessageReceived(RetainableByteBuffer msg) { final int messages = ++m_messages; if (messages < REPLY_MESSAGES) { final ByteBuffer reply = ByteBuffer.allocateDirect(msg.remaining()); msg.get(reply); reply.flip(); final int rc = m_session.sendData(reply); if (rc < 0) throw new AssertionError(); return 0; } else if (messages == REPLY_MESSAGES) { final int messageLength = msg.remaining(); assert (messageLength >= 8); final ByteBuffer reply = ByteBuffer.allocateDirect(messageLength); msg.get(reply); reply.flip(); reply.putInt(4, -1); int rc = m_session.sendData(reply); if (rc < 0) throw new AssertionError(); rc = m_session.closeConnection(); if (rc != 0) throw new AssertionError(); rc = m_session.sendData(reply); if (rc != -1) throw new AssertionError(); return -1; } else { /* Listener should not receive any messages * after Session.closeConnection() call. */ throw new AssertionError(); } }
public int onMessageReceived(RetainableByteBuffer msg) { /* Just send message back */ final ByteBuffer reply = ByteBuffer.allocateDirect(msg.remaining()); msg.get(reply); reply.flip(); final int rc = m_session.sendData(reply); if (rc >= 0) m_processedMessages++; return 0; }
public void onDataReceived(RetainableByteBuffer data) { /* All subscribers are connected to the server, * let's start. */ if (data.remaining() == 0) throw new AssertionError(); m_thread = new Thread(this); m_thread.start(); }
public void onDataReceived(RetainableByteBuffer data) { if (data.remaining() == 0) throw new AssertionError(); RetainableByteBuffer msg = m_stream.getNext(data); while (msg != null) { final int rc = onMessageReceived(msg); if (rc != 0) break; msg = m_stream.getNext(); } }
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(); } }