com.google.common.cache.RemovalNotification Java Examples

The following examples show how to use com.google.common.cache.RemovalNotification. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KMSAudit.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Create a new KMSAudit.
 *
 * @param windowMs Duplicate events within the aggregation window are quashed
 *                 to reduce log traffic. A single message for aggregated
 *                 events is printed at the end of the window, along with a
 *                 count of the number of aggregated events.
 */
KMSAudit(long windowMs) {
  cache = CacheBuilder.newBuilder()
      .expireAfterWrite(windowMs, TimeUnit.MILLISECONDS)
      .removalListener(
          new RemovalListener<String, AuditEvent>() {
            @Override
            public void onRemoval(
                RemovalNotification<String, AuditEvent> entry) {
              AuditEvent event = entry.getValue();
              if (event.getAccessCount().get() > 0) {
                KMSAudit.this.logEvent(event);
                event.getAccessCount().set(0);
                KMSAudit.this.cache.put(entry.getKey(), event);
              }
            }
          }).build();
  executor = Executors.newScheduledThreadPool(1, new ThreadFactoryBuilder()
      .setDaemon(true).setNameFormat(KMS_LOGGER_NAME + "_thread").build());
  executor.scheduleAtFixedRate(new Runnable() {
    @Override
    public void run() {
      cache.cleanUp();
    }
  }, windowMs / 10, windowMs / 10, TimeUnit.MILLISECONDS);
}
 
Example #2
Source File: RecordLogDirectory.java    From lsmtree with Apache License 2.0 6 votes vote down vote up
public FileCache(final boolean mlockFiles) {
    this.mlockFiles = mlockFiles;
    decompressorPool = new LinkedBlockingQueue<Decompressor>();
    readerCache = CacheBuilder.newBuilder().maximumSize(maxCachedFiles)
            .removalListener(new RemovalListener<Integer, Option<SharedReference<BlockCompressedRecordFile<E>>>>() {
                @Override
                public void onRemoval(RemovalNotification<Integer, Option<SharedReference<BlockCompressedRecordFile<E>>>> notification) {
                    final Integer segmentNum = notification.getKey();
                    final Option<SharedReference<BlockCompressedRecordFile<E>>> referenceOption = notification.getValue();
                    for (SharedReference<BlockCompressedRecordFile<E>> reference : referenceOption) {
                        try {
                            reference.close();
                        } catch (IOException e) {
                            log.error("error on block cleanup", e);
                        }
                    }
                }
            })
            .build(open);
}
 
Example #3
Source File: SourceManager.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
private SourceManager(KylinConfig config) {
    this.systemConfig = config;
    this.sourceMap = CacheBuilder.newBuilder().expireAfterWrite(1, TimeUnit.DAYS)
            .removalListener(new RemovalListener<String, ISource>() {
                @Override
                public void onRemoval(RemovalNotification<String, ISource> entry) {
                    ISource s = entry.getValue();
                    if (s != null) {
                        try {
                            s.close();
                        } catch (Throwable e) {
                            logger.error("Failed to close ISource: {}", s.getClass().getName(), e);
                        }
                    }
                }
            }).build();
}
 
Example #4
Source File: WorkerStubs.java    From bazel-buildfarm with Apache License 2.0 6 votes vote down vote up
public static LoadingCache create(DigestUtil digestUtil) {
  return CacheBuilder.newBuilder()
      .expireAfterAccess(10, TimeUnit.MINUTES)
      .removalListener(
          new RemovalListener<String, Instance>() {
            @Override
            public void onRemoval(RemovalNotification<String, Instance> notification) {
              stopInstance(notification.getValue());
            }
          })
      .build(
          new CacheLoader<String, Instance>() {
            @Override
            public Instance load(String worker) {
              return newStubInstance(worker, digestUtil);
            }
          });
}
 
Example #5
Source File: KMSAudit.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Create a new KMSAudit.
 *
 * @param windowMs Duplicate events within the aggregation window are quashed
 *                 to reduce log traffic. A single message for aggregated
 *                 events is printed at the end of the window, along with a
 *                 count of the number of aggregated events.
 */
