public OutgoingPacket getNextPacket(String connectionKey, Pointer<PacketInfo> pPacketInfo)
    {
    	synchronized(lock)
        {
    		Integer value = connectionMap.get(connectionKey);
    		if (value == null && requireRegistration)
    			return null;
    		
    		int previouslyInsertedId = 0;
    		if (value != null)
    			previouslyInsertedId = value.intValue();

    		// Try to find the PacketInfo by the position value
    		// stored in the map
    		PacketInfo searchItem = head;
            while (searchItem != null && searchItem.queuePosition <= previouslyInsertedId)
            {
                searchItem = searchItem.next;
            }

            // If found, increment the reference and return the packet
            if (searchItem != null)
            {
                searchItem.incrementRefCount();
                pPacketInfo.setValue(searchItem);
                return searchItem.packet;
            }
            
            return null;
        }
    }