@Override
    public HandlerStatus onRead() throws Exception {
        src.flip();
        try {
            while (src.hasRemaining()) {
                Packet packet = packetReader.readFrom(src);
                if (packet == null) {
                    break;
                }
                onPacketComplete(packet);
            }

            return CLEAN;
        } finally {
            compactOrClear(src);
        }
    }
@Test
    public void whenMultiplePackets() throws Exception {
        ByteBuffer src = ByteBuffer.allocate(1000);

        Packet packet1 = new Packet(serializationService.toBytes("packet1"));
        new PacketIOHelper().writeTo(packet1, src);

        Packet packet2 = new Packet(serializationService.toBytes("packet2"));
        new PacketIOHelper().writeTo(packet2, src);

        Packet packet3 = new Packet(serializationService.toBytes("packet3"));
        new PacketIOHelper().writeTo(packet3, src);

        Packet packet4 = new Packet(serializationService.toBytes("packet4"));
        packet4.raiseFlags(Packet.FLAG_URGENT);
        new PacketIOHelper().writeTo(packet4, src);

        decoder.src(src);
        decoder.onRead();

        assertEquals(asList(packet1, packet2, packet3, packet4), dispatcher.packets);
        assertEquals(3, normalPacketCounter.get());
        assertEquals(1, priorityPacketCounter.get());
    }