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:Test.java

public static void main(String[] args) {
    ConcurrentMap<Integer, String> concurrentMap = new ConcurrentHashMap<Integer, String>();
    for (int i = 0; i < 1000; i++) {
        startUpdateThread(i, concurrentMap);
    }//from ww w  .  jav a 2 s.co m
    for (Map.Entry<Integer, String> entry : concurrentMap.entrySet()) {
        System.out.println("Key :" + entry.getKey() + " Value:" + entry.getValue());
    }
    for (Thread thread : updateThreads) {
        thread.interrupt();
    }
}

From source file:Main.java

public static void main(String[] args) {
    List<Person> roster = createRoster();
    ConcurrentMap<Person.Sex, List<Person>> byGenderParallel = roster.parallelStream()
            .collect(Collectors.groupingByConcurrent(Person::getGender));

    List<Map.Entry<Person.Sex, List<Person>>> byGenderList = new ArrayList<>(byGenderParallel.entrySet());

    System.out.println("Group members by gender:");
    byGenderList.stream().forEach(e -> {
        System.out.println("Gender: " + e.getKey());
        e.getValue().stream().map(Person::getName).forEach(f -> System.out.println(f));
    });//from   ww  w .  j  av  a 2  s. c  o m

}

From source file:com.opengamma.component.ComponentConfigLoader.java

private String applyReplacements(String line, ConcurrentMap<String, String> properties) {
    for (Entry<String, String> entry : properties.entrySet()) {
        line = StringUtils.replace(line, entry.getKey(), entry.getValue());
    }//from   w ww.  j a  va 2s .  com
    return line;
}

From source file:com.bt.aloha.media.conference.collections.ConferenceCollectionImpl.java

public ConferenceInfo getCurrentConferenceForCall(String callId) {
    log.debug(String.format("Getting current conference from ConferenceCollection for call %s", callId));
    String mostRecentConferenceId = null;
    long mostRecentConferenceCreateTime = 0;

    ConcurrentMap<String, ConferenceInfo> allConferenceInfos = getAll();
    for (Map.Entry<String, ConferenceInfo> entry : allConferenceInfos.entrySet()) {
        ConferenceInfo conferenceInfo = entry.getValue();
        if (conferenceInfo.containsParticipant(callId)) {
            long createTime = conferenceInfo.getCreateTime();
            if (createTime > mostRecentConferenceCreateTime) {
                mostRecentConferenceId = entry.getKey();
                mostRecentConferenceCreateTime = createTime;
            }//from   w  ww.  j a v  a  2 s  . co  m
        }
    }

    if (mostRecentConferenceId != null) {
        ConferenceInfo result = collection.get(mostRecentConferenceId);
        log.debug(String.format("Current conference for call %s is %s with sipUri %s", callId,
                mostRecentConferenceId, result.getConferenceSipUri()));
        return result;
    } else {
        log.debug("No conference for call " + callId);
        return null;
    }
}

From source file:com.bt.aloha.call.collections.CallCollectionImpl.java

public CallInfo getCurrentCallForCallLeg(String dialogId, String callIdToIgnore) {
    log.debug(String.format("Getting current call from CallCollection for dialog %s, ignoring call id %s",
            dialogId, callIdToIgnore));/*from   w w w. j a v a  2 s.  c  o  m*/
    String mostRecentCallId = null;
    long mostRecentCallCreateTime = 0;
    ConcurrentMap<String, CallInfo> allCallInfos = getAll();
    for (Map.Entry<String, CallInfo> entry : allCallInfos.entrySet()) {
        if (entry.getKey().equals(callIdToIgnore))
            continue;
        ImmutableCallInfo callInfo = entry.getValue();
        if (dialogId.equals(callInfo.getFirstDialogId()) || dialogId.equals(callInfo.getSecondDialogId())) {
            long createTime = callInfo.getCreateTime();
            if (createTime > mostRecentCallCreateTime) {
                mostRecentCallId = entry.getKey();
                mostRecentCallCreateTime = createTime;
            }
        }

    }

    if (mostRecentCallId != null) {
        CallInfo result = collection.get(mostRecentCallId);
        if (null != result)
            log.debug(String.format(
                    "Current call for dialog %s is %s, containing first dialogId %s and second dialog %s",
                    dialogId, mostRecentCallId, result.getFirstDialogId(), result.getSecondDialogId()));
        else
            log.debug(String.format("Current call (%s) for dialog %s not found, returning null",
                    mostRecentCallId, dialogId));
        return result;
    } else {
        log.debug(String.format("Dialog %s not in a call", dialogId));
        return null;
    }
}

