public static void serveRead(ReactorSession session) throws IOException {
		ByteBuffer buffer = session.getInBuffer();
		SocketChannel socketChannel = (SocketChannel) session.getSelectionKey().channel();

		// Read the data.
		int amount = socketChannel.read(buffer);
		if (amount == -1) {
			session.disconnect();
			return; // End of stream.
		}
		if (amount == 0) {
			return; // No bytes read.
		}

		// Decode and produce all messages.
		buffer.flip();
		while (buffer.hasRemaining()) {
			Message message = null;
			if ((message = session.getDecoder().decode(buffer)) == null) {
				// The message is incomplete.
				buffer.flip();
				buffer.compact();
				return;
			}
			buffer.clear();
			session.produce(message);
		}
	}