下面列出了com.google.common.cache.RemovalNotification#getValue ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void onRemoval(RemovalNotification<Integer, StatementInfo> notification) {
Integer stmtId = notification.getKey();
StatementInfo doomed = notification.getValue();
if (doomed == null) {
// log/throw?
return;
}
LOGGER.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) {
LOGGER.info("Exception thrown while expiring statement {}", stmtId, t);
}
}
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
}
public void onRemoval(RemovalNotification<Integer, StatementInfo> notification) {
Integer stmtId = notification.getKey();
StatementInfo doomed = notification.getValue();
if (doomed == null) {
// log/throw?
return;
}
if (LOG.isDebugEnabled()) {
LOG.debug("Expiring statement " + stmtId + " because "
+ notification.getCause());
}
try {
if (doomed.resultSet != null) {
doomed.resultSet.close();
}
if (doomed.statement != null) {
doomed.statement.close();
}
} catch (Throwable t) {
LOG.info("Exception thrown while expiring statement " + stmtId);
}
}
@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);
}
}
}
@Inject
public MitmProxyManager(@Named("minPort") Integer minPort, @Named("maxPort") Integer maxPort, final @Named("ttl") Integer ttl) {
this.minPort = minPort;
this.maxPort = maxPort;
this.lastPort = maxPort;
if (ttl > 0) {
// proxies should be evicted after the specified ttl, so set up an evicting cache and a listener to stop the proxies when they're evicted
RemovalListener<Integer, MitmProxyServer> removalListener = new RemovalListener<Integer, MitmProxyServer>() {
public void onRemoval(RemovalNotification<Integer, MitmProxyServer> removal) {
try {
MitmProxyServer proxy = removal.getValue();
if (proxy != null) {
LOG.info("Expiring ProxyServer on port {} after {} seconds without activity", proxy.getPort(), ttl);
proxy.stop();
}
} catch (Exception ex) {
LOG.warn("Error while stopping an expired proxy on port " + removal.getKey(), ex);
}
}
};
this.proxyCache = CacheBuilder.newBuilder()
.expireAfterAccess(ttl, TimeUnit.SECONDS)
.removalListener(removalListener)
.build();
this.proxies = proxyCache.asMap();
// schedule the asynchronous proxy cleanup task
ScheduledExecutorHolder.expiredProxyCleanupExecutor.scheduleWithFixedDelay(new ProxyCleanupTask(proxyCache),
EXPIRED_PROXY_CLEANUP_INTERVAL_SECONDS, EXPIRED_PROXY_CLEANUP_INTERVAL_SECONDS, TimeUnit.SECONDS);
} else {
this.proxies = new ConcurrentHashMap<Integer, MitmProxyServer>();
// nothing to timeout, so no Cache
this.proxyCache = null;
}
}
public void onRemoval(RemovalNotification<String, Connection> notification) {
String connectionId = notification.getKey();
Connection doomed = notification.getValue();
LOGGER.debug("Expiring connection {} because {}", connectionId, notification.getCause());
try {
if (doomed != null) {
doomed.close();
}
} catch (Throwable t) {
LOGGER.info("Exception thrown while expiring connection {}", connectionId, t);
}
}
@Override
public void onRemoval(RemovalNotification<String, CuratorFramework> notification) {
logger.info("CuratorFramework for zkString " + notification.getKey() + " is removed due to "
+ notification.getCause());
CuratorFramework curator = notification.getValue();
try {
curator.close();
} catch (Exception ex) {
logger.error("Error at closing " + curator, ex);
}
}
public void onRemoval(RemovalNotification<String, DataStaxSessionWrapper> notification) {
DataStaxSessionWrapper session = notification.getValue();
Logger.debug("Closing [{}] (cause: {})...", session, notification.getCause());
if (session != null) {
try {
session.close();
} catch (Throwable t) {
Logger.debug(t, "Error occurred when closing session");
}
}
Logger.debug("Closed [{0}].", session);
}
@Override
public void onRemoval(RemovalNotification<UUID, CacheEntry> notification) {
CacheEntry entry = notification.getValue();
if(entry.isPresent()) {
stopExecutor(entry.getExecutor());
}
}
@Override
public void onRemoval(
RemovalNotification<Integer, SettableFuture<Response>> arg0) {
if (arg0.wasEvicted()) {
SettableFuture<Response> response = arg0.getValue();
logger.warn("request id {} timeout", arg0.getKey());
response.setException(new RequestTimeoutException("request timeout"));
}
}
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"));
});
}
}
}
private RemovalListener<String, TenantContext> createRemovalListener() {
return new RemovalListener<String, TenantContext>() {
@Override
public void onRemoval(final RemovalNotification<String, TenantContext> notification) {
final TenantContext tenantContext = notification.getValue();
// TenantContexts could be closeable - attempt closing it here
FileHelper.safeClose(tenantContext);
}
};
}
@Override
public void onRemoval(RemovalNotification<IndicesRequestCache.Key, IndicesRequestCache.Value> removalNotification) {
if (removalNotification.wasEvicted()) {
evictionsMetric.inc();
}
long dec = 0;
if (removalNotification.getKey() != null) {
dec += removalNotification.getKey().ramBytesUsed();
}
if (removalNotification.getValue() != null) {
dec += removalNotification.getValue().ramBytesUsed();
}
totalMetric.dec(dec);
}
/**
* Creates the removal listener which is attached to the cache.
*
* @return cache entry removal listener.
*/
private RemovalListener<String, FSFilterStreamContext> createCacheRemoveListener()
{
//When an entry is removed from the cache, removal listener is notified and it closes the output stream.
return new RemovalListener<String, FSFilterStreamContext>()
{
@Override
public void onRemoval(@Nonnull RemovalNotification<String, FSFilterStreamContext> notification)
{
FSFilterStreamContext streamContext = notification.getValue();
if (streamContext != null) {
try {
String filename = notification.getKey();
String partFileName = getPartFileNamePri(filename);
LOG.info("closing {}", partFileName);
long start = System.currentTimeMillis();
closeStream(streamContext);
filesWithOpenStreams.remove(filename);
totalWritingTime += System.currentTimeMillis() - start;
} catch (IOException e) {
LOG.error("removing {}", notification.getValue(), e);
throw new RuntimeException(e);
}
}
}
};
}
@Override
public void onRemoval(
RemovalNotification<StorageKey, DatasetWriter<E>> notification) {
DatasetWriter<E> writer = notification.getValue();
LOG.debug("Closing writer:{} for partition:{}", writer,
notification.getKey());
writer.close();
}
public void onRemoval(RemovalNotification<String, Connection> notification) {
String connectionId = notification.getKey();
Connection doomed = notification.getValue();
LOG.debug("Expiring connection {} because {}", connectionId, notification.getCause());
try {
if (doomed != null) {
doomed.close();
}
} catch (Throwable t) {
LOG.info("Exception thrown while expiring connection {}", connectionId, t);
}
}
/**
* Creates a RemovalListener that will close SimpleConsumer on cache removal.
*/
private RemovalListener<BrokerInfo, SimpleConsumer> createRemovalListener() {
return new RemovalListener<BrokerInfo, SimpleConsumer>() {
@Override
public void onRemoval(RemovalNotification<BrokerInfo, SimpleConsumer> notification) {
SimpleConsumer consumer = notification.getValue();
if (consumer != null) {
consumer.close();
}
}
};
}
@Override
public void onRemoval(RemovalNotification<String, Object[]> notification) {
String key = (String) notification.getValue()[1];
addTiming(maxTimeMSec, key);
}
private void graphDataCacheRemoved(RemovalNotification<Function, FcgData> notification) {
FcgData data = notification.getValue();
data.dispose();
}
private void onViewRemoved(final RemovalNotification<Object, Object> notification)
{
final IView view = (IView)notification.getValue();
logger.debug("View <" + view.getViewId() + "> removed from cache. Cause: " + notification.getCause());
view.afterDestroy();
}