• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java RemovalNotification类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.google.common.collect.MapMaker.RemovalNotification的典型用法代码示例。如果您正苦于以下问题:Java RemovalNotification类的具体用法?Java RemovalNotification怎么用?Java RemovalNotification使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



RemovalNotification类属于com.google.common.collect.MapMaker包,在下文中一共展示了RemovalNotification类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: makeSoftValueComputingMapWithRemoveListenr

import com.google.common.collect.MapMaker.RemovalNotification; //导入依赖的package包/类
@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);
}
 
开发者ID:alibaba,项目名称:otter,代码行数:17,代码来源:OtterMigrateMap.java


示例2: processPendingNotifications

import com.google.common.collect.MapMaker.RemovalNotification; //导入依赖的package包/类
/**
 * 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);
    }
  }
}
 
开发者ID:cplutte,项目名称:bts,代码行数:16,代码来源:MapMakerInternalMap.java


示例3: testSetRemovalListener

import com.google.common.collect.MapMaker.RemovalNotification; //导入依赖的package包/类
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);
}
 
开发者ID:sander120786,项目名称:guava-libraries,代码行数:10,代码来源:MapMakerInternalMapTest.java


示例4: assertNotified

import com.google.common.collect.MapMaker.RemovalNotification; //导入依赖的package包/类
static <K, V> void assertNotified(
    QueuingRemovalListener<K, V> listener, K key, V value, RemovalCause cause) {
  RemovalNotification<K, V> notification = listener.remove();
  assertSame(key, notification.getKey());
  assertSame(value, notification.getValue());
  assertSame(cause, notification.getCause());
}
 
开发者ID:sander120786,项目名称:guava-libraries,代码行数:8,代码来源:MapMakerInternalMapTest.java


示例5: onRemoval

import com.google.common.collect.MapMaker.RemovalNotification; //导入依赖的package包/类
@Override
public void onRemoval(RemovalNotification<Object, Object> notification) {}
 
开发者ID:cplutte,项目名称:bts,代码行数:3,代码来源:GenericMapMaker.java


示例6: MapMakerInternalMap

import com.google.common.collect.MapMaker.RemovalNotification; //导入依赖的package包/类
/**
 * 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);
    }
  }
}
 
开发者ID:cplutte,项目名称:bts,代码行数:73,代码来源:MapMakerInternalMap.java


示例7: enqueueNotification

import com.google.common.collect.MapMaker.RemovalNotification; //导入依赖的package包/类
void enqueueNotification(@Nullable K key, int hash, @Nullable V value, RemovalCause cause) {
  if (map.removalNotificationQueue != DISCARDING_QUEUE) {
    RemovalNotification<K, V> notification = new RemovalNotification<K, V>(key, value, cause);
    map.removalNotificationQueue.offer(notification);
  }
}
 
开发者ID:cplutte,项目名称:bts,代码行数:7,代码来源:MapMakerInternalMap.java


示例8: testRemovalNotification_clear

import com.google.common.collect.MapMaker.RemovalNotification; //导入依赖的package包/类
@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"));
  }
 
开发者ID:sander120786,项目名称:guava-libraries,代码行数:48,代码来源:MapMakerTest.java


示例9: assertNotificationEnqueued

import com.google.common.collect.MapMaker.RemovalNotification; //导入依赖的package包/类
private static <K, V> void assertNotificationEnqueued(
    MapMakerInternalMap<K, V> map, K key, V value) {
  RemovalNotification<K, V> notification = map.removalNotificationQueue.poll();
  assertSame(key, notification.getKey());
  assertSame(value, notification.getValue());
}
 
开发者ID:sander120786,项目名称:guava-libraries,代码行数:7,代码来源:MapMakerInternalMapTest.java


示例10: onRemoval

import com.google.common.collect.MapMaker.RemovalNotification; //导入依赖的package包/类
@Override
public void onRemoval(RemovalNotification<K, V> notification) {
  count.incrementAndGet();
  lastKey = notification.getKey();
  lastValue = notification.getValue();
}
 
开发者ID:sander120786,项目名称:guava-libraries,代码行数:7,代码来源:MapMakerInternalMapTest.java



注:本文中的com.google.common.collect.MapMaker.RemovalNotification类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java GuiTask类代码示例发布时间:2022-05-22
下一篇:
Java Lock类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap