本文整理了Java中java.util.concurrent.ConcurrentSkipListMap
类的一些代码示例,展示了ConcurrentSkipListMap
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ConcurrentSkipListMap
类的具体详情如下:
包路径:java.util.concurrent.ConcurrentSkipListMap
类名称:ConcurrentSkipListMap
[英]Base of iterator classes:
[中]迭代器类的基:
代码示例来源:origin: apache/pulsar
/**
* Construct a new RangeLruCache.
*
* @param weighter
* a custom weighter to compute the size of each stored value
*/
public RangeCache(Weighter<Value> weighter) {
this.size = new AtomicLong(0);
this.entries = new ConcurrentSkipListMap<>();
this.weighter = weighter;
}
代码示例来源:origin: Alluxio/alluxio
public void addChild(String name, Long id) {
if (mChildren != null && mChildren.put(name, id) == null) {
mWeight.incrementAndGet();
}
}
代码示例来源:origin: apache/storm
private V load(K key) {
V val = map.get(key);
if (val == null) {
val = cacheLoader.load(key);
if (val == null) {
throw new NullPointerException("Null value for key " + key);
}
ensureCapacity();
map.put(key, val);
++size;
}
return val;
}
代码示例来源:origin: apache/hbase
public void deleteRegion(final RegionInfo regionInfo) {
regionsMap.remove(regionInfo.getRegionName());
// See HBASE-20860
// After master restarts, merged regions' RIT state may not be cleaned,
// making sure they are cleaned here
if (regionInTransition.containsKey(regionInfo)) {
regionInTransition.remove(regionInfo);
}
// Remove from the offline regions map too if there.
if (this.regionOffline.containsKey(regionInfo)) {
if (LOG.isTraceEnabled()) LOG.trace("Removing from regionOffline Map: " + regionInfo);
this.regionOffline.remove(regionInfo);
}
}
代码示例来源:origin: apache/hive
private TagState getTagState(String tag) {
TagState state = tagInfo.get(tag);
if (state == null) {
state = new TagState(tag);
TagState old = tagInfo.putIfAbsent(tag, state);
state = (old == null) ? state : old;
}
return state;
}
代码示例来源:origin: neo4j/neo4j
private static void doCheckFree( long pointer )
{
long count = freeCounter.getAndIncrement();
Allocation allocation = allocations.remove( pointer );
if ( allocation == null )
{
StringBuilder sb = new StringBuilder( format( "Bad free: 0x%x, valid pointers are:", pointer ) );
allocations.forEach( ( k, v ) -> sb.append( '\n' ).append( k ) );
throw new AssertionError( sb.toString() );
}
int idx = (int) (count & 4095);
freeTraces[idx] = new FreeTrace( pointer, allocation, count );
}
代码示例来源:origin: alibaba/jstorm
/**
* Adds an old value with a fixed timestamp to the reservoir.
*
* @param value the value to be added
* @param timestamp the epoch timestamp of {@code value} in seconds
*/
public void update(long value, long timestamp) {
rescaleIfNeeded();
lockForRegularUsage();
try {
final double itemWeight = weight(timestamp - startTime);
final WeightedSnapshot.WeightedSample sample = new WeightedSnapshot.WeightedSample(value, itemWeight);
final double priority = itemWeight / ThreadLocalRandom.current().nextDouble();
final long newCount = count.incrementAndGet();
if (newCount <= size) {
values.put(priority, sample);
} else {
Double first = values.firstKey();
if (first < priority && values.putIfAbsent(priority, sample) == null) {
// ensure we always remove an item
while (values.remove(first) == null) {
first = values.firstKey();
}
}
}
} finally {
unlockForRegularUsage();
}
}
代码示例来源:origin: neo4j/neo4j
private static void addAllocatedPointer( long pointer, long sizeInBytes )
{
if ( CHECK_NATIVE_ACCESS )
{
allocations.put( pointer, new Allocation( pointer, sizeInBytes, freeCounter.get() ) );
}
}
代码示例来源:origin: Alluxio/alluxio
/**
* Notifies the cache of a newly created empty directory.
*
* This way, we can have a cache hit on the first time the directory is listed.
*
* @param inodeId the inode id of the directory
*/
public void addEmptyDirectory(long inodeId) {
evictIfNecessary();
mMap.computeIfAbsent(inodeId, x -> {
mWeight.incrementAndGet();
ListingCacheEntry entry = new ListingCacheEntry();
entry.mChildren = new ConcurrentSkipListMap<>();
return entry;
});
}
代码示例来源:origin: apache/incubator-druid
@Override
public void stop()
{
synchronized (lock) {
if (stopped) {
return;
}
stopped = true;
for (SegmentHolder holder : segmentsToDrop.values()) {
holder.requestFailed("Stopping load queue peon.");
}
for (SegmentHolder holder : segmentsToLoad.values()) {
holder.requestFailed("Stopping load queue peon.");
}
segmentsToDrop.clear();
segmentsToLoad.clear();
queuedSize.set(0L);
failedAssignCount.set(0);
}
}
代码示例来源:origin: apache/incubator-druid
@Override
public void stop()
{
synchronized (lock) {
if (currentlyProcessing != null) {
executeCallbacks(currentlyProcessing.getCallbacks());
currentlyProcessing = null;
}
if (!segmentsToDrop.isEmpty()) {
for (SegmentHolder holder : segmentsToDrop.values()) {
executeCallbacks(holder.getCallbacks());
}
}
segmentsToDrop.clear();
if (!segmentsToLoad.isEmpty()) {
for (SegmentHolder holder : segmentsToLoad.values()) {
executeCallbacks(holder.getCallbacks());
}
}
segmentsToLoad.clear();
queuedSize.set(0L);
failedAssignCount.set(0);
stopped = true;
}
}
代码示例来源:origin: Alluxio/alluxio
private SortedMap<String, Long> loadChildren(Long inodeId, ListingCacheEntry entry) {
evictIfNecessary();
entry.mModified = false;
SortedMap<String, Long> listing = mEdgeCache.getChildIds(inodeId);
mMap.computeIfPresent(inodeId, (key, value) -> {
// Perform the update inside computeIfPresent to prevent concurrent modification to the
// cache entry.
if (!entry.mModified) {
entry.mChildren = new ConcurrentSkipListMap<>(listing);
mWeight.addAndGet(weight(entry));
return entry;
}
return null;
});
return listing;
}
代码示例来源:origin: lealone/Lealone
private void doWaitSpin() {
// pick a random sleep interval based on the number of threads spinning, so that
// we should always have a thread about to wake up, but most threads are sleeping
long sleep = 10000L * pool.spinningCount.get();
sleep = Math.min(1000000, sleep);
sleep *= Math.random();
sleep = Math.max(10000, sleep);
long start = System.nanoTime();
// place ourselves in the spinning collection; if we clash with another thread just exit
Long target = start + sleep;
if (pool.spinning.putIfAbsent(target, this) != null)
return;
LockSupport.parkNanos(sleep);
// remove ourselves (if haven't been already) - we should be at or near the front, so should be cheap-ish
pool.spinning.remove(target, this);
// finish timing and grab spinningTime (before we finish timing so it is under rather than overestimated)
long end = System.nanoTime();
long spin = end - start;
long stopCheck = pool.stopCheck.addAndGet(spin);
maybeStop(stopCheck, end);
if (prevStopCheck + spin == stopCheck)
soleSpinnerSpinTime += spin;
else
soleSpinnerSpinTime = 0;
prevStopCheck = stopCheck;
}
代码示例来源:origin: apache/incubator-druid
@Override
public void loadSegment(final DataSegment segment, final LoadPeonCallback callback)
{
synchronized (lock) {
if ((currentlyProcessing != null) &&
currentlyProcessing.getSegmentId().equals(segment.getId())) {
if (callback != null) {
currentlyProcessing.addCallback(callback);
}
return;
}
}
synchronized (lock) {
final SegmentHolder existingHolder = segmentsToLoad.get(segment);
if (existingHolder != null) {
if ((callback != null)) {
existingHolder.addCallback(callback);
}
return;
}
}
log.debug("Asking server peon[%s] to load segment[%s]", basePath, segment.getId());
queuedSize.addAndGet(segment.getSize());
segmentsToLoad.put(segment, new SegmentHolder(segment, LOAD, Collections.singletonList(callback)));
}
代码示例来源:origin: apache/incubator-druid
private void actionCompleted()
{
if (currentlyProcessing != null) {
switch (currentlyProcessing.getType()) {
case LOAD:
segmentsToLoad.remove(currentlyProcessing.getSegment());
queuedSize.addAndGet(-currentlyProcessing.getSegmentSize());
break;
case DROP:
segmentsToDrop.remove(currentlyProcessing.getSegment());
break;
default:
throw new UnsupportedOperationException();
}
final List<LoadPeonCallback> callbacks = currentlyProcessing.getCallbacks();
currentlyProcessing = null;
callBackExecutor.execute(
() -> executeCallbacks(callbacks)
);
}
}
代码示例来源:origin: google/guava
@Override
protected SortedMap<String, String> create(Entry<String, String>[] entries) {
return populate(new ConcurrentSkipListMap<String, String>(), entries);
}
})
代码示例来源:origin: Alluxio/alluxio
public void removeChild(String name) {
if (mChildren != null && mChildren.remove(name) != null) {
mWeight.decrementAndGet();
}
}
}
代码示例来源:origin: apache/hbase
@Before
public void setUp() {
m = new CopyOnWriteArrayMap<>();
csm = new ConcurrentSkipListMap<>();
for ( long i = 0 ; i < 10000; i++ ) {
long o = ThreadLocalRandom.current().nextLong(MAX_RAND);
m.put(i, o);
csm.put(i,o);
}
long o = ThreadLocalRandom.current().nextLong(MAX_RAND);
m.put(0L, o);
csm.put(0L,o);
}
代码示例来源:origin: apache/hbase
for (Entry<byte[], RegionMetrics> entry : hsl.getRegionMetrics().entrySet()) {
byte[] encodedRegionName = Bytes.toBytes(RegionInfo.encodeRegionName(entry.getKey()));
Long existingValue = flushedSequenceIdByRegion.get(encodedRegionName);
long l = entry.getValue().getCompletedSequenceId();
flushedSequenceIdByRegion.put(encodedRegionName, l);
} else if (l != HConstants.NO_SEQNUM && l < existingValue) {
LOG.warn("RegionServer " + sn + " indicates a last flushed sequence id ("
() -> new ConcurrentSkipListMap<>(Bytes.BYTES_COMPARATOR));
for (Entry<byte[], Long> storeSeqId : entry.getValue().getStoreSequenceId().entrySet()) {
byte[] family = storeSeqId.getKey();
existingValue = storeFlushedSequenceId.get(family);
l = storeSeqId.getValue();
if (LOG.isTraceEnabled()) {
代码示例来源:origin: apache/hbase
.getRegionEncodedName().toByteArray();
flushedSequenceIdByRegion
.putIfAbsent(encodedRegionName, flushedRegionSequenceId.getSeqId());
if (flushedRegionSequenceId.getStoresList() != null
&& flushedRegionSequenceId.getStoresList().size() != 0) {
ConcurrentNavigableMap<byte[], Long> storeFlushedSequenceId =
computeIfAbsent(storeFlushedSequenceIdsByRegion, encodedRegionName,
() -> new ConcurrentSkipListMap<>(Bytes.BYTES_COMPARATOR));
for (FlushedStoreSequenceId flushedStoreSequenceId : flushedRegionSequenceId
.getStoresList()) {
storeFlushedSequenceId
.put(flushedStoreSequenceId.getFamily().toByteArray(),
flushedStoreSequenceId.getSeqId());
内容来源于网络,如有侵权,请联系作者删除!