KMSAudit(long windowMs) {
  cache = CacheBuilder.newBuilder()
      .expireAfterWrite(windowMs, TimeUnit.MILLISECONDS)
      .removalListener(
          new RemovalListener<String, AuditEvent>() {
            @Override
            public void onRemoval(
                RemovalNotification<String, AuditEvent> entry) {
              AuditEvent event = entry.getValue();
              if (event.getAccessCount().get() > 0) {
                KMSAudit.this.logEvent(event);
                event.getAccessCount().set(0);
                KMSAudit.this.cache.put(entry.getKey(), event);
              }
            }
          }).build();
  executor = Executors.newScheduledThreadPool(1, new ThreadFactoryBuilder()
      .setDaemon(true).setNameFormat(KMS_LOGGER_NAME + "_thread").build());
  executor.scheduleAtFixedRate(new Runnable() {
    @Override
    public void run() {
      cache.cleanUp();
    }
  }, windowMs / 10, windowMs / 10, TimeUnit.MILLISECONDS);
}
 
Example #6
Source File: SnapshotManager.java    From kylin with Apache License 2.0 6 votes vote down vote up
private SnapshotManager(KylinConfig config) {
    this.config = config;
    this.snapshotCache = CacheBuilder.newBuilder().removalListener(new RemovalListener<String, SnapshotTable>() {
        @Override
        public void onRemoval(RemovalNotification<String, SnapshotTable> notification) {
            SnapshotManager.logger.info("Snapshot with resource path {} is removed due to {}",
                    notification.getKey(), notification.getCause());
        }
    }).maximumSize(config.getCachedSnapshotMaxEntrySize())//
            .expireAfterWrite(1, TimeUnit.DAYS).build(new CacheLoader<String, SnapshotTable>() {
                @Override
                public SnapshotTable load(String key) throws Exception {
                    SnapshotTable snapshotTable = SnapshotManager.this.load(key, true);
                    return snapshotTable;
                }
            });
}
 
Example #7
Source File: PageCacheBuilder.java    From hermes with Apache License 2.0 6 votes vote down vote up
private LoadingCache<Long, Page<T>> buildCache(int size) {
	return CacheBuilder.newBuilder().concurrencyLevel(1).initialCapacity(size).maximumSize(size)
	      .removalListener(new RemovalListener<Long, Page<T>>() {

		      @Override
		      public void onRemoval(RemovalNotification<Long, Page<T>> notification) {
			      m_recentlyExpiredPagesCache.get().put(notification.getKey(), true);
		      }
	      }).build(new CacheLoader<Long, Page<T>>() {

		      @Override
		      public Page<T> load(Long pageNo) throws Exception {
			      return new Page<>(pageNo, m_pageSize, m_pageLoadIntervalMillis);
		      }

	      });
}
 
Example #8
Source File: OpenFlowMeterProvider.java    From onos with Apache License 2.0 6 votes vote down vote up
@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) {
                    log.debug("Expired on meter provider. Meter key {} and operation {}",
                            notification.getKey(), notification.getValue());
                    providerService.meterOperationFailed(notification.getValue(),
                                                         MeterFailReason.TIMEOUT);
                }
            }).build();

    controller.addEventListener(listener);
    controller.addListener(listener);

    controller.getSwitches().forEach((sw -> createStatsCollection(sw)));
}
 
Example #9
Source File: ZKDiscoveryService.java    From twill with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs ZKDiscoveryService using the provided zookeeper client for storing service registry under namespace.
 * @param zkClient of zookeeper quorum
 * @param namespace under which the service registered would be stored in zookeeper.
 *                  If namespace is {@code null}, no namespace will be used.
 */
