@SuppressWarnings("deprecation")
public static <K,V> ConcurrentMap<K,V> makeSoftValueComputingMapWithRemoveListenr(MapMaker maker,Function<? super K,? extends V> computingFunction,final otterRemovalListener listener) {
return maker.softValues().removalListener(new RemovalListener<K,V>() {
@Override
public void onRemoval(RemovalNotification<K,V> notification) {
if (notification == null) {
return;
}
listener.onRemoval(notification.getKey(),notification.getValue());
}
}).makeComputingMap(computingFunction);
}
项目:bts
文件:MapMakerInternalMap.java
/**
* Notifies listeners that an entry has been automatically removed due to expiration,eviction,* or eligibility for garbage collection. This should be called every time expireEntries or
* evictEntry is called (once the lock is released).
*/
void processpendingNotifications() {
RemovalNotification<K,V> notification;
while ((notification = removalNotificationQueue.poll()) != null) {
try {
removalListener.onRemoval(notification);
} catch (Exception e) {
logger.log(Level.WARNING,"Exception thrown by removal listener",e);
}
}
}
项目:j2objc
文件:MapMakerInternalMap.java
/**
* Notifies listeners that an entry has been automatically removed due to expiration,e);
}
}
}
项目:guava-libraries
文件:MapMakerInternalMap.java
/**
* Notifies listeners that an entry has been automatically removed due to expiration,e);
}
}
}
项目:guava-libraries
文件:MapMakerInternalMapTest.java
public void testSetRemovalListener() {
RemovalListener<Object,Object> testListener = new RemovalListener<Object,Object>() {
@Override
public void onRemoval(RemovalNotification<Object,Object> notification) {}
};
MapMakerInternalMap<Object,Object> map =
makeMap(createMapMaker().removalListener(testListener));
assertSame(testListener,map.removalListener);
}
项目:guava-libraries
文件:MapMakerInternalMapTest.java
项目:VectorAttackScanner
文件:MapMakerInternalMap.java
/**
* Notifies listeners that an entry has been automatically removed due to expiration,e);
}
}
}
项目:My-Wallet-Android
文件:MapMakerInternalMap.java
/**
* Notifies listeners that an entry has been automatically removed due to expiration,e);
}
}
}
项目:cnGuava
文件:MapMakerInternalMap.java
/**
* Notifies listeners that an entry has been automatically removed due to expiration,e);
}
}
}
@SuppressWarnings("deprecation")
public static <K,V> makeSoftValueComputingMapWithRemoveListenr(Function<? super K,final otterRemovalListener<K,V> listener) {
return new MapMaker().softValues().removalListener(new RemovalListener<K,notification.getValue());
}
}).makeComputingMap(computingFunction);
}
项目:org.openntf.domino
文件:MapMakerInternalMap.java
/**
* Notifies listeners that an entry has been automatically removed due to expiration,e);
}
}
}
项目:bts
文件:GenericMapMaker.java
项目:bts
文件:MapMakerInternalMap.java
/**
* Creates a new,empty map with the specified strategy,initial capacity and concurrency level.
*/
MapMakerInternalMap(MapMaker builder) {
concurrencyLevel = Math.min(builder.getConcurrencyLevel(),MAX_SEGMENTS);
keyStrength = builder.getKeyStrength();
valueStrength = builder.getValueStrength();
keyEquivalence = builder.getKeyEquivalence();
valueEquivalence = valueStrength.defaultEquivalence();
maximumSize = builder.maximumSize;
expireAfteraccessNanos = builder.getExpireAfteraccessNanos();
expireAfterWriteNanos = builder.getExpireAfterWriteNanos();
entryFactory = EntryFactory.getFactory(keyStrength,expires(),evictsBySize());
ticker = builder.getTicker();
removalListener = builder.getRemovalListener();
removalNotificationQueue = (removalListener == NullListener.INSTANCE)
? MapMakerInternalMap.<RemovalNotification<K,V>>discardingQueue()
: new ConcurrentLinkedQueue<RemovalNotification<K,V>>();
int initialCapacity = Math.min(builder.getinitialCapacity(),MAXIMUM_CAPACITY);
if (evictsBySize()) {
initialCapacity = Math.min(initialCapacity,maximumSize);
}
// Find power-of-two sizes best matching arguments. Constraints:
// (segmentCount <= maximumSize)
// && (concurrencyLevel > maximumSize || segmentCount > concurrencyLevel)
int segmentShift = 0;
int segmentCount = 1;
while (segmentCount < concurrencyLevel
&& (!evictsBySize() || segmentCount * 2 <= maximumSize)) {
++segmentShift;
segmentCount <<= 1;
}
this.segmentShift = 32 - segmentShift;
segmentMask = segmentCount - 1;
this.segments = newSegmentArray(segmentCount);
int segmentCapacity = initialCapacity / segmentCount;
if (segmentCapacity * segmentCount < initialCapacity) {
++segmentCapacity;
}
int segmentSize = 1;
while (segmentSize < segmentCapacity) {
segmentSize <<= 1;
}
if (evictsBySize()) {
// Ensure sum of segment max sizes = overall max size
int maximumSegmentSize = maximumSize / segmentCount + 1;
int remainder = maximumSize % segmentCount;
for (int i = 0; i < this.segments.length; ++i) {
if (i == remainder) {
maximumSegmentSize--;
}
this.segments[i] =
createSegment(segmentSize,maximumSegmentSize);
}
} else {
for (int i = 0; i < this.segments.length; ++i) {
this.segments[i] =
createSegment(segmentSize,MapMaker.UNSET_INT);
}
}
}
项目:bts
文件:MapMakerInternalMap.java
项目:j2objc
文件:GenericMapMaker.java
项目:j2objc
文件:MapMakerInternalMap.java
/**
* Creates a new,MapMaker.UNSET_INT);
}
}
}
项目:j2objc
文件:MapMakerInternalMap.java
void enqueueNotification(@Nullable K key,cause);
map.removalNotificationQueue.offer(notification);
}
}
项目:guava-libraries
文件:GenericMapMaker.java
项目:guava-libraries
文件:MapMakerInternalMap.java
/**
* Creates a new,MapMaker.UNSET_INT);
}
}
}
项目:guava-libraries
文件:MapMakerInternalMap.java
void enqueueNotification(@Nullable K key,cause);
map.removalNotificationQueue.offer(notification);
}
}
项目:guava-libraries
文件:MapMakerTest.java
@GwtIncompatible("threads")
public void testRemovalNotification_clear() throws InterruptedException {
// If a clear() happens while a computation is pending,we should not get a removal
// notification.
final CountDownLatch computingLatch = new CountDownLatch(1);
Function<String,String> computingFunction = new DelayingIdentityLoader<String>(computingLatch);
QueuingRemovalListener<String,String> listener = new QueuingRemovalListener<String,String>();
@SuppressWarnings("deprecation") // test of deprecated code
final ConcurrentMap<String,String> map = new MapMaker()
.concurrencyLevel(1)
.removalListener(listener)
.makeComputingMap(computingFunction);
// seed the map,so its segment's count > 0
map.put("a","a");
final CountDownLatch computationStarted = new CountDownLatch(1);
final CountDownLatch computationComplete = new CountDownLatch(1);
new Thread(new Runnable() {
@Override public void run() {
computationStarted.countDown();
map.get("b");
computationComplete.countDown();
}
}).start();
// wait for the computingEntry to be created
computationStarted.await();
map.clear();
// let the computation proceed
computingLatch.countDown();
// don't check map.size() until we kNow the get("b") call is complete
computationComplete.await();
// At this point,the listener should be holding the seed value (a -> a),and the map should
// contain the computed value (b -> b),since the clear() happened before the computation
// completed.
assertEquals(1,listener.size());
RemovalNotification<String,String> notification = listener.remove();
assertEquals("a",notification.getKey());
assertEquals("a",notification.getValue());
assertEquals(1,map.size());
assertEquals("b",map.get("b"));
}
项目:guava-libraries
文件:MapMakerInternalMapTest.java
项目:guava-libraries
文件:MapMakerInternalMapTest.java
项目:guava-libraries
文件:MapMakerInternalMapTest.java
项目:VectorAttackScanner
文件:GenericMapMaker.java
项目:VectorAttackScanner
文件:MapMakerInternalMap.java
/**
* Creates a new,MapMaker.UNSET_INT);
}
}
}
项目:VectorAttackScanner
文件:MapMakerInternalMap.java
void enqueueNotification(@Nullable K key,cause);
map.removalNotificationQueue.offer(notification);
}
}
项目:My-Wallet-Android
文件:GenericMapMaker.java
项目:My-Wallet-Android
文件:MapMakerInternalMap.java
/**
* Creates a new,MapMaker.UNSET_INT);
}
}
}
项目:My-Wallet-Android
文件:MapMakerInternalMap.java
void enqueueNotification(@Nullable K key,cause);
map.removalNotificationQueue.offer(notification);
}
}
项目:cnGuava
文件:GenericMapMaker.java
项目:cnGuava
文件:MapMakerInternalMap.java
/**
* Creates a new,MapMaker.UNSET_INT);
}
}
}
项目:cnGuava
文件:MapMakerInternalMap.java
void enqueueNotification(@Nullable K key,cause);
map.removalNotificationQueue.offer(notification);
}
}
项目:org.openntf.domino
文件:GenericMapMaker.java
项目:org.openntf.domino
文件:MapMakerInternalMap.java
/**
* Creates a new,MapMaker.UNSET_INT);
}
}
}
项目:org.openntf.domino
文件:MapMakerInternalMap.java
void enqueueNotification(@Nullable K key,cause);
map.removalNotificationQueue.offer(notification);
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。