Search in sources :

Example 81 with ConcurrentSkipListMap

use of java.util.concurrent.ConcurrentSkipListMap in project j2objc by google.

the class ConcurrentSkipListMapTest method testPutAll.

/**
 * putAll adds all key-value pairs from the given map
 */
public void testPutAll() {
    ConcurrentSkipListMap empty = new ConcurrentSkipListMap();
    ConcurrentSkipListMap 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));
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap)

Example 82 with ConcurrentSkipListMap

use of java.util.concurrent.ConcurrentSkipListMap in project hbase by apache.

the class TestCatalogJanitor method setup.

@Before
public void setup() throws IOException, KeeperException {
    setRootDirAndCleanIt(HTU, this.name.getMethodName());
    NavigableMap<ServerName, SortedSet<byte[]>> regionsToRegionServers = new ConcurrentSkipListMap<ServerName, SortedSet<byte[]>>();
    this.masterServices = new MockMasterServices(HTU.getConfiguration(), regionsToRegionServers);
    this.masterServices.start(10, null);
    this.janitor = new CatalogJanitor(masterServices);
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) ServerName(org.apache.hadoop.hbase.ServerName) MockMasterServices(org.apache.hadoop.hbase.master.assignment.MockMasterServices) SortedSet(java.util.SortedSet) Before(org.junit.Before)

Example 83 with ConcurrentSkipListMap

use of java.util.concurrent.ConcurrentSkipListMap in project dubbo by alibaba.

the class PojoUtils method createMap.

private static Map createMap(Map src) {
    Class<? extends Map> cl = src.getClass();
    int size = src.size();
    Map result = null;
    if (HashMap.class == cl) {
        result = new HashMap(Math.max((int) (size / .75f) + 1, 16));
    } else if (Hashtable.class == cl) {
        result = new Hashtable(Math.max((int) (size / .75f) + 1, 16));
    } else if (IdentityHashMap.class == cl) {
        result = new IdentityHashMap((int) (1 + size * 1.1));
    } else if (LinkedHashMap.class == cl) {
        result = new LinkedHashMap();
    } else if (Properties.class == cl) {
        result = new Properties();
    } else if (TreeMap.class == cl) {
        result = new TreeMap();
    } else if (WeakHashMap.class == cl) {
        return new WeakHashMap(Math.max((int) (size / .75f) + 1, 16));
    } else if (ConcurrentHashMap.class == cl) {
        result = new ConcurrentHashMap(Math.max((int) (size / .75f) + 1, 16));
    } else if (ConcurrentSkipListMap.class == cl) {
        result = new ConcurrentSkipListMap();
    } else {
        try {
            result = cl.newInstance();
        } catch (Exception e) {
        /* ignore */
        }
        if (result == null) {
            try {
                Constructor<?> constructor = cl.getConstructor(Map.class);
                result = (Map) constructor.newInstance(Collections.EMPTY_MAP);
            } catch (Exception e) {
            /* ignore */
            }
        }
    }
    if (result == null) {
        result = new HashMap<Object, Object>(Math.max((int) (size / .75f) + 1, 16));
    }
    return result;
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) WeakHashMap(java.util.WeakHashMap) IdentityHashMap(java.util.IdentityHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Hashtable(java.util.Hashtable) IdentityHashMap(java.util.IdentityHashMap) Properties(java.util.Properties) TreeMap(java.util.TreeMap) InvocationTargetException(java.lang.reflect.InvocationTargetException) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) WeakHashMap(java.util.WeakHashMap) IdentityHashMap(java.util.IdentityHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) TreeMap(java.util.TreeMap) WeakHashMap(java.util.WeakHashMap)

Example 84 with ConcurrentSkipListMap

use of java.util.concurrent.ConcurrentSkipListMap in project hive by apache.

the class LowLevelCacheImpl method getFileData.