public ZKDiscoveryService(ZKClient zkClient, String namespace) {
  this.closed = new AtomicBoolean();
  this.discoverables = HashMultimap.create();
  this.lock = new ReentrantLock();
  this.retryExecutor = Executors.newSingleThreadScheduledExecutor(
    Threads.createDaemonThreadFactory("zk-discovery-retry"));
  this.zkClient = namespace == null ? zkClient : ZKClients.namespace(zkClient, namespace);
  this.services = CacheBuilder.newBuilder()
    .removalListener(new RemovalListener<String, ServiceDiscoveredCacheEntry>() {
      @Override
      public void onRemoval(RemovalNotification<String, ServiceDiscoveredCacheEntry> notification) {
        ServiceDiscoveredCacheEntry entry = notification.getValue();
        if (entry != null) {
          entry.cancel();
        }
      }
    })
    .build(createServiceLoader());
  this.watcherCancellable = this.zkClient.addConnectionWatcher(createConnectionWatcher());
}
 
Example #10
Source File: SingularityOfferCache.java    From Singularity with Apache License 2.0 6 votes vote down vote up
@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();
    }
  }
}
 
Example #11
Source File: BookKeeper.java    From rubix with Apache License 2.0 6 votes vote down vote up
@Override
public void onRemoval(RemovalNotification<String, FileMetadata> notification)
{
  FileMetadata md = notification.getValue();
  try {
    md.closeAndCleanup(notification.getCause(), fileMetadataCache);
    if (!isValidatingCachingBehavior(md.getRemotePath())) {
      switch (notification.getCause()) {
        case EXPLICIT:
          cacheInvalidationCount.inc();
          break;
        case SIZE:
          cacheEvictionCount.inc();
          break;
        case EXPIRED:
          cacheExpiryCount.inc();
          break;
        default:
          break;
      }
    }
  }
  catch (IOException e) {
    log.warn("Could not cleanup FileMetadata for " + notification.getKey(), e);
  }
}
 
Example #12
Source File: ActionInvokingWebSocket.java    From chassis with Apache License 2.0 6 votes vote down vote up
public void onRemoval(RemovalNotification<String, Object> notification) {
	Class<?> handlerClass = null;
	
	try {
		handlerClass = Class.forName(notification.getKey());
	} catch (ClassNotFoundException e) {
		logger.error("Unexpected exception", e);
	}
	
	if (handlerClass != null) {
		String[] beanNames = beanFactory.getBeanNamesForType(handlerClass);

		if (beanNames != null && beanNames.length > 0) {
			if (beanFactory.isPrototype(beanNames[0])) {
				if (notification.getValue() instanceof WebSocketSessionAware) {
					WebSocketSessionAware webSocketSessionAwareHandler = (WebSocketSessionAware)notification.getValue();
					
					webSocketSessionAwareHandler.onWebSocketSessionRemoved(webSocketSession);
				}
				
				beanFactory.destroyBean(notification.getValue());
			} // else this is a singleton and we don't do anything with singletons
		} // this shouldn't happen
	} // this shouldn't happen either
}
 
Example #13
Source File: ChallengeCompletionLogic.java    From uSkyBlock with GNU General Public License v3.0 6 votes vote down vote up
public ChallengeCompletionLogic(uSkyBlock plugin, FileConfiguration config) {
    this.plugin = plugin;
    storeOnIsland = config.getString("challengeSharing", "island").equalsIgnoreCase("island");
    completionCache = CacheBuilder
            .from(plugin.getConfig().getString("options.advanced.completionCache", "maximumSize=200,expireAfterWrite=15m,expireAfterAccess=10m"))
            .removalListener(new RemovalListener<String, Map<String, ChallengeCompletion>>() {
                @Override
                public void onRemoval(RemovalNotification<String, Map<String, ChallengeCompletion>> removal) {
                    saveToFile(removal.getKey(), removal.getValue());
                }
            })
            .build(new CacheLoader<String, Map<String, ChallengeCompletion>>() {
                       @Override
                       public Map<String, ChallengeCompletion> load(String id) throws Exception {
                           return loadFromFile(id);
                       }
                   }
            );
    storageFolder = new File(plugin.getDataFolder(), "completion");
    if (!storageFolder.exists() || !storageFolder.isDirectory()) {
        storageFolder.mkdirs();
    }
}
 
