Java Code Examples for java.util.concurrent.ConcurrentHashMap#putAll()

The following examples show how to use java.util.concurrent.ConcurrentHashMap#putAll() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RegionVersionVector.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example 2
Source File: RegionVersionVector.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example 3
Source File: TaskHeartbeatUpdater.java    From jstorm with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 4
Source File: ConcurrentHashMapTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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));
}
 
Example 5
Source File: ConcurrentHashMapTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * 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));
}
 
Example 6
Source File: AuthenticationSessionAdapter.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 7
Source File: IrisCollections.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
@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;
}
 
Example 8
Source File: ReferenceCountingReadOnlyIndexReaderFactory.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
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;
}
 
Example 9
Source File: SharedMap.java    From pravega-samples with Apache License 2.0 4 votes vote down vote up
@Override
public void process(ConcurrentHashMap<K, V> impl) {
    impl.putAll(map);
}