@Override
public DiskRangeList getFileData(Object fileKey, DiskRangeList ranges, long baseOffset, DiskRangeListFactory factory, LowLevelCacheCounters qfCounters, BooleanRef gotAllData) {
    if (ranges == null)
        return null;
    DiskRangeList prev = ranges.prev;
    FileCache<ConcurrentSkipListMap<Long, LlapDataBuffer>> subCache = cache.get(fileKey);
    if (subCache == null || !subCache.incRef()) {
        long totalMissed = ranges.getTotalLength();
        metrics.incrCacheRequestedBytes(totalMissed);
        if (qfCounters != null) {
            qfCounters.recordCacheMiss(totalMissed);
        }
        if (prev != null && gotAllData != null) {
            gotAllData.value = false;
        }
        return ranges;
    }
    try {
        if (prev == null) {
            prev = new MutateHelper(ranges);
        }
        if (gotAllData != null) {
            gotAllData.value = true;
        }
        DiskRangeList current = ranges;
        while (current != null) {
            metrics.incrCacheRequestedBytes(current.getLength());
            // We assume ranges in "ranges" are non-overlapping; thus, we will save next in advance.
            DiskRangeList next = current.next;
            getOverlappingRanges(baseOffset, current, subCache.getCache(), factory, gotAllData);
            current = next;
        }
    } finally {
        subCache.decRef();
    }
    boolean isInvalid = false;
    if (qfCounters != null) {
        DiskRangeList current = prev.next;
        long bytesHit = 0, bytesMissed = 0;
        while (current != null) {
            // This assumes no ranges passed to cache to fetch have data beforehand.
            if (current.hasData()) {
                bytesHit += current.getLength();
            } else {
                if (gotAllData.value) {
                    isInvalid = true;
                }
                bytesMissed += current.getLength();
            }
            current = current.next;
        }
        qfCounters.recordCacheHit(bytesHit);
        qfCounters.recordCacheMiss(bytesMissed);
    } else if (gotAllData != null && gotAllData.value) {
        DiskRangeList current = prev.next;
        while (current != null) {
            if (!current.hasData()) {
                isInvalid = true;
                break;
            }
            current = current.next;
        }
    }
    if (isInvalid) {
        StringBuilder invalidMsg = new StringBuilder("Internal error - gotAllData=true but the resulting ranges are ").append(RecordReaderUtils.stringifyDiskRanges(prev.next));
        subCache = cache.get(fileKey);
        if (subCache != null && subCache.incRef()) {
            try {
                invalidMsg.append("; cache ranges (not necessarily consistent) are ");
                for (Map.Entry<Long, LlapDataBuffer> e : subCache.getCache().entrySet()) {
                    long start = e.getKey(), end = start + e.getValue().declaredCachedLength;
                    invalidMsg.append("[").append(start).append(", ").append(end).append("), ");
                }
            } finally {
                subCache.decRef();
            }
        } else {
            invalidMsg.append("; cache ranges can no longer be determined");
        }
        String s = invalidMsg.toString();
        LlapIoImpl.LOG.error(s);
        throw new RuntimeException(s);
    }
    return prev.next;
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) DiskRangeList(org.apache.hadoop.hive.common.io.DiskRangeList) MutateHelper(org.apache.hadoop.hive.common.io.DiskRangeList.MutateHelper) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) Map(java.util.Map)

Example 85 with ConcurrentSkipListMap

use of java.util.concurrent.ConcurrentSkipListMap in project new-cloud by xie-summer.

the class PojoUtils method createMap.

private static Map createMap(Map src) {
    Class<? extends Map> cl = src.getClass();
    Map result = null;
    if (HashMap.class == cl) {
        result = Maps.newHashMap();
    } else if (Hashtable.class == cl) {
        result = new Hashtable();
    } else if (IdentityHashMap.class == cl) {
        result = new IdentityHashMap();
    } else if (LinkedHashMap.class == cl) {
        result = Maps.newLinkedHashMap();
    } else if (Properties.class == cl) {
        result = new Properties();
    } else if (TreeMap.class == cl) {
        result = new TreeMap();
    } else if (WeakHashMap.class == cl) {
        return new WeakHashMap();
    } else if (ConcurrentHashMap.class == cl) {
        result = Maps.newConcurrentMap();
    } else if (ConcurrentSkipListMap.class == cl) {
        result = new ConcurrentSkipListMap();
    } else {
        try {
            result = cl.newInstance();
        } catch (Exception e) {
        /* ignore */
        }
        if (result == null) {
            try {
                Constructor<?> constructor = cl.getConstructor(Map.class);
                result = (Map) constructor.newInstance(Collections.EMPTY_MAP);
            } catch (Exception e) {
            /* ignore */
            }
        }
    }
    if (result == null) {
        result = Maps.newHashMap();
    }
    return result;
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) Hashtable(java.util.Hashtable) IdentityHashMap(java.util.IdentityHashMap) Properties(java.util.Properties) TreeMap(java.util.TreeMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) WeakHashMap(java.util.WeakHashMap) IdentityHashMap(java.util.IdentityHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) TreeMap(java.util.TreeMap) InvocationTargetException(java.lang.reflect.InvocationTargetException) LinkedHashMap(java.util.LinkedHashMap) WeakHashMap(java.util.WeakHashMap)

Aggregations

ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)183 Test (org.junit.Test)66 PollStatus (org.opennms.netmgt.poller.PollStatus)32 MonitoredService (org.opennms.netmgt.poller.MonitoredService)31 Map (java.util.Map)30 ServiceMonitor (org.opennms.netmgt.poller.ServiceMonitor)25 MqttDeviceTwin (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceTwin)23 HashMap (java.util.HashMap)21 DeviceTwinMessage (com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceTwinMessage)17 NavigableMap (java.util.NavigableMap)14 Set (java.util.Set)12 Iterator (java.util.Iterator)11 NavigableSet (java.util.NavigableSet)11 MockMonitoredService (org.opennms.netmgt.poller.mock.MockMonitoredService)11 IOException (java.io.IOException)10 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)10 ArrayList (java.util.ArrayList)9 BitSet (java.util.BitSet)9 DeviceOperations (com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceOperations)8 JUnitHttpServer (org.opennms.core.test.http.annotations.JUnitHttpServer)8