本文整理汇总了Java中com.google.common.cache.RemovalNotification.getCause方法的典型用法代码示例。如果您正苦于以下问题:Java RemovalNotification.getCause方法的具体用法?Java RemovalNotification.getCause怎么用?Java RemovalNotification.getCause使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.cache.RemovalNotification
的用法示例。
在下文中一共展示了RemovalNotification.getCause方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onRemoval
import com.google.common.cache.RemovalNotification; //导入方法依赖的package包/类
@Override
public void onRemoval(RemovalNotification<K, V> notification)
{
switch (notification.getCause())
{
case EXPIRED:
notifyListeners(new GuavaCacheEntryEvent<>(this, EventType.EXPIRED, notification));
break;
case EXPLICIT:
notifyListeners(new GuavaCacheEntryEvent<>(this, EventType.REMOVED, notification));
break;
case REPLACED:
notifyListeners(new GuavaCacheEntryEvent<>(this, EventType.UPDATED, notification));
break;
}
}
示例2: testCacheExpire
import com.google.common.cache.RemovalNotification; //导入方法依赖的package包/类
@Test
public void testCacheExpire() throws InterruptedException {
int total = 10;
final Map<String, String> expired = new HashMap<>();
RemovalListener removalListener = new RemovalListener<String, String>() {
@Override
public void onRemoval(RemovalNotification<String, String> notification) {
if(RemovalCause.EXPIRED == notification.getCause()) {
expired.put(notification.getKey(), notification.getValue());
}
}
};
Cache<String, String> myCache = CacheBuilder.newBuilder()
.expireAfterWrite(2, TimeUnit.MILLISECONDS)
.removalListener(removalListener)
.build();
for(int i = 0; i < total; i++) {
myCache.put("key_" + i, "val_" + i);
}
Thread.sleep(10);
myCache.cleanUp();
assertEquals(total, expired.size());
}
示例3: onRemoval
import com.google.common.cache.RemovalNotification; //导入方法依赖的package包/类
@Override
public void onRemoval(RemovalNotification<CacheValue, NodeDocument> n) {
//If removed explicitly then we clear from L2
if (n.getCause() == RemovalCause.EXPLICIT
|| n.getCause() == RemovalCause.REPLACED) {
offHeapCache.invalidate(n.getKey());
}
//If removed because of size then we move it to
//L2
if (n.getCause() == RemovalCause.SIZE) {
NodeDocument doc = n.getValue();
if (doc != NodeDocument.NULL) {
offHeapCache.put(n.getKey(),
new NodeDocReference(n.getKey(), doc));
}
}
}
示例4: onRemoval
import com.google.common.cache.RemovalNotification; //导入方法依赖的package包/类
@Override
public void onRemoval(RemovalNotification<Writable, T> note) {
// System.err.println("S0 Cache: " + activeKey + " " + note.getKey() + " " + note.getCause() + " " + cache.size());
if (!(note.wasEvicted() || note.getCause() == RemovalCause.EXPLICIT)) {
return;
}
if (activeKey != null && activeKey.equals(note.getKey())) {
return;
}
try {
// System.err.println(" s0emit: " + note.getCause() + " " + note.getKey() + " " + note.getValue());
// Emit the record.
collector.emit(new FValues(note.getKey(), note.getValue()));
} catch (Throwable e) {
lastThrown = e;
}
}
示例5: onRemoval
import com.google.common.cache.RemovalNotification; //导入方法依赖的package包/类
@Override
public void onRemoval(RemovalNotification<String, CachedOffer> notification) {
if (notification.getCause() == RemovalCause.EXPLICIT) {
return;
}
LOG.debug("Cache removal for {} due to {}", notification.getKey(), notification.getCause());
synchronized (offerCache) {
if (notification.getValue().offerState == OfferState.AVAILABLE) {
declineOffer(notification.getValue());
} else {
notification.getValue().expire();
}
}
}
示例6: onRemoval
import com.google.common.cache.RemovalNotification; //导入方法依赖的package包/类
@Override
public void onRemoval(RemovalNotification<Object, Object> notification) {
if (notification.getCause() == RemovalCause.SIZE) {
if (evictionCounter % logInterval == 0) {
logger.log(LogLevel.INFO, "Cache entries evicted. In-memory cache of {}: Size{{}} MaxSize{{}}, {} {}", cacheId, cache.size(), maxSize, cache.stats(), EVICTION_MITIGATION_MESSAGE);
}
evictionCounter++;
}
}
示例7: onRemoval
import com.google.common.cache.RemovalNotification; //导入方法依赖的package包/类
@Override
public void onRemoval(RemovalNotification<FileInfo, MuxedFile> notification) {
if (notification.getCause() != RemovalCause.EXPLICIT) {
MuxedFile muxedFile = notification.getValue();
// This is racy, at worst we will re-trigger muxing for unlucky files being re-opened
if (!openMuxFiles.containsValue(muxedFile)) {
muxFiles.remove(muxedFile.getInfo(), muxedFile.getMuxer());
logger.info("Expired {}: {} deleted = {}", notification.getCause(), muxedFile, safeDelete(muxedFile));
} else {
logger.warn("BUG: Expired {}: {}, but is still open!", notification.getCause(), muxedFile);
}
}
}
示例8: onRemoval
import com.google.common.cache.RemovalNotification; //导入方法依赖的package包/类
@Override
public void onRemoval(final RemovalNotification<String, List<MemberDescriptor>> notification) {
final RemovalCause cause = notification.getCause();
if (cause.equals(RemovalCause.EXPLICIT)) {
final String key = notification.getKey();
ProjectDatabaseHelper.deleteMemberDescriptors(key);
}
}
示例9: onRemoval
import com.google.common.cache.RemovalNotification; //导入方法依赖的package包/类
@Override
public void onRemoval(final RemovalNotification<File, Source> notification) {
final RemovalCause cause = notification.getCause();
final Config config = Config.load();
if (config.useSourceCache() && cause.equals(RemovalCause.EXPLICIT)) {
final Source source = notification.getValue();
try {
deleteSource(source);
} catch (Exception e) {
log.catching(e);
}
}
}
示例10: onRemoval
import com.google.common.cache.RemovalNotification; //导入方法依赖的package包/类
@Override
public void onRemoval(RemovalNotification<String, String> notification) {
// rollback transaction on expire
if(RemovalCause.EXPIRED == notification.getCause()) {
rollback(notification.getKey());
}
}
示例11: onRemoval
import com.google.common.cache.RemovalNotification; //导入方法依赖的package包/类
@Override
public void onRemoval(final RemovalNotification<ChunkCoordIntPair, NBTTagCompound> notification) {
try {
// Only flush the entry if it was invalidated. Any entry could
// be updated prior to it being written by an IO thread so we
// want to avoid unnecessary writes.
if (notification.getCause() == RemovalCause.EXPLICIT)
AnvilChunkLoader.this.writeChunkNBTTags(notification.getKey(), notification.getValue());
} catch (final Exception e) {
e.printStackTrace();
}
}
示例12: onRemoval
import com.google.common.cache.RemovalNotification; //导入方法依赖的package包/类
@Override
public void onRemoval(RemovalNotification<TypedDirectionNamedPath, Notification> event) {
switch (event.getCause()) {
case SIZE: {
LOG.warn(String.format("Evicted notification '%s' with %d events", event.getKey(), event.getValue().getCount()));
break;
}
default: {
break;
}
}
}
示例13: onRemoval
import com.google.common.cache.RemovalNotification; //导入方法依赖的package包/类
/**
* Callback method for removal of items from the histories cache. Items removed from the cache need to be acked or failed
* according to the reason they were removed
*/
@Override
public void onRemoval(RemovalNotification<CVParticle, String> notification) {
// make sure the CVParticle object is removed from the history (even if removal was automatic!)
history.clear(notification.getKey(), notification.getValue());
if(notification.getCause() == RemovalCause.EXPIRED || notification.getCause() == RemovalCause.SIZE){
// item removed automatically --> fail the tuple
collector.fail(notification.getKey().getTuple());
}else{
// item removed explicitly --> ack the tuple
collector.ack(notification.getKey().getTuple());
}
}
示例14: onRemoval
import com.google.common.cache.RemovalNotification; //导入方法依赖的package包/类
@Override
public void onRemoval(RemovalNotification<Writable, T> note) {
// System.err.println("S1 Cache: " + activeKey + " " + note.getKey() + " " + note.getCause() + " " + cache.size());
if (!(note.wasEvicted() || note.getCause() == RemovalCause.EXPLICIT)) {
return;
}
if (activeKey != null && activeKey.equals(note.getKey())) {
return;
}
try {
// Determine if the current value is in the backlog or the prefetch.
T cur;
if (!stateBacklog.containsKey(note.getKey())) {
// Pull the values in from the prefetch.
runPrefetch();
}
cur = stateBacklog.remove(note.getKey());
// System.err.println("stateBacklogged: k=<" + note.getKey() + "> v=" + cur);
// Apply the update.
cur = storeAgg.combine(cur, note.getValue());
// Move things to the writeAhead.
writeAhead.put(note.getKey(), cur);
// Emit the result.
collector.emit(new FValues(note.getKey(), cur));
} catch (Throwable e) {
lastThrown = e;
}
}
示例15: onRemoval
import com.google.common.cache.RemovalNotification; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void onRemoval(final RemovalNotification<String, StratumTcpServerConnection> notification)
{
if (notification.getCause() == RemovalCause.EXPIRED)
StratumTcpServer.this.onConnectionTimeout(notification.getValue());
}