Example usage for java.util.concurrent ConcurrentMap get

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

Introduction

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

Prototype

V get(Object key);

Source Link

Document

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Usage

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   w ww.j a  v a  2  s .co m
    for (Entry<String, List<String>> entry : collections.entrySet()) {
        output.println(entry.getKey() + ": " + StringUtils.join(entry.getValue().toArray(), ", "));
    }
}

From source file:Main.java

/**
 * If map already has a value associated with the key it adds values to that
 * value, otherwise it will put values to the map.  Do not reuse values.
 *
 * @param key    Key under which we are adding values
 * @param values Values we want to add/*w  w  w . j  a va  2s  . co  m*/
 * @param map    Map which we are adding values to
 * @param <K> Key
 * @param <V> Value
 * @param <C> Collection
 * @return New value associated with the key
 */
public static <K, V, C extends Collection<V>> C addConcurrent(K key, C values, ConcurrentMap<K, C> map) {
    C currentValues = map.get(key);
    if (currentValues == null) {
        currentValues = map.putIfAbsent(key, values);
        if (currentValues == null) {
            return values;
        }
    }
    synchronized (currentValues) {
        currentValues.addAll(values);
    }
    return currentValues;
}

From source file:Main.java

public static void addLong(ConcurrentMap<String, AtomicLong> map, String key, long delta) {
    map.putIfAbsent(key, new AtomicLong(0));
    map.get(key).getAndAdd(delta);
}

From source file:Main.java

public static void setLong(ConcurrentMap<String, AtomicLong> map, String key, long newValue) {
    map.putIfAbsent(key, new AtomicLong(0));
    map.get(key).getAndSet(newValue);
}

From source file:org.linagora.linshare.webservice.utils.FlowUploaderUtils.java

public static java.nio.file.Path getTempFile(String identifier, ConcurrentMap<String, ChunkedFile> chunkedFiles)
        throws IOException {
    ChunkedFile chunkedFile = chunkedFiles.get(identifier);
    if (chunkedFile == null) {
        java.nio.file.Path path = Files.createTempFile("ls-chunks-" + identifier, ".temp");
        chunkedFiles.putIfAbsent(identifier, new ChunkedFile(path));
        chunkedFile = chunkedFiles.get(identifier);
    }//from w  ww .j ava2  s  .c o m
    return chunkedFile.getPath();
}

From source file:org.linagora.linshare.webservice.utils.FlowUploaderUtils.java

public static boolean isUploadFinished(String identifier, long chunkSize, long totalSize,
        ConcurrentMap<String, ChunkedFile> chunkedFiles) {
    double numberOfChunks = computeNumberOfChunks(chunkSize, totalSize);
    return chunkedFiles.get(identifier).getChunks().size() == numberOfChunks;
}

From source file:org.apache.ranger.common.TestTimedExecutor.java

static void recordResult(ConcurrentMap<String, AtomicInteger> results, String key) {
    if (results.containsKey(key)) {
        results.get(key).incrementAndGet();
    } else {//  w w  w  .ja va2s  . c o m
        AtomicInteger previous = results.putIfAbsent(key, new AtomicInteger(1));
        if (previous != null) { // a value was already associated with the key
            previous.incrementAndGet();
        }
    }
}

From source file:com.google.api.ads.adwords.jaxws.extensions.kratu.restserver.AbstractServerResource.java

@SuppressWarnings("unchecked")
static Series<Header> getMessageHeaders(Message message) {
    ConcurrentMap<String, Object> attrs = message.getAttributes();
    Series<Header> headers = (Series<Header>) attrs.get(HEADERS_KEY);
    if (headers == null) {
        headers = new Series<Header>(Header.class);
        Series<Header> prev = (Series<Header>) attrs.putIfAbsent(HEADERS_KEY, headers);
        if (prev != null) {
            headers = prev;//  ww w. j av a 2s .  c o m
        }
    }
    return headers;
}

From source file:xbird.util.nio.RemoteMemoryMappedFile.java

public static void handleResponse(final ReadRequestMessage request, final ProtocolEncoderOutput out,
        final ConcurrentMap<String, FileChannel> fdCacheMap) {
    final String filePath = request.filePath;

    FileChannel fileChannel = fdCacheMap.get(filePath);
    if (fileChannel == null) {
        File file = new File(filePath);
        if (!file.exists()) {
            throw new IllegalStateException("file not exists: " + filePath);
        }//from   w  w w  .  j  a  va  2s  . c o  m
        final RandomAccessFile raf;
        try {
            raf = new RandomAccessFile(file, "r");
        } catch (FileNotFoundException e) {
            throw new IllegalStateException(e);
        }
        fileChannel = raf.getChannel();
        fdCacheMap.put(filePath, fileChannel);
    }
    long count = request.endOffset - request.startOffset;
    long position = request.startOffset;

    if (LOG.isDebugEnabled()) {
        LOG.debug("Transfer " + count + " bytes of file '" + filePath + "' from the offset " + position);
    }

    FileRegion fileRegion = new DefaultFileRegion(fileChannel, position, count);
    out.write(fileRegion);
}

From source file:org.archive.io.warc.WARCWriter.java

public static long getStat(ConcurrentMap<String, ConcurrentMap<String, AtomicLong>> map, String key,
        String subkey) {/*from w  w  w .  j  a  v a 2  s  .c  om*/
    if (map != null && map.get(key) != null && map.get(key).get(subkey) != null) {
        return map.get(key).get(subkey).get();
    } else {
        return 0l;
    }
}