Example #14
Source File: DictionaryManager.java    From kylin with Apache License 2.0 6 votes vote down vote up
private DictionaryManager(KylinConfig config) {
    this.config = config;
    this.dictCache = CacheBuilder.newBuilder()//
            .softValues()//
            .removalListener(new RemovalListener<String, DictionaryInfo>() {
                @Override
                public void onRemoval(RemovalNotification<String, DictionaryInfo> notification) {
                    DictionaryManager.logger.info("Dict with resource path {} is removed due to {}",
                            notification.getKey(), notification.getCause());
                }
            })//
            .maximumSize(config.getCachedDictMaxEntrySize())//
            .expireAfterWrite(1, TimeUnit.DAYS).build(new CacheLoader<String, DictionaryInfo>() {
                @Override
                public DictionaryInfo load(String key) throws Exception {
                    DictionaryInfo dictInfo = DictionaryManager.this.load(key, true);
                    if (dictInfo == null) {
                        return NONE_INDICATOR;
                    } else {
                        return dictInfo;
                    }
                }
            });
}
 
Example #15
Source File: TransportSessionManager.java    From joyqueue with Apache License 2.0 6 votes vote down vote up
@Override
protected void validate() throws Exception {
    client = transportClientFactory.create(clientConfig);
    sessions = CacheBuilder.newBuilder()
            .expireAfterAccess(config.getSessionExpireTime(), TimeUnit.MILLISECONDS)
            .removalListener((RemovalNotification<Integer, TransportSession>  notification) -> {
                try {
                    TransportSession session = notification.getValue();
                    logger.info("create session, id: {}, ip: {}, port: {}", session.getId(), session.getHost(), session.getPort());
                    session.stop();
                } catch (Exception e) {
                    logger.error("stop session exception, id: {}", notification.getKey(), e);
                }
            })
            .build();
}
 
Example #16
Source File: ClientGroupManager.java    From joyqueue with Apache License 2.0 6 votes vote down vote up
@Override
protected void validate() throws Exception {
    clientGroupCache = CacheBuilder.newBuilder()
            .expireAfterAccess(config.getChannelMaxIdleTime(), TimeUnit.MILLISECONDS)
            .removalListener(new RemovalListener<BrokerNode, ClientGroup>() {
                @Override
                public void onRemoval(RemovalNotification<BrokerNode, ClientGroup> removalNotification) {
                    try {
                        removalNotification.getValue().stop();
                    } catch (Exception e) {
                        logger.error("close client exception, address: {}, error: {}", removalNotification.getKey().getHost(), e.getMessage());
                        logger.debug("close client exception, address: {}", removalNotification.getKey().getHost(), e);
                    }
                }
            })
            .build();
}
 
Example #17
Source File: TenantCacheImpl.java    From phoenix with Apache License 2.0 6 votes vote down vote up
private Cache<ImmutableBytesPtr, CacheEntry> buildCache(final int ttl, final boolean isPersistent) {
    CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder();
    if (isPersistent) {
        builder.expireAfterWrite(ttl, TimeUnit.MILLISECONDS);
    } else {
        builder.expireAfterAccess(ttl, TimeUnit.MILLISECONDS);
    }
    return builder
        .ticker(getTicker())
        .removalListener(new RemovalListener<ImmutableBytesPtr, CacheEntry>(){
            @Override
            public void onRemoval(RemovalNotification<ImmutableBytesPtr, CacheEntry> notification) {
                if (isPersistent || !notification.getValue().getUsePersistentCache()) {
                    Closeables.closeAllQuietly(Collections.singletonList(notification.getValue()));
                }
            }
        })
        .build();
}
 
Example #18
Source File: FileWatcherRegistry.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
/**
 * 
 */
public FileWatcherRegistry() {
   this.watchers =
         CacheBuilder
            .newBuilder()
            .removalListener(new RemovalListener<Path, FileWatcherRegistry.Watcher>() {
               @Override
               public void onRemoval(RemovalNotification<Path, Watcher> notification) {
                  notification.getValue().stop();
               }
            })
            .build(new CacheLoader<Path, Watcher>() {
               @Override
               public FileWatcherRegistry.Watcher load(Path key) throws Exception {
                  return watch(key);
               }
            });
   this.executor =
         new ThreadPoolBuilder()
            .withNameFormat("resource-watcher-%d")
            .withMetrics("resource.watcher")
            .build();
}
 
