java.util.concurrent.ConcurrentHashMap#putAll ( )源码实例Demo

下面列出了java.util.concurrent.ConcurrentHashMap#putAll ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: gemfirexd-oss   文件: RegionVersionVector.java
/**
 * Retrieve a vector that can be sent to another member.  This clones all
 * of the version information to protect against concurrent modification
 * during serialization
 */
public RegionVersionVector<T> getCloneForTransmission() {
  Map<T,RegionVersionHolder<T>> liveHolders;
  liveHolders = new HashMap<T,RegionVersionHolder<T>>(this.memberToVersion);
  ConcurrentHashMap<T, RegionVersionHolder<T>> clonedHolders = new ConcurrentHashMap<T, RegionVersionHolder<T>>(
      liveHolders.size(), LOAD_FACTOR, CONCURRENCY_LEVEL);
  for (Map.Entry<T, RegionVersionHolder<T>> entry: liveHolders.entrySet()) {
    clonedHolders.put(entry.getKey(), entry.getValue().clone());
  }
  ConcurrentHashMap<T, Long> gcVersions = new ConcurrentHashMap<T, Long>(
      this.memberToGCVersion.size(), LOAD_FACTOR, CONCURRENCY_LEVEL);
  gcVersions.putAll(this.memberToGCVersion);
  RegionVersionHolder<T>  clonedLocalHolder;
  clonedLocalHolder = this.localExceptions.clone();
  //Make sure the holder that we send to the peer does
  //have an accurate RegionVersionHolder for our local version
  return createCopy(this.myId, clonedHolders, this.localVersion.get(),
      gcVersions, this.localGCVersion.get(), false, 
      clonedLocalHolder);
}
 
源代码2 项目: gemfirexd-oss   文件: RegionVersionVector.java
/**
 * Retrieve a vector that can be sent to another member.  This clones all
 * of the version information to protect against concurrent modification
 * during serialization
 */
public RegionVersionVector<T> getCloneForTransmission() {
  Map<T,RegionVersionHolder<T>> liveHolders;
  liveHolders = new HashMap<T,RegionVersionHolder<T>>(this.memberToVersion);
  ConcurrentHashMap<T, RegionVersionHolder<T>> clonedHolders = new ConcurrentHashMap<T, RegionVersionHolder<T>>(
      liveHolders.size(), LOAD_FACTOR, CONCURRENCY_LEVEL);
  for (Map.Entry<T, RegionVersionHolder<T>> entry: liveHolders.entrySet()) {
    clonedHolders.put(entry.getKey(), entry.getValue().clone());
  }
  ConcurrentHashMap<T, Long> gcVersions = new ConcurrentHashMap<T, Long>(
      this.memberToGCVersion.size(), LOAD_FACTOR, CONCURRENCY_LEVEL);
  gcVersions.putAll(this.memberToGCVersion);
  RegionVersionHolder<T>  clonedLocalHolder;
  clonedLocalHolder = this.localExceptions.clone();
  //Make sure the holder that we send to the peer does
  //have an accurate RegionVersionHolder for our local version
  return createCopy(this.myId, clonedHolders, this.localVersion.get(),
      gcVersions, this.localGCVersion.get(), false, 
      clonedLocalHolder);
}
 
源代码3 项目: jstorm   文件: TaskHeartbeatUpdater.java
public void initTaskHb() {
    this.taskHbs = new TopologyTaskHbInfo(this.topologyId, this.taskId);
    ConcurrentHashMap<Integer, TaskHeartbeat> tmpTaskHbMap = new ConcurrentHashMap<>();
    try {

        TopologyTaskHbInfo taskHbInfo = zkCluster.topology_heartbeat(topologyId);
        if (taskHbInfo != null) {
            LOG.info("Found task heartbeat info left in zk for " + topologyId + ": " + taskHbInfo.toString());
            if (taskHbInfo.get_taskHbs() != null) {
                tmpTaskHbMap.putAll(taskHbInfo.get_taskHbs());
            }
        }

    } catch (Exception e) {
        LOG.warn("Failed to get topology heartbeat from zk", e);
    }

    this.taskHbMap.set(tmpTaskHbMap);
    taskHbs.set_taskHbs(tmpTaskHbMap);
}
 
源代码4 项目: openjdk-jdk9   文件: ConcurrentHashMapTest.java
/**
 * putAll adds all key-value pairs from the given map
 */
public void testPutAll() {
    ConcurrentHashMap empty = new ConcurrentHashMap();
    ConcurrentHashMap map = map5();
    empty.putAll(map);
    assertEquals(5, empty.size());
    assertTrue(empty.containsKey(one));
    assertTrue(empty.containsKey(two));
    assertTrue(empty.containsKey(three));
    assertTrue(empty.containsKey(four));
    assertTrue(empty.containsKey(five));
}
 
源代码5 项目: j2objc   文件: ConcurrentHashMapTest.java
/**
 * putAll adds all key-value pairs from the given map
 */
public void testPutAll() {
    ConcurrentHashMap empty = new ConcurrentHashMap();
    ConcurrentHashMap map = map5();
    empty.putAll(map);
    assertEquals(5, empty.size());
    assertTrue(empty.containsKey(one));
    assertTrue(empty.containsKey(two));
    assertTrue(empty.containsKey(three));
    assertTrue(empty.containsKey(four));
    assertTrue(empty.containsKey(five));
}
 
源代码6 项目: keycloak   文件: AuthenticationSessionAdapter.java
@Override
public Map<String, String> getUserSessionNotes() {
    if (entity.getUserSessionNotes() == null) {
        return Collections.EMPTY_MAP;
    }
    ConcurrentHashMap<String, String> copy = new ConcurrentHashMap<>();
    copy.putAll(entity.getUserSessionNotes());
    return copy;
}
 
源代码7 项目: arcusplatform   文件: IrisCollections.java
@Override
public Map<K, V> create() {
 ConcurrentHashMap<K, V> map = new ConcurrentHashMap<K, V>(Math.max(this.delegate.size(), 16), 0.75f, concurrency);
 map.putAll(this.delegate);
 return map;
}
 
private <T> T manageCache(ConcurrentHashMap<Integer, WithUseCount<T>> cache, Accessor<T> accessor, int n, FieldSelector fieldSelector, int limit) throws IOException
{
    Integer key = Integer.valueOf(n);
    WithUseCount<T> value = cache.get(key);
    if (value == null)
    {
        T made = accessor.get(n, fieldSelector);
        value = new WithUseCount<T>(made, n);
        cache.put(key, value);

        // resize

        if (limit >= 0)
        {
            if (cache.size() >= limit)
            {
                HashMap<Integer, WithUseCount<T>> keep = new HashMap<Integer, WithUseCount<T>>();
                WithUseCount<T>[] existing = new WithUseCount[0];
                synchronized (cache)
                {
                    existing = cache.values().toArray(existing);
                    cache.clear();
                }
                Arrays.sort(existing);

                for (WithUseCount<T> current : existing)
                {
                    keep.put(Integer.valueOf(current.doc), current);
                    if ((current.count.get() == 0) || (keep.size() > (limit / 4)))
                    {
                        break;
                    }
                }
                keep.put(key, value);
                cache.putAll(keep);
            }
        }
    }
    else
    {
        value.count.getAndIncrement();
    }
    return value.object;
}
 
源代码9 项目: pravega-samples   文件: SharedMap.java
@Override
public void process(ConcurrentHashMap<K, V> impl) {
    impl.putAll(map);
}