本文整理汇总了Java中com.google.common.cache.RemovalCause类的典型用法代码示例。如果您正苦于以下问题:Java RemovalCause类的具体用法?Java RemovalCause怎么用?Java RemovalCause使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RemovalCause类属于com.google.common.cache包,在下文中一共展示了RemovalCause类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import com.google.common.cache.RemovalCause; //导入依赖的package包/类
@Override
public void init(DeviceId deviceId, PipelinerContext context) {
this.serviceDirectory = context.directory();
this.deviceId = deviceId;
flowRuleService = serviceDirectory.get(FlowRuleService.class);
flowObjectiveStore = serviceDirectory.get(FlowObjectiveStore.class);
pendingNext = CacheBuilder.newBuilder()
.expireAfterWrite(20, TimeUnit.SECONDS)
.removalListener((RemovalNotification<Integer, NextObjective> notification) -> {
if (notification.getCause() == RemovalCause.EXPIRED) {
notification.getValue().context()
.ifPresent(c -> c.onError(notification.getValue(),
ObjectiveError.FLOWINSTALLATIONFAILED));
}
}).build();
}
示例2: activate
import com.google.common.cache.RemovalCause; //导入依赖的package包/类
@Activate
public void activate() {
providerService = providerRegistry.register(this);
pendingOperations = CacheBuilder.newBuilder()
.expireAfterWrite(TIMEOUT, TimeUnit.SECONDS)
.removalListener((RemovalNotification<Long, MeterOperation> notification) -> {
if (notification.getCause() == RemovalCause.EXPIRED) {
providerService.meterOperationFailed(notification.getValue(),
MeterFailReason.TIMEOUT);
}
}).build();
controller.addEventListener(listener);
controller.addListener(listener);
controller.getSwitches().forEach((sw -> createStatsCollection(sw)));
}
示例3: testCacheExpire
import com.google.common.cache.RemovalCause; //导入依赖的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());
}
示例4: AutoScaleProcessor
import com.google.common.cache.RemovalCause; //导入依赖的package包/类
AutoScaleProcessor(AutoScalerConfig configuration,
ScheduledExecutorService maintenanceExecutor) {
this.configuration = configuration;
this.maintenanceExecutor = maintenanceExecutor;
serializer = new JavaSerializer<>();
writerConfig = EventWriterConfig.builder().build();
writer = new AtomicReference<>();
cache = CacheBuilder.newBuilder()
.initialCapacity(INITIAL_CAPACITY)
.maximumSize(MAX_CACHE_SIZE)
.expireAfterAccess(configuration.getCacheExpiry().getSeconds(), TimeUnit.SECONDS)
.removalListener(RemovalListeners.asynchronous((RemovalListener<String, Pair<Long, Long>>) notification -> {
if (notification.getCause().equals(RemovalCause.EXPIRED)) {
triggerScaleDown(notification.getKey(), true);
}
}, maintenanceExecutor))
.build();
CompletableFuture.runAsync(this::bootstrapRequestWriters, maintenanceExecutor);
}
示例5: ShardWriterCache
import com.google.common.cache.RemovalCause; //导入依赖的package包/类
ShardWriterCache() {
this.cache = CacheBuilder
.newBuilder()
.expireAfterWrite(IDLE_TIMEOUT_MS, TimeUnit.MILLISECONDS)
.removalListener(new RemovalListener<Integer, ShardWriter<K, V>>() {
@Override
public void onRemoval(RemovalNotification<Integer, ShardWriter<K, V>> notification) {
if (notification.getCause() != RemovalCause.EXPLICIT) {
ShardWriter writer = notification.getValue();
LOG.info("{} : Closing idle shard writer {} after 1 minute of idle time.",
writer.shard, writer.producerName);
writer.producer.close();
}
}
}).build();
// run cache.cleanUp() every 10 seconds.
SCHEDULED_CLEAN_UP_THREAD.scheduleAtFixedRate(
new Runnable() {
@Override
public void run() {
cache.cleanUp();
}
},
CLEAN_UP_CHECK_INTERVAL_MS, CLEAN_UP_CHECK_INTERVAL_MS, TimeUnit.MILLISECONDS);
}
示例6: activate
import com.google.common.cache.RemovalCause; //导入依赖的package包/类
@Activate
public void activate() {
providerService = providerRegistry.register(this);
controller.addListener(listener);
controller.addEventListener(listener);
pendingBatches = CacheBuilder.newBuilder()
.expireAfterWrite(10, TimeUnit.SECONDS)
.removalListener((RemovalNotification<Long, InternalCacheEntry> notification) -> {
if (notification.getCause() == RemovalCause.EXPIRED) {
providerService.batchOperationCompleted(notification.getKey(),
notification.getValue().failedCompletion());
}
}).build();
for (OpenFlowSwitch sw : controller.getSwitches()) {
FlowStatsCollector fsc = new FlowStatsCollector(sw, POLL_INTERVAL);
fsc.start();
collectors.put(new Dpid(sw.getId()), fsc);
}
log.info("Started");
}
示例7: onRemoval
import com.google.common.cache.RemovalCause; //导入依赖的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));
}
}
}
示例8: onRemoval
import com.google.common.cache.RemovalCause; //导入依赖的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;
}
}
示例9: createRequestResponseMap
import com.google.common.cache.RemovalCause; //导入依赖的package包/类
/**
* Creates a new request response map, which holds requests that are waiting for responses.
*
* @return A new cache for waiting request responses.
*/
protected Cache<String, Class<? extends ResponseMessage>> createRequestResponseMap()
{
return CacheBuilder
.newBuilder()
.expireAfterWrite(IGNORED_REQUEST_TIMEOUT_MINUTES, TimeUnit.MINUTES)
.removalListener(new RemovalListener<String, Class<? extends ResponseMessage>>()
{
@Override
public void onRemoval(RemovalNotification<String, Class<? extends ResponseMessage>> notification)
{
if (notification.getCause() == RemovalCause.EXPIRED)
{
MessageMarshaller.this.onRequestExpired(
notification.getKey(),
notification.getValue());
}
}
}).build();
}
示例10: init
import com.google.common.cache.RemovalCause; //导入依赖的package包/类
@Override
public void init(DeviceId deviceId, PipelinerContext context) {
this.serviceDirectory = context.directory();
this.deviceId = deviceId;
flowRuleService = serviceDirectory.get(FlowRuleService.class);
pendingNext = CacheBuilder.newBuilder()
.expireAfterWrite(20, TimeUnit.SECONDS)
.removalListener((RemovalNotification<Integer, NextObjective> notification) -> {
if (notification.getCause() == RemovalCause.EXPIRED) {
notification.getValue().context()
.ifPresent(c -> c.onError(notification.getValue(),
ObjectiveError.FLOWINSTALLATIONFAILED));
}
}).build();
log.debug("Loaded handler behaviour EA1000Pipeliner for " + handler().data().deviceId().uri());
}
示例11: onRemoval
import com.google.common.cache.RemovalCause; //导入依赖的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();
}
}
}
示例12: onRemoval
import com.google.common.cache.RemovalCause; //导入依赖的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++;
}
}
示例13: onRemoval
import com.google.common.cache.RemovalCause; //导入依赖的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);
}
}
}
示例14: init
import com.google.common.cache.RemovalCause; //导入依赖的package包/类
public static void init() {
RemovalListener<String, Object> removalListener = removal -> {
if (removal.getCause() == RemovalCause.EXPIRED) {
getModpacks();
}
};
MODPACKS_CACHE = CacheBuilder.newBuilder().expireAfterWrite(1, TimeUnit.HOURS).removalListener(removalListener).build();
getModpacks();
getMods();
}
示例15: init
import com.google.common.cache.RemovalCause; //导入依赖的package包/类
@Override
public void init(DeviceId deviceId, PipelinerContext context) {
this.serviceDirectory = context.directory();
this.deviceId = deviceId;
pendingGroups = CacheBuilder.newBuilder()
.expireAfterWrite(20, TimeUnit.SECONDS)
.removalListener((RemovalNotification<GroupKey, NextObjective> notification) -> {
if (notification.getCause() == RemovalCause.EXPIRED) {
fail(notification.getValue(), ObjectiveError.GROUPINSTALLATIONFAILED);
}
}).build();
groupChecker.scheduleAtFixedRate(new GroupChecker(), 0, 500, TimeUnit.MILLISECONDS);
coreService = serviceDirectory.get(CoreService.class);
flowRuleService = serviceDirectory.get(FlowRuleService.class);
groupService = serviceDirectory.get(GroupService.class);
flowObjectiveStore = context.store();
groupService.addListener(new InnerGroupListener());
appId = coreService.registerApplication(
"org.onosproject.driver.CentecV350Pipeline");
initializePipeline();
}