From source file:com.adobe.acs.commons.util.impl.AbstractGuavaCacheMBean.java

@Override
public final String getCacheSize() {
    // Iterate through the cache entries and compute the total size of byte array.
    long size = 0L;
    ConcurrentMap<K, V> cacheAsMap = getCache().asMap();
    for (final Map.Entry<K, V> entry : cacheAsMap.entrySet()) {
        size += getBytesLength(entry.getValue());
    }/*from   w ww .j  a  v  a  2 s .  com*/

    // Convert bytes to human-friendly format
    return FileUtils.byteCountToDisplaySize(size);
}

From source file:com.adobe.acs.commons.util.impl.AbstractGuavaCacheMBean.java

@Override
public final TabularData getCacheContents() throws OpenDataException {
    final CompositeType cacheEntryType = getCacheEntryType();

    final TabularDataSupport tabularData = new TabularDataSupport(
            new TabularType("Cache Entries", "Cache Entries", cacheEntryType, new String[] { "Cache Key" }));

    ConcurrentMap<K, V> cacheAsMap = getCache().asMap();
    for (final Map.Entry<K, V> entry : cacheAsMap.entrySet()) {
        final Map<String, Object> data = new HashMap<String, Object>();
        data.put("Cache Key", entry.getKey().toString());

        V cacheObj = entry.getValue();// w  ww  .  j av  a2s . c om
        if (cacheObj != null) {
            addCacheData(data, cacheObj);
        }

        tabularData.put(new CompositeDataSupport(cacheEntryType, data));
    }

    return tabularData;
}

From source file:com.sastix.cms.server.services.cache.hazelcast.HazelcastCacheService.java

@Override
public void clearCache() {
    LOG.info("HazelcastCacheService->CLEAR_ALL_CACHE_REGIONS_AND_MAIN_CACHE");
    ConcurrentMap<String, IMap> caches = cm.getCaches();
    for (Map.Entry<String, IMap> entry : caches.entrySet()) {
        entry.getValue().clear();/*from   w  w  w.  j a  v a  2  s.c o m*/
    }
    this.cache.clear();
    cm.clearAllCaches();
}

From source file:com.sastix.cms.server.services.cache.hazelcast.HazelcastCacheService.java

@Override
public void clearCacheExcept(List<String> cacheRegions) {
    LOG.info("HazelcastCacheService->CLEAR_ALL_CACHE_REGIONS_AND_MAIN_CACHE Except for specific values");
    ConcurrentMap<String, IMap> caches = cm.getCaches();
    for (Map.Entry<String, IMap> entry : caches.entrySet()) {
        String region = entry.getValue().getName();
        boolean exists = cacheRegions.stream().filter(s -> region.contains(s)).count() > 0;
        if (!exists) {
            entry.getValue().clear();//  w ww. j av  a 2s  .  c om
        }
    }
    this.cache.clear();
    cm.clearAllCachesExcept(cacheRegions);
}

From source file:com.buaa.cfs.nfs3.DFSClientCache.java

/**
 * Close all DFSClient instances in the Cache.
 *
 * @param onlyAutomatic only close those that are marked for automatic closing
 *///  w  w  w .j ava2 s . co m
synchronized void closeAll(boolean onlyAutomatic) throws IOException {
    List<IOException> exceptions = new ArrayList<IOException>();

    ConcurrentMap<String, DFSClient> map = clientCache.asMap();

    for (Entry<String, DFSClient> item : map.entrySet()) {
        final DFSClient client = item.getValue();
        if (client != null) {
            try {
                client.close();
            } catch (IOException ioe) {
                exceptions.add(ioe);
            }
        }
    }

    if (!exceptions.isEmpty()) {
        throw MultipleIOException.createIOException(exceptions);
    }
}