private ChannelInfo insertChannelIntoOrderedChain(Channel channel, 
    		int priority, int packetQuota)
    {
        ChannelInfo channelInfo = new ChannelInfo(channel, packetQuota);

        //if list is empty, create one and insert channel there.
        if (channelInfoGroupList.isEmpty())
        {
        	ChannelInfoGroup channelInfoGroup = new ChannelInfoGroup(priority);
        	channelInfoGroup.insertChannelInfo(channelInfo);
        	channelInfoGroupList.add(channelInfoGroup);
            return channelInfo;
        }

        //Search for group in the list order by the priority
        ChannelInfoGroup after = null;

        int pos = 0;
        for (ChannelInfoGroup cif :  channelInfoGroupList)
        {
            if (priority >= cif.priority)
            {
            	after = cif;
                break;
            }
        }

        ChannelInfoGroup parentGroup = null;
        
        // If reaches the end, create a new group and append
        // into the queue
        if (after == null)
        {
            ChannelInfoGroup newGroup = new ChannelInfoGroup(priority);
            channelInfoGroupList.add(newGroup);

            parentGroup = newGroup;
        }
        // If a group with same priority found, insert directly
        else if (priority == after.priority)
        {
            parentGroup = after;
        }
        // Otherwise, insert a new group before the "after".
        else
        {
            ChannelInfoGroup newGroup = new ChannelInfoGroup(priority);
            channelInfoGroupList.add(pos, newGroup);

            parentGroup = newGroup;

        }

        // Insert into the group
        parentGroup.insertChannelInfo(channelInfo);
        return channelInfo;
    }