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));
}
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);
}
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;
}
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;
}
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;
}
Aggregations