@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(); }
@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))); }
@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()); }
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); }
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); }
@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"); }
@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)); } } }
@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; } }
/** * 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(); }
@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()); }
@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(); } } }
@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++; } }
@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); } } }
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(); }
@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(); }
@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.SpringOpenTTP"); setTableMissEntries(); log.info("Spring Open TTP driver initialized"); }
@Override public void init(DeviceId deviceId, PipelinerContext context) { log.debug("Initiate OLT pipeline"); this.serviceDirectory = context.directory(); this.deviceId = deviceId; flowRuleService = serviceDirectory.get(FlowRuleService.class); coreService = serviceDirectory.get(CoreService.class); groupService = serviceDirectory.get(GroupService.class); flowObjectiveStore = context.store(); storageService = serviceDirectory.get(StorageService.class); appId = coreService.registerApplication( "org.onosproject.driver.OLTPipeline"); pendingGroups = CacheBuilder.newBuilder() .expireAfterWrite(20, TimeUnit.SECONDS) .removalListener((RemovalNotification<GroupKey, NextObjective> notification) -> { if (notification.getCause() == RemovalCause.EXPIRED) { fail(notification.getValue(), ObjectiveError.GROUPINSTALLATIONFAILED); } }).build(); groupService.addListener(new InnerGroupListener()); }
@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); meterService = serviceDirectory.get(MeterService.class); deviceService = serviceDirectory.get(DeviceService.class); flowObjectiveStore = context.store(); groupService.addListener(new InnerGroupListener()); appId = coreService.registerApplication(APPID); initializePipeline(); }
private Cache<Long, InternalCacheEntry> createBatchCache() { return CacheBuilder.newBuilder() .expireAfterWrite(10, TimeUnit.SECONDS) .removalListener((RemovalNotification<Long, InternalCacheEntry> notification) -> { if (notification.getCause() == RemovalCause.EXPIRED) { providerService.batchOperationCompleted(notification.getKey(), notification.getValue().failedCompletion()); } }).build(); }
/** * Constructor. */ TypeCache() { this.lruCache = CacheBuilder.newBuilder().maximumSize(8192).removalListener(new RemovalListener<String, CachedType>() { @Override public void onRemoval(RemovalNotification<String, CachedType> notification) { if (RemovalCause.SIZE.equals(notification.getCause())) { softCache.put(notification.getKey(), notification.getValue()); } } }).build(); this.softCache = CacheBuilder.newBuilder().softValues().build(); }
@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); } }
@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); } } }
@Override public void onRemoval(RemovalNotification<String, String> notification) { // rollback transaction on expire if(RemovalCause.EXPIRED == notification.getCause()) { rollback(notification.getKey()); } }
private static Cache<RaptureURI, Optional<String>> setupObjectStorageCache() { return CacheBuilder.newBuilder().expireAfterAccess(1, TimeUnit.MINUTES) .removalListener(new RemovalListener<RaptureURI, Optional<String>>() { @Override public void onRemoval(RemovalNotification<RaptureURI, Optional<String>> notification) { if (notification.getCause() != RemovalCause.REPLACED) { if (log.isTraceEnabled()) log.trace("Removed " + notification.getKey() + " from local cache because " + notification.getCause()); } } }).build(); }
private void handleCacheRemove(RemovalNotification<Long, UnconfirmedMessage> notification) { if (notification.getCause().equals(RemovalCause.EXPIRED)) { UnconfirmedMessage message = notification.getValue(); if (message != null) { //TODO figure out why this can be null?? ackWorker.schedule(() -> { if (message.published) { log.warnWithParams("Message did not receive publish-confirm in time", "messageId", message.props.getMessageId()); } message.nack(new TimeoutException("Message did not receive publish confirm in time")); }); } } }
@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(); } }
/** * 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()); } }
@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; } }
/** * {@inheritDoc} */ @Override public void onRemoval(final RemovalNotification<String, StratumTcpServerConnection> notification) { if (notification.getCause() == RemovalCause.EXPIRED) StratumTcpServer.this.onConnectionTimeout(notification.getValue()); }
@Override public void onRemoval(RemovalNotification<UUID, MapReduceTracker.RequestWrapper> notification) { if (notification.getCause() == RemovalCause.EXPIRED) { RequestWrapper wrapper = notification.getValue(); log.warn("Timing out MapReduce request <{}> with ref count <{}>", wrapper.getClass().toString(), wrapper.pendingResponseCount.get()); wrapper.request.onComplete(true); } }
@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(); 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.SpringOpenTTP"); setTableMissEntries(); log.info("Spring Open TTP driver initialized"); }
@Activate public void activate() { providerRegistryService.registerProvider(this); internalMeterListener = new InternalMeterListener(); idGenerator = getIdGenerator(); pendingOperations = CacheBuilder.newBuilder() .expireAfterWrite(TIMEOUT, TimeUnit.SECONDS) .removalListener( (RemovalNotification<Long, VirtualMeterOperation> notification) -> { if (notification.getCause() == RemovalCause.EXPIRED) { NetworkId networkId = notification.getValue().networkId(); MeterOperation op = notification.getValue().operation(); VirtualMeterProviderService providerService = (VirtualMeterProviderService) providerRegistryService .getProviderService(networkId, VirtualMeterProvider.class); providerService.meterOperationFailed(op, MeterFailReason.TIMEOUT); } }).build(); meterService.addListener(internalMeterListener); log.info("Started"); }
@Override public void init(DeviceId deviceId, PipelinerContext context) { this.deviceId = deviceId; 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(); }
@Override public void onRemoval(RemovalNotification<State, Set<KeyAndSource>> notification) { Preconditions.checkState(RemovalCause.COLLECTED.equals(notification.getCause())); cleanUpForCollectedState(notification.getValue()); }
public RemovalCause getRemovalCause() { return removalCause; }