Refine search
private static <K, V> boolean compareAndSet(ConcurrentMap<K, V> map, K key, V oldValue, V newValue) { if (oldValue == null) { return map.putIfAbsent(key, newValue) == null; } return map.replace(key, oldValue, newValue); }
public void fireConnect(InetSocketAddress addr) { if (maps.get(addr) == Status.CONNECTED) { return; } if (maps.putIfAbsent(addr, Status.CONNECTED) == null || maps.replace(addr, Status.DISCONNECTED, Status.CONNECTED)) { for (ConnectionListener listener : listenersMap.values()) { listener.onConnect(addr); } } }
public void fireConnect(InetSocketAddress addr) { if (maps.get(addr) == Status.CONNECTED) { return; } if (maps.putIfAbsent(addr, Status.CONNECTED) == null || maps.replace(addr, Status.DISCONNECTED, Status.CONNECTED)) { for (ConnectionListener listener : listenersMap.values()) { listener.onConnect(addr); } } }
private <K, V> boolean updateCollection(ConcurrentMap<K, V> collection, K key, @Nullable V oldValue, V newValue) { if (oldValue == null) { if (collection.putIfAbsent(key, newValue) == null) { return true; } } else { if (collection.replace(key, oldValue, newValue)) { return true; } } return false; }
public boolean addIfAbsentOrExpired(K key) { Long val=map.get(key); if(val == null) return map.putIfAbsent(key, System.nanoTime()) == null; long current_time=System.nanoTime(); return hasExpired(val, current_time) && map.replace(key, val, current_time); }
public void removeBucketServerLocation(ServerLocation serverLocation) { Iterator<Map.Entry<Integer, List<BucketServerLocation66>>> iter = this.bucketServerLocationsMap.entrySet().iterator(); while (iter.hasNext()) { Map.Entry<Integer, List<BucketServerLocation66>> entry = iter.next(); Integer key = entry.getKey(); List<BucketServerLocation66> oldLocations = entry.getValue(); List<BucketServerLocation66> newLocations = new ArrayList<BucketServerLocation66>(oldLocations); // if this serverLocation contains in the list the remove the // serverLocation and update the map with new List while (newLocations.remove(serverLocation) && !this.bucketServerLocationsMap.replace(key, oldLocations, newLocations)) { oldLocations = this.bucketServerLocationsMap.get(key); newLocations = new ArrayList<BucketServerLocation66>(oldLocations); } } }
/** * @param t Log throttle entry. * @param oldStamp Old timestamp, possibly {@code null}. * @param newStamp New timestamp. * @return {@code True} if throttle value was replaced. */ private static boolean replace(IgniteBiTuple<Class<? extends Throwable>, String> t, @Nullable Long oldStamp, Long newStamp) { assert newStamp != null; if (oldStamp == null) { Long old = errors.putIfAbsent(t, newStamp); return old == null; } return errors.replace(t, oldStamp, newStamp); }
static Semaphore getLock(ConcurrentMap<String, Semaphore> locks2, String key) { Semaphore lock = locks2.get(key); if (lock == null) { Semaphore newLock = new Semaphore(1, true); locks2.get(null); locks2.put(null, null); locks2.remove(null); locks2.containsKey(null); locks2.containsValue(null); locks2.putIfAbsent(null, null); locks2.remove(null, null); locks2.replace(null, null); locks2.replace(null, null, null); lock = locks2.putIfAbsent(key, lock); // value, being null, will *always* throw NullPointerException if (lock == null) lock = newLock; } return lock; } // static Semaphore getLock(ConcurrentMap<String, Semaphore> locks2,
/** * Returns a list of any reference count tracking information for the given Chunk address. */ public List<RefCountChangeInfo> getRefCountInfo(long address) { if (!trackReferenceCounts()) return null; List<RefCountChangeInfo> result = stacktraces.get(address); getReferenceCountInfoTestHook(stacktraces, address); while (result != null && !stacktraces.replace(address, result, LOCKED)) { result = stacktraces.get(address); } return result; }
return 0; } else { existingCounter = countMap.putIfAbsent(element, new AtomicInteger(count)); if (existingCounter == null) { return 0; } else { AtomicInteger newCounter = new AtomicInteger(count); if ((countMap.putIfAbsent(element, newCounter) == null) || countMap.replace(element, existingCounter, newCounter)) { return 0;
/** * Concurrently increments numeric cache value. * * @param key Key for the value to be incremented. */ private <T> void concurrentIncrement(T key) { ConcurrentMap<T, Integer> nodeLoc = ignite.cluster().nodeLocalMap(); Integer cntr = nodeLoc.get(key); if (cntr == null) cntr = nodeLoc.putIfAbsent(key, 1); if (cntr != null) { while (!nodeLoc.replace(key, cntr, cntr + 1)) { cntr = nodeLoc.get(key); assert cntr != null; } } } }
} else { return countMap.putIfAbsent(element, new AtomicInteger(newCount)) == null; } else { AtomicInteger newCounter = new AtomicInteger(newCount); return (countMap.putIfAbsent(element, newCounter) == null) || countMap.replace(element, existingCounter, newCounter);
SaveableReference ref = referTo(obj); while (true) { VersionRange vr = odm.data.get(ref); if (vr != null && odm.data.replace(ref, vr, new VersionRange(vr, null, buf.toString()))) { break; } else if (odm.data.putIfAbsent(ref, new VersionRange(null, null, buf.toString())) == null) { break;
AtomicInteger existingCounter = Maps.safeGet(countMap, element); if (existingCounter == null) { existingCounter = countMap.putIfAbsent(element, new AtomicInteger(occurrences)); if (existingCounter == null) { return 0; if ((countMap.putIfAbsent(element, newCounter) == null) || countMap.replace(element, existingCounter, newCounter)) { return 0;
@Override public CompletableFuture<Boolean> setOption(Set<Context> contexts, String key, @Nullable String value) { Map<String, String> origMap = this.options.get(contexts); Map<String, String> newMap; if (origMap == null) { if (value == null) { return CompletableFuture.completedFuture(false); } if ((origMap = this.options.putIfAbsent(ImmutableSet.copyOf(contexts), ImmutableMap.of(key.toLowerCase(), value))) == null) { return CompletableFuture.completedFuture(true); } } do { if (value == null) { if (!origMap.containsKey(key)) { return CompletableFuture.completedFuture(false); } newMap = new HashMap<>(); newMap.putAll(origMap); newMap.remove(key); } else { newMap = new HashMap<>(); newMap.putAll(origMap); newMap.put(key, value); } newMap = Collections.unmodifiableMap(newMap); } while (!this.options.replace(contexts, origMap, newMap)); return CompletableFuture.completedFuture(true); }
@Override public ReplaceStatus replace(String key, String oldValue, String newValue) throws StoreAccessException { String currentValue = map.get(key); if(currentValue == null) { return ReplaceStatus.MISS_NOT_PRESENT; } if(currentValue.equals(oldValue)) { map.replace(key, newValue); return ReplaceStatus.HIT; } return ReplaceStatus.MISS_PRESENT; } }