public V putIfAbsent(Long key, V val) { if (val == null) return null; CacheEntry<Long, V> e = new CacheEntry<Long, V>(key, val, stats.accessCounter.incrementAndGet()); CacheEntry<Long, V> oldCacheEntry = map.putIfAbsent(key, e); if (oldCacheEntry == null) // only do maintenance if we have put a new item to the map doCacheMaintenanceOnPut(oldCacheEntry); return oldCacheEntry == null ? null : oldCacheEntry.value; }
public V putIfAbsent(Long key, V val) { if (val == null) return null; final CacheEntry<Long, V> e = new CacheEntry<>(key, val, stats.accessCounter.incrementAndGet()); final CacheEntry<Long, V> oldCacheEntry = map.putIfAbsent(key, e); if (oldCacheEntry == null) // only do maintenance if we have put a new item to the map doCacheMaintenanceOnPut(oldCacheEntry); return oldCacheEntry == null ? null : oldCacheEntry.value; }
private VertexState<M> get(long vertexId, boolean create) { assert vertexId==getCanonicalId(vertexId); VertexState<M> state = vertexStates.get(vertexId); if (state==null) { if (!create) return VertexState.EMPTY_STATE; vertexStates.putIfAbsent(vertexId,new VertexState<>(elementKeyMap)); state = vertexStates.get(vertexId); } return state; }
private VertexState<M> get(long vertexId, boolean create) { assert vertexId==getCanonicalId(vertexId); VertexState<M> state = vertexStates.get(vertexId); if (state==null) { if (!create) return VertexState.EMPTY_STATE; vertexStates.putIfAbsent(vertexId,new VertexState<>(elementKeyMap)); state = vertexStates.get(vertexId); } return state; }
private PartitionVertexAggregate<M> getPartitioned(long vertexId) { assert idManager.isPartitionedVertex(vertexId); vertexId=getCanonicalId(vertexId); PartitionVertexAggregate<M> state = partitionVertices.get(vertexId); if (state==null) { partitionVertices.putIfAbsent(vertexId,new PartitionVertexAggregate<>(previousScopes)); state = partitionVertices.get(vertexId); } return state; }
public LRUVertexCache(int capacity) { volatileVertices = new NonBlockingHashMapLong<>(); cache = new ConcurrentLRUCache<>(capacity * 2, // upper is double capacity capacity + capacity / 3, // lower is capacity + 1/3 capacity, // acceptable watermark is capacity 100, true, false, // 100 items initial size + use only one thread for items cleanup (vertexId, vertex) -> { if (vertexId == null || vertex == null) { return; } if (vertex.isModified()) { volatileVertices.putIfAbsent(vertexId, vertex); } }); cache.setAlive(true); //need counters to its actually LRU }
private PartitionVertexAggregate<M> getPartitioned(long vertexId) { assert idManager.isPartitionedVertex(vertexId); vertexId=getCanonicalId(vertexId); PartitionVertexAggregate<M> state = partitionVertices.get(vertexId); if (state==null) { partitionVertices.putIfAbsent(vertexId,new PartitionVertexAggregate<>(previousScopes)); state = partitionVertices.get(vertexId); } return state; }
/** Add {@code o} to the set. * @return <tt>true</tt> if {@code o} was added to the set, <tt>false</tt> * if {@code o} was already in the set. */ public boolean add(final long o) { return _map.putIfAbsent(o,V) != V; }
/** * To support AbstractCollection.addAll */ @Override public boolean add(final Long o) { return _map.putIfAbsent(o.longValue(),V) != V; }
/** Auto-boxing version of {@link #putIfAbsent}. */ public TypeV putIfAbsent( Long key, TypeV val ) { return putIfAbsent( ((Long)key).longValue(), val ); } /** Auto-boxing version of {@link #replace}. */
/** Auto-boxing version of {@link #putIfAbsent}. */ public TypeV putIfAbsent( Long key, TypeV val ) { return putIfAbsent( ((Long)key).longValue(), val ); } /** Auto-boxing version of {@link #replace}. */
/** Auto-boxing version of {@link #putIfAbsent}. */ public TypeV putIfAbsent( Long key, TypeV val ) { return putIfAbsent( ((Long)key).longValue(), val ); } /** Auto-boxing version of {@link #replace}. */
public V putIfAbsent(Long key, V val) { if (val == null) return null; CacheEntry<Long, V> e = new CacheEntry<Long, V>(key, val, stats.accessCounter.incrementAndGet()); CacheEntry<Long, V> oldCacheEntry = map.putIfAbsent(key, e); if (oldCacheEntry == null) // only do maintenance if we have put a new item to the map doCacheMaintenanceOnPut(oldCacheEntry); return oldCacheEntry == null ? null : oldCacheEntry.value; }
public V putIfAbsent(Long key, V val) { if (val == null) return null; CacheEntry<Long, V> e = new CacheEntry<Long, V>(key, val, stats.accessCounter.incrementAndGet()); CacheEntry<Long, V> oldCacheEntry = map.putIfAbsent(key, e); if (oldCacheEntry == null) // only do maintenance if we have put a new item to the map doCacheMaintenanceOnPut(oldCacheEntry); return oldCacheEntry == null ? null : oldCacheEntry.value; }
private OwnerClock getOwnerClock(short owner) { OwnerClock oc = ownerClocks.get(owner); if (oc == null) { oc = new OwnerClock(); final OwnerClock tmp = ownerClocks.putIfAbsent(owner, oc); if (tmp != null) oc = tmp; } return oc; }
private CacheLine putLine(long id, Cache.CacheLine line, int oldSize, int newSize) { final CacheLine old; if (line.getState().isLessThan(State.O)) { old = shared.put(id, line); // to make sure eviction data is updated we must put rather than putIfAbsent if (old != null && old != line) evictLine(old, false); return line; } else { old = owned.putIfAbsent(id, (CacheLine) line); if (old != null && old != line) { evictLine(line, false); return old; } else return line; } }
private VertexState<M> get(long vertexId, boolean create) { assert vertexId==getCanonicalId(vertexId); VertexState<M> state = vertexStates.get(vertexId); if (state==null) { if (!create) return VertexState.EMPTY_STATE; vertexStates.putIfAbsent(vertexId,new VertexState<>(elementKeyMap)); state = vertexStates.get(vertexId); } return state; }
private PartitionVertexAggregate<M> getPartitioned(long vertexId) { assert idManager.isPartitionedVertex(vertexId); vertexId=getCanonicalId(vertexId); PartitionVertexAggregate<M> state = partitionVertices.get(vertexId); if (state==null) { partitionVertices.putIfAbsent(vertexId,new PartitionVertexAggregate<>(previousScopes)); state = partitionVertices.get(vertexId); } return state; }