Example #19
Source File: JdbcMeta.java    From calcite-avatica with Apache License 2.0 6 votes vote down vote up
public void onRemoval(RemovalNotification<Integer, StatementInfo> notification) {
  Integer stmtId = notification.getKey();
  StatementInfo doomed = notification.getValue();
  if (doomed == null) {
    // log/throw?
    return;
  }
  LOG.debug("Expiring statement {} because {}", stmtId, notification.getCause());
  try {
    if (doomed.getResultSet() != null) {
      doomed.getResultSet().close();
    }
    if (doomed.statement != null) {
      doomed.statement.close();
    }
  } catch (Throwable t) {
    LOG.info("Exception thrown while expiring statement {}", stmtId, t);
  }
}
 
Example #20
Source File: ExtTableSnapshotInfoManager.java    From kylin with Apache License 2.0 6 votes vote down vote up
private ExtTableSnapshotInfoManager(KylinConfig config) {
    this.config = config;
    this.snapshotCache = CacheBuilder.newBuilder().removalListener(new RemovalListener<String, ExtTableSnapshotInfo>() {
        @Override
        public void onRemoval(RemovalNotification<String, ExtTableSnapshotInfo> notification) {
            ExtTableSnapshotInfoManager.logger.info("Snapshot with resource path " + notification.getKey()
                    + " is removed due to " + notification.getCause());
        }
    }).maximumSize(1000)//
            .expireAfterWrite(1, TimeUnit.DAYS).build(new CacheLoader<String, ExtTableSnapshotInfo>() {
                @Override
                public ExtTableSnapshotInfo load(String key) throws Exception {
                    ExtTableSnapshotInfo snapshot = ExtTableSnapshotInfoManager.this.load(key);
                    return snapshot;
                }
            });
}
 
Example #21
Source File: KeyProviderCache.java    From big-c with Apache License 2.0 6 votes vote down vote up
public KeyProviderCache(long expiryMs) {
  cache = CacheBuilder.newBuilder()
      .expireAfterAccess(expiryMs, TimeUnit.MILLISECONDS)
      .removalListener(new RemovalListener<URI, KeyProvider>() {
        @Override
        public void onRemoval(
            RemovalNotification<URI, KeyProvider> notification) {
          try {
            notification.getValue().close();
          } catch (Throwable e) {
            LOG.error(
                "Error closing KeyProvider with uri ["
                    + notification.getKey() + "]", e);
            ;
          }
        }
      })
      .build();
}
 
Example #22
Source File: RqdClientGrpc.java    From OpenCue with Apache License 2.0 6 votes vote down vote up
private void buildChannelCache() {
    this.channelCache = CacheBuilder.newBuilder()
            .maximumSize(rqdCacheSize)
            .expireAfterAccess(rqdCacheExpiration, TimeUnit.MINUTES)
            .removalListener(new RemovalListener<String, ManagedChannel>() {
                @Override
                public void onRemoval(RemovalNotification<String, ManagedChannel> removal){
                    ManagedChannel conn = removal.getValue();
                    conn.shutdown();
                }
            })
            .build(
                    new CacheLoader<String, ManagedChannel>() {
                        @Override
                        public ManagedChannel load(String host) throws Exception {
                            ManagedChannelBuilder channelBuilder = ManagedChannelBuilder.forAddress(
                                    host, rqdServerPort).usePlaintext();
                            return channelBuilder.build();
                        }
                    });
}
 
Example #23
Source File: ScriptService.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public void onRemoval(RemovalNotification<CacheKey, CompiledScript> notification) {
    if (logger.isDebugEnabled()) {
        logger.debug("notifying script services of script removal due to: [{}]", notification.getCause());
    }
    scriptMetrics.onCacheEviction();
    for (ScriptEngineService service : scriptEngines) {
        try {
            service.scriptRemoved(notification.getValue());
        } catch (Exception e) {
            logger.warn("exception calling script removal listener for script service", e);
            // We don't rethrow because Guava would just catch the
            // exception and log it, which we have already done
        }
    }
}
 
