Guava RemovalNotification - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Guava RemovalNotification class.

This code example shows how to use the following methods:getValue, wasEvicted
        totalMetric.inc(sizeInBytes); 
    } 
 
    @Override 
    public void onRemoval(RemovalNotification<WeightedFilterCache.FilterCacheKey, DocIdSet> removalNotification) { 
        if (removalNotification.wasEvicted()) { 
            evictionsMetric.inc(); 
        } 
        if (removalNotification.getValue() != null) { 
            totalMetric.dec(DocIdSets.sizeInBytes(removalNotification.getValue())); 
        } 
    } 
} 
7
CodeRank
This code example shows how to use the following methods:getCause, getKey, getValue
    this.executorService = executorService;
  } 
 
  @Override 
  public void onRemoval(RemovalNotification<QueryHandle, OperationInfo> notification) {
    LOG.trace("Got removal notification for handle {} with cause {}", notification.getKey(), notification.getCause());
    executorService.submit(new ResourceCleanup(notification.getKey(), notification.getValue()));
  } 
 
  private class ResourceCleanup implements Runnable {
    private final QueryHandle handle;
    private final OperationInfo opInfo;
 
    private ResourceCleanup(QueryHandle handle, OperationInfo opInfo) {
      this.handle = handle;
      this.opInfo = opInfo;
    } 
 
    @Override 
    public void run() { 
5
CodeRank
This code example shows how to use the following methods:getKey
package org.springframework.issues; 
 
import com.google.common.cache.RemovalListener;
import com.google.common.cache.RemovalNotification;
 
public class PortletCacheListener implements RemovalListener<String,Object> {
 
	 
	public void onRemoval(RemovalNotification<String, Object> arg0) {
		System.out.println(arg0.getKey() + " has been altered");
	} 
 
} 

5
CodeRank
This code example shows how to use the following methods:getKey, getValue
        this.engineCache = engineCache; 
    } 
 
    @Override 
    public void onRemoval(RemovalNotification<String, QueryEngine> notification) { 
        QueryEngine qe = notification.getValue(); 
        // a refresh call that returns the current value can generate spurious events 
        QueryEngine currentEngine = engineCache.loadingEngineCache.asMap().get(notification.getKey()); 
        if (currentEngine != qe) { 
            assert qe != null; //we only use strong references 
            try { 
                qe.closeWhenIdle(); 
            } catch (Throwable t) { 
                log.error("Generic Error while closing Engine", t); 
            } 
            if (currentEngine == null) { 
                directoriesEvicted.mark(); 
            } 
        } 
    } 
5
CodeRank
This code example shows how to use the following methods:getCause, getValue
                                    return kb;
                                } 
                            }) 
                            .removalListener(new RemovalListener<String, File>() {
                                public void onRemoval(RemovalNotification<String, File> rn) {
                                    if (rn.getCause().equals(RemovalCause.REPLACED)) {
                                        /* don't delete replaced files */ 
                                        return; 
                                    } 
                                    removeFile(rn.getValue());
                                } 
                            }) 
                            .build(new CacheLoader<String, File>() {
                                public File load(String path) throws Exception {
                                    return downloadFile(path);
                                } 
                            }); 
 
        scanExistingFiles(); 
    } 
4
CodeRank
This code example shows how to use the following methods:getValue
          .maximumSize(cacheSize)
          .recordStats()
          .removalListener(new RemovalListener<Integer, MappedByteBuffer>() {
            @Override 
            public void onRemoval(RemovalNotification<Integer, MappedByteBuffer> notification) {
              MappedByteBuffer value = notification.getValue();
              if (value != null) {
                value.force();
              } 
            }}) 
          .build(new CacheLoader<Integer, MappedByteBuffer>() {
            @Override 
            public MappedByteBuffer load(Integer key) throws Exception {
              return ByteBufferUtil.createNewBuffer( 
                  String.format("%s/dma_list_%d.mem", directory, key), fileSize);
            } 
          }); 
      return new DmaList<>(directory, schema, metaDataBuffer, buffers, numRecords, numRecordsPerFile);
    } catch (IOException e) {
      throw new RuntimeException(e);
3
CodeRank
See Code Examples for Guava RemovalNotification Methods: