Search in sources :

Example 1 with AbstractQueue

use of java.util.AbstractQueue in project eureka by Netflix.

the class Applications method shuffleAndFilterInstances.

/**
     * Shuffle the instances and filter for only {@link InstanceStatus#UP} if
     * required.
     *
     */
private void shuffleAndFilterInstances(Map<String, AbstractQueue<InstanceInfo>> srcMap, Map<String, AtomicReference<List<InstanceInfo>>> destMap, Map<String, AtomicLong> vipIndexMap, boolean filterUpInstances) {
    for (Map.Entry<String, AbstractQueue<InstanceInfo>> entries : srcMap.entrySet()) {
        AbstractQueue<InstanceInfo> instanceInfoQueue = entries.getValue();
        List<InstanceInfo> l = new ArrayList<InstanceInfo>(instanceInfoQueue);
        if (filterUpInstances) {
            Iterator<InstanceInfo> it = l.iterator();
            while (it.hasNext()) {
                InstanceInfo instanceInfo = it.next();
                if (!InstanceStatus.UP.equals(instanceInfo.getStatus())) {
                    it.remove();
                }
            }
        }
        Collections.shuffle(l);
        AtomicReference<List<InstanceInfo>> instanceInfoList = destMap.get(entries.getKey());
        if (instanceInfoList == null) {
            instanceInfoList = new AtomicReference<List<InstanceInfo>>(l);
            destMap.put(entries.getKey(), instanceInfoList);
        }
        instanceInfoList.set(l);
        vipIndexMap.put(entries.getKey(), new AtomicLong(0));
    }
    // finally remove all vips that are completed deleted (i.e. missing) from the srcSet
    Set<String> srcVips = srcMap.keySet();
    Set<String> destVips = destMap.keySet();
    destVips.retainAll(srcVips);
}
Also used : ArrayList(java.util.ArrayList) InstanceInfo(com.netflix.appinfo.InstanceInfo) AtomicLong(java.util.concurrent.atomic.AtomicLong) AbstractQueue(java.util.AbstractQueue) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TreeMap(java.util.TreeMap)

Aggregations

InstanceInfo (com.netflix.appinfo.InstanceInfo)1 AbstractQueue (java.util.AbstractQueue)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1