Example usage for java.util.concurrent ConcurrentMap entrySet

List of usage examples for java.util.concurrent ConcurrentMap entrySet

Introduction

In this page you can find the example usage for java.util.concurrent ConcurrentMap entrySet.

Prototype

Set<Map.Entry<K, V>> entrySet();

Source Link

Document

Returns a Set view of the mappings contained in this map.

Usage

From source file:org.apache.hadoop.mapreduce.v2.app.speculate.DefaultSpeculator.java

private int maybeScheduleASpeculation(TaskType type) {
    int successes = 0;

    long now = clock.getTime();

    ConcurrentMap<JobId, AtomicInteger> containerNeeds = type == TaskType.MAP ? mapContainerNeeds
            : reduceContainerNeeds;/* ww w  .  jav a  2 s  .  com*/

    for (ConcurrentMap.Entry<JobId, AtomicInteger> jobEntry : containerNeeds.entrySet()) {
        // This race conditon is okay.  If we skip a speculation attempt we
        //  should have tried because the event that lowers the number of
        //  containers needed to zero hasn't come through, it will next time.
        // Also, if we miss the fact that the number of containers needed was
        //  zero but increased due to a failure it's not too bad to launch one
        //  container prematurely.
        if (jobEntry.getValue().get() > 0) {
            continue;
        }

        int numberSpeculationsAlready = 0;
        int numberRunningTasks = 0;

        // loop through the tasks of the kind
        Job job = context.getJob(jobEntry.getKey());

        Map<TaskId, Task> tasks = job.getTasks(type);

        int numberAllowedSpeculativeTasks = (int) Math.max(minimumAllowedSpeculativeTasks,
                proportionTotalTasksSpeculatable * tasks.size());

        TaskId bestTaskID = null;
        long bestSpeculationValue = -1L;

        // this loop is potentially pricey.
        // TODO track the tasks that are potentially worth looking at
        for (Map.Entry<TaskId, Task> taskEntry : tasks.entrySet()) {
            long mySpeculationValue = speculationValue(taskEntry.getKey(), now);

            if (mySpeculationValue == ALREADY_SPECULATING) {
                ++numberSpeculationsAlready;
            }

            if (mySpeculationValue != NOT_RUNNING) {
                ++numberRunningTasks;
            }

            if (mySpeculationValue > bestSpeculationValue) {
                bestTaskID = taskEntry.getKey();
                bestSpeculationValue = mySpeculationValue;
            }
        }
        numberAllowedSpeculativeTasks = (int) Math.max(numberAllowedSpeculativeTasks,
                proportionRunningTasksSpeculatable * numberRunningTasks);

        // If we found a speculation target, fire it off
        if (bestTaskID != null && numberAllowedSpeculativeTasks > numberSpeculationsAlready) {
            addSpeculativeAttempt(bestTaskID);
            ++successes;
        }
    }

    return successes;
}

From source file:org.apache.hadoop.metrics2.lib.MutableRatesWithAggregation.java

@Override
public synchronized void snapshot(MetricsRecordBuilder rb, boolean all) {
    Iterator<WeakReference<ConcurrentMap<String, ThreadSafeSampleStat>>> iter = weakReferenceQueue.iterator();
    while (iter.hasNext()) {
        ConcurrentMap<String, ThreadSafeSampleStat> map = iter.next().get();
        if (map == null) {
            // Thread has died; clean up its state
            iter.remove();//from   w w w . ja  v  a  2s  . c  om
        } else {
            // Aggregate the thread's local samples into the global metrics
            for (Map.Entry<String, ThreadSafeSampleStat> entry : map.entrySet()) {
                String name = entry.getKey();
                MutableRate globalMetric = addMetricIfNotExists(name);
                entry.getValue().snapshotInto(globalMetric);
            }
        }
    }
    for (MutableRate globalMetric : globalMetrics.values()) {
        globalMetric.snapshot(rb, all);
    }
}

From source file:org.apereo.portal.portlets.search.SearchPortletController.java

/**
 * Return the search results in a sorted map based on priority of the search result type
 * @param resultsMap Search results map//from  w w w  .j a v  a  2  s .c o  m
 * @return Sorted map of search results ordered on search result type priority
 */
