Example usage for java.util.concurrent ConcurrentNavigableMap size

List of usage examples for java.util.concurrent ConcurrentNavigableMap size

Introduction

In this page you can find the example usage for java.util.concurrent ConcurrentNavigableMap size.

Prototype

int size();

Source Link

Document

Returns the number of key-value mappings in this map.

Usage

From source file:org.apache.hama.graph.IncomingVertexMessageManager.java

public List<GraphJobMessage> getRelevantMessages(String peerName) {
    HashPartitioner<WritableComparable, IntWritable> partitioner = new HashPartitioner();
    List<GraphJobMessage> msgs = new ArrayList<GraphJobMessage>();
    ConcurrentNavigableMap<WritableComparable, List<WritableComparable>> offsetMap = msgPerVertex
            .getVertexIdOffsetMap();/*from www.jav  a  2 s.  c  o m*/
    HashMap<WritableComparable, GraphJobMessage> aggregatorMap = msgPerVertex.getMessageAggregatorMap();
    if (offsetMap.size() != aggregatorMap.size()) {
        LOG.info("[ERROR IncomingVertexManager.java] Size mismatch!");
    }

    for (WritableComparable<?> dstVertexId : offsetMap.keySet()) {

        List<WritableComparable> list = offsetMap.get(dstVertexId);
        GraphJobMessage aggregatorGraphMsg = aggregatorMap.get(dstVertexId);
        byte[] valueArray = aggregatorGraphMsg.getValuesBytes();
        int messageSizeBytes = valueArray.length / aggregatorGraphMsg.getNumOfValues();

        Iterator<WritableComparable> it = list.iterator();
        Iterator<Writable> aggregateIt = aggregatorGraphMsg.getIterableMessages().iterator();
        while (it.hasNext()) {
            WritableComparable srcId = it.next();
            int partition = partitioner.getPartition(srcId, null, peer.getNumPeers());
            String srcPeer = peer.getAllPeerNames()[partition];
            if (srcPeer.equals(peerName)) {
                GraphJobMessage newMsg = new GraphJobMessage(dstVertexId, aggregateIt.next(), srcId);
                msgs.add(newMsg);
            } else {
                aggregateIt.next();
            }
        }
    }
    return msgs;
}

From source file:voldemort.store.cachestore.impl.SortedCacheStore.java

public List<KeyValue> scan(Key from, Key to) {
    Key floor = findFloorKey(getSkipListMap(map), from);
    Key ceil = findCeilKey(getSkipListMap(map), to);
    ConcurrentNavigableMap<Key, CacheBlock> subMap = getSkipListMap(map).subMap(floor, true, ceil, true);
    if (subMap != null) {
        int j = 0;
        List<KeyValue> list = new ArrayList<KeyValue>(subMap.size());
        Iterator<Key> keyIt = subMap.keySet().iterator();
        for (int i = 0; i < subMap.size(); i++) {
            Key key = keyIt.next();
            if (key != null && !skipKey(key, from, to)) {
                Value value = super.get(key);
                if (value != null) {
                    list.add(new KeyValue(key, value));
                    j++;/*from   w ww  .  j  a  v  a 2  s  .c o  m*/
                }
            }
            if (j > MAX_SIZE) {
                logger.warn("exceed max list size " + MAX_SIZE);
                break;
            }
        }
        return list;
    }
    return null;
}