Example #24
Source File: RocksDBLookupTableCache.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
private void init() {
    this.basePath = getCacheBasePath(config);

    this.maxCacheSizeInKB = (long) (config.getExtTableSnapshotLocalCacheMaxSizeGB() * 1024 * 1024);
    this.tablesCache = CacheBuilder.newBuilder().removalListener(new RemovalListener<String, CachedTableInfo>() {
        @Override
        public void onRemoval(RemovalNotification<String, CachedTableInfo> notification) {
            logger.warn(notification.getValue() + " is removed " + "because of " + notification.getCause());
            notification.getValue().cleanStorage();
        }
    }).maximumWeight(maxCacheSizeInKB).weigher(new Weigher<String, CachedTableInfo>() {
        @Override
        public int weigh(String key, CachedTableInfo value) {
            return value.getSizeInKB();
        }
    }).build();
    restoreCacheState();
    cacheStateChecker = new CacheStateChecker();
    initExecutors();
}
 
Example #25
Source File: IndicesRequestCache.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void onRemoval(RemovalNotification<Key, Value> notification) {
    if (notification.getKey() == null) {
        return;
    }
    notification.getKey().shard.requestCache().onRemoval(notification);
}
 
Example #26
Source File: ShuffleHandler.java    From tez with Apache License 2.0 5 votes vote down vote up
@Override
public void onRemoval(RemovalNotification<AttemptPathIdentifier,
    AttemptPathInfo> notification) {
  if (LOG.isDebugEnabled()) {
    LOG.debug("PathCache Eviction: " + notification.getKey() +
        ", Reason=" + notification.getCause());
  }
}
 
Example #27
Source File: CachedDataSourceRegistryWrapper.java    From metamodel-membrane with Apache License 2.0 5 votes vote down vote up
private RemovalListener<String, DataContext> createRemovalListener() {
    return new RemovalListener<String, DataContext>() {
        @Override
        public void onRemoval(final RemovalNotification<String, DataContext> notification) {
            final DataContext dataContext = notification.getValue();
            // some DataContexts are closeable - attempt closing it here
            FileHelper.safeClose(dataContext);
        }
    };
}
 
Example #28
Source File: LogSegmentMetadataCache.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
@Override
public void onRemoval(RemovalNotification<String, LogSegmentMetadata> notification) {
    if (notification.wasEvicted()) {
        if (logger.isDebugEnabled()) {
            logger.debug("Log segment of {} was evicted.", notification.getKey());
        }
    }
}
 
Example #29
Source File: HiveMetastoreClientPool.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
private static final Cache<Optional<String>, HiveMetastoreClientPool> createPoolCache(final Properties properties) {
  long duration = properties.containsKey(POOL_CACHE_TTL_MINUTES_KEY)
      ? Long.parseLong(properties.getProperty(POOL_CACHE_TTL_MINUTES_KEY)) : DEFAULT_POOL_CACHE_TTL_MINUTES;
  return CacheBuilder.newBuilder()
      .expireAfterAccess(duration, TimeUnit.MINUTES)
      .removalListener(new RemovalListener<Optional<String>, HiveMetastoreClientPool>() {
        @Override
        public void onRemoval(RemovalNotification<Optional<String>, HiveMetastoreClientPool> notification) {
          if (notification.getValue() != null) {
            notification.getValue().close();
          }
        }
      }).build();
}
 
Example #30
Source File: DFSClientCache.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private RemovalListener<String, DFSClient> clientRemovalListener() {
  return new RemovalListener<String, DFSClient>() {
    @Override
    public void onRemoval(RemovalNotification<String, DFSClient> notification) {
      DFSClient client = notification.getValue();
      try {
        client.close();
      } catch (IOException e) {
        LOG.warn(String.format(
            "IOException when closing the DFSClient(%s), cause: %s", client,
            e));
      }
    }
  };
}