微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

com.google.common.collect.MapMaker.RemovalNotification的实例源码

项目:otter    文件otterMigrateMap.java   
@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   
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());
}
项目: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);
    }
  }
}
项目:otter    文件otterMigrateMap.java   
@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   
@Override
public void onRemoval(RemovalNotification<Object,Object> notification) {}
项目: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   
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);
  }
}
项目:j2objc    文件GenericMapMaker.java   
@Override
public void onRemoval(RemovalNotification<Object,Object> notification) {}
项目: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   
@Override
public void onRemoval(RemovalNotification<Object,Object> notification) {}
项目: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   
private static <K,V> void assertNotificationEnqueued(
    MapMakerInternalMap<K,V> map,V value) {
  RemovalNotification<K,V> notification = map.removalNotificationQueue.poll();
  assertSame(key,notification.getValue());
}
项目:guava-libraries    文件MapMakerInternalMapTest.java   
@Override
public void onRemoval(RemovalNotification<K,V> notification) {
  count.incrementAndGet();
  lastKey = notification.getKey();
  lastValue = notification.getValue();
}
项目:guava-libraries    文件MapMakerInternalMapTest.java   
@Override
public void onRemoval(RemovalNotification<K,V> notification) {
  add(notification);
}
项目:VectorAttackScanner    文件GenericMapMaker.java   
@Override
public void onRemoval(RemovalNotification<Object,Object> notification) {}
项目: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   
@Override
public void onRemoval(RemovalNotification<Object,Object> notification) {}
项目: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   
@Override
public void onRemoval(RemovalNotification<Object,Object> notification) {}
项目: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   
@Override
public void onRemoval(RemovalNotification<Object,Object> notification) {}
项目: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] 举报,一经查实,本站将立刻删除。