/** * Decrements the ref count of k, and removes from map if ref count == 0. * @param k the key to remove * @return the value associated with the specified key or null if key is removed from map. */ V remove(K k) { Payload<V> p = map.computeIfPresent(k, (k1, v) -> --v.refCount <= 0 ? null : v); return p == null ? null : p.v; }
private void decrementUgiReference(UserGroupInformation ugi) { ugiReferenceCounter.computeIfPresent(ugi, new BiFunction<UserGroupInformation, Integer, Integer>() { @Override public Integer apply(UserGroupInformation key, Integer value) { return value > 1 ? --value : null; } }); }
public V computeIfPresent(final K key, final BiFunction<? super K, ? super V, ? extends V> remappingFunction) { return backingMap.computeIfPresent(key, remappingFunction); }
/** * @param c Cache context closure. */ void forAllCaches(final IgniteInClosure<GridCacheContext> c) { for (Integer cacheId : ctxMap.keySet()) { ctxMap.computeIfPresent(cacheId, (cacheId1, ctx) -> { c.apply(ctx); return ctx; } ); } }
@Override public boolean replace(K key, V oldValue, V newValue) { requireNonNull(oldValue); requireNonNull(newValue); @SuppressWarnings({"unchecked", "rawtypes"}) V[] prev = (V[]) new Object[1]; data.computeIfPresent(key, (k, v) -> { if (v.equals(oldValue)) { if (newValue != v) { writer.write(key, newValue); } prev[0] = v; return newValue; } return v; }); boolean replaced = (prev[0] != null); if (hasRemovalListener() && replaced && (prev[0] != newValue)) { notifyRemoval(key, prev[0], RemovalCause.REPLACED); } return replaced; }
@Override public boolean remove(Object key, Object value) { if (value == null) { requireNonNull(key); return false; } @SuppressWarnings("unchecked") K castKey = (K) key; @SuppressWarnings({"unchecked", "rawtypes"}) V[] oldValue = (V[]) new Object[1]; data.computeIfPresent(castKey, (k, v) -> { if (v.equals(value)) { writer.delete(castKey, v, RemovalCause.EXPLICIT); oldValue[0] = v; return null; } return v; }); boolean removed = (oldValue[0] != null); if (hasRemovalListener() && removed) { notifyRemoval(castKey, oldValue[0], RemovalCause.EXPLICIT); } return removed; }
@Override public @Nullable V computeIfPresent(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) { requireNonNull(remappingFunction); // optimistic fast path due to computeIfAbsent always locking if (!data.containsKey(key)) { return null; } // ensures that the removal notification is processed after the removal has completed @SuppressWarnings({"unchecked", "rawtypes"}) V[] oldValue = (V[]) new Object[1]; RemovalCause[] cause = new RemovalCause[1]; V nv = data.computeIfPresent(key, (K k, V value) -> { BiFunction<? super K, ? super V, ? extends V> function = statsAware(remappingFunction, /* recordMiss */ false, /* recordLoad */ true); V newValue = function.apply(k, value); cause[0] = (newValue == null) ? RemovalCause.EXPLICIT : RemovalCause.REPLACED; if (hasRemovalListener() && (newValue != value)) { oldValue[0] = value; } return newValue; }); if (oldValue[0] != null) { notifyRemoval(key, oldValue[0], cause[0]); } return nv; }
@Override public @Nullable V replace(K key, V value) { requireNonNull(value); @SuppressWarnings({"unchecked", "rawtypes"}) V[] oldValue = (V[]) new Object[1]; data.computeIfPresent(key, (k, v) -> { if (value != v) { writer.write(key, value); } oldValue[0] = v; return value; }); if (hasRemovalListener() && (oldValue[0] != null) && (oldValue[0] != value)) { notifyRemoval(key, value, RemovalCause.REPLACED); } return oldValue[0]; }
@Override public @Nullable V remove(Object key) { @SuppressWarnings("unchecked") K castKey = (K) key; @SuppressWarnings({"unchecked", "rawtypes"}) V[] oldValue = (V[]) new Object[1]; if (writer == CacheWriter.disabledWriter()) { oldValue[0] = data.remove(key); } else { data.computeIfPresent(castKey, (k, v) -> { writer.delete(castKey, v, RemovalCause.EXPLICIT); oldValue[0] = v; return null; }); } if (hasRemovalListener() && (oldValue[0] != null)) { notifyRemoval(castKey, oldValue[0], RemovalCause.EXPLICIT); } return oldValue[0]; }
@Override public boolean removeSegment(String dataSourceName, final String segmentId) { try { final boolean removed = removeSegmentFromTable(segmentId); // Call iteratePossibleParsingsWithDataSource() outside of dataSources.computeIfPresent() because the former is a // potentially expensive operation, while lambda to be passed into computeIfPresent() should preferably run fast. List<SegmentId> possibleSegmentIds = SegmentId.iteratePossibleParsingsWithDataSource(dataSourceName, segmentId); dataSources.computeIfPresent( dataSourceName, (dsName, dataSource) -> { for (SegmentId possibleSegmentId : possibleSegmentIds) { if (dataSource.removeSegment(possibleSegmentId) != null) { break; } } // Returning null from the lambda here makes the ConcurrentHashMap to remove the current entry. //noinspection ReturnOfNull return dataSource.isEmpty() ? null : dataSource; } ); return removed; } catch (Exception e) { log.error(e, e.toString()); return false; } }
@Override public boolean removeSegment(SegmentId segmentId) { try { final boolean removed = removeSegmentFromTable(segmentId.toString()); dataSources.computeIfPresent( segmentId.getDataSource(), (dsName, dataSource) -> { dataSource.removeSegment(segmentId); // Returning null from the lambda here makes the ConcurrentHashMap to remove the current entry. //noinspection ReturnOfNull return dataSource.isEmpty() ? null : dataSource; } ); return removed; } catch (Exception e) { log.error(e, e.toString()); return false; } }
RemovalCause[] cause = new RemovalCause[1]; data.computeIfPresent(nodeFactory.newLookupKey(key), (kR, node) -> { synchronized (node) { oldKey[0] = node.getKey();
int[] oldWeight = new int[1]; long[] now = new long[1]; Node<K, V> node = data.computeIfPresent(nodeFactory.newLookupKey(key), (k, n) -> { synchronized (n) { nodeKey[0] = n.getKey();
RemovalCause[] cause = new RemovalCause[1]; data.computeIfPresent(nodeFactory.newLookupKey(key), (k, n) -> { synchronized (n) { oldValue[0] = n.getValue();
long[] now = new long[1]; int weight = weigher.weigh(key, value); Node<K, V> node = data.computeIfPresent(nodeFactory.newLookupKey(key), (k, n) -> { synchronized (n) { nodeKey[0] = n.getKey();
RemovalCause[] cause = new RemovalCause[1]; data.computeIfPresent(node.getKeyReference(), (k, n) -> { if (n != node) { return n;
@Override public @Nullable V replace(K key, V value) { requireNonNull(value); @SuppressWarnings({"unchecked", "rawtypes"}) V[] oldValue = (V[]) new Object[1]; data.computeIfPresent(key, (k, v) -> { if (value != v) { writer.write(key, value); } oldValue[0] = v; return value; }); if (hasRemovalListener() && (oldValue[0] != null) && (oldValue[0] != value)) { notifyRemoval(key, value, RemovalCause.REPLACED); } return oldValue[0]; }
@Override public boolean replace(K key, V oldValue, V newValue) { requireNonNull(oldValue); requireNonNull(newValue); @SuppressWarnings({"unchecked", "rawtypes"}) V[] prev = (V[]) new Object[1]; data.computeIfPresent(key, (k, v) -> { if (v.equals(oldValue)) { if (newValue != v) { writer.write(key, newValue); } prev[0] = v; return newValue; } return v; }); boolean replaced = (prev[0] != null); if (hasRemovalListener() && replaced && (prev[0] != newValue)) { notifyRemoval(key, prev[0], RemovalCause.REPLACED); } return replaced; }
@Override public @Nullable V remove(Object key) { @SuppressWarnings("unchecked") K castKey = (K) key; @SuppressWarnings({"unchecked", "rawtypes"}) V[] oldValue = (V[]) new Object[1]; if (writer == CacheWriter.disabledWriter()) { oldValue[0] = data.remove(key); } else { data.computeIfPresent(castKey, (k, v) -> { writer.delete(castKey, v, RemovalCause.EXPLICIT); oldValue[0] = v; return null; }); } if (hasRemovalListener() && (oldValue[0] != null)) { notifyRemoval(castKey, oldValue[0], RemovalCause.EXPLICIT); } return oldValue[0]; }
RemovalCause[] actualCause = new RemovalCause[1]; data.computeIfPresent(node.getKeyReference(), (k, n) -> { if (n != node) { return n;