private SortedMap<Integer, List<AutocompleteResultsModel>> getCleanedAndSortedMapResults(
        ConcurrentMap<String, List<Tuple<SearchResult, String>>> resultsMap, int maxTextLength) {
    SortedMap<Integer, List<AutocompleteResultsModel>> prioritizedResultsMap = createAutocompletePriorityMap();

    // Put the results into the map of <priority,list>
    for (Map.Entry<String, List<Tuple<SearchResult, String>>> entry : resultsMap.entrySet()) {
        for (Tuple<SearchResult, String> tupleSearchResult : entry.getValue()) {
            SearchResult searchResult = tupleSearchResult.getFirst();
            List<String> resultTypes = searchResult.getType();
            // If the search result doesn't have a type defined, use the undefined result type.
            if (resultTypes.size() == 0) {
                resultTypes = UNDEFINED_SEARCH_RESULT_TYPE;
            }
            for (String category : resultTypes) {
                // Exclude the result if it is a result type that's in the ignore list.
                if (!autocompleteIgnoreResultTypes.contains(category)) {
                    int priority = calculatePriorityFromCategory(category);
                    AutocompleteResultsModel result = new AutocompleteResultsModel(
                            cleanAndTrimString(searchResult.getTitle(), maxTextLength),
                            cleanAndTrimString(searchResult.getSummary(), maxTextLength),
                            tupleSearchResult.getSecond(), category);
                    prioritizedResultsMap.get(priority).add(result);
                }
            }
        }
    }
    return prioritizedResultsMap;
}

From source file:org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.java

private static void cleanUpObjectStreamClassCaches(@Nonnull Class<?> clazz) throws Exception {
    Class<?> cachesC = Class.forName("java.io.ObjectStreamClass$Caches");
    for (String cacheFName : new String[] { "localDescs", "reflectors" }) {
        Field cacheF = cachesC.getDeclaredField(cacheFName);
        cacheF.setAccessible(true);/*from  w ww. ja v  a2s  .  co  m*/
        ConcurrentMap<Reference<Class<?>>, ?> cache = (ConcurrentMap) cacheF.get(null);
        Iterator<? extends Entry<Reference<Class<?>>, ?>> iterator = cache.entrySet().iterator();
        while (iterator.hasNext()) {
            if (iterator.next().getKey().get() == clazz) {
                iterator.remove();
                LOGGER.log(Level.FINER, "cleaning up {0} from ObjectStreamClass.Caches.{1}",
                        new Object[] { clazz.getName(), cacheFName });
                break;
            }
        }
    }
}

From source file:org.onosproject.yms.app.ysr.DefaultYangSchemaRegistry.java

private String getLatestVersion(ConcurrentMap<String, YangSchemaNode> revMap) {
    List<String> keys = new ArrayList<>();
    for (Map.Entry<String, YangSchemaNode> entry : revMap.entrySet()) {
        keys.add(entry.getKey());//from  www. j  av  a  2  s.c o m
    }
    sort(keys);
    return keys.get(keys.size() - 1);
}

From source file:org.slc.sli.dal.convert.SubDocAccessor.java

public static void main(String[] args) {
    PrintStream output = System.out;
    SubDocAccessor accessor = new SubDocAccessor(null, null, null);
    ConcurrentMap<String, List<String>> collections = new ConcurrentHashMap<String, List<String>>();
    for (Entry<String, Location> entry : accessor.locations.entrySet()) {
        String type = entry.getKey();
        String collectionName = entry.getValue().collection;
        collections.putIfAbsent(collectionName, new ArrayList<String>());
        collections.get(collectionName).add(type);
    }/*from www .ja  v a 2s.  c  om*/
    for (Entry<String, List<String>> entry : collections.entrySet()) {
        output.println(entry.getKey() + ": " + StringUtils.join(entry.getValue().toArray(), ", "));
    }
}

From source file:org.wisdom.framework.mustache.ExtendedMustacheFactory.java

/**
 * Removes the template from the cache./*from  ww w .j  a  v  a 2  s.  c om*/
 *
 * @param template the template
 */
public void clear(MustacheTemplate template) {
    mustacheCache.remove(template.name());
    if (template.compiled != null) {
        ConcurrentMap<FragmentKey, Mustache> map = new ConcurrentHashMap<>(templateCache);
        for (Map.Entry<FragmentKey, Mustache> entry : map.entrySet()) {
            if (entry.getValue().equals(template.compiled)) {
                templateCache.remove(entry.getKey());
            }
        }
    }
}