Java Code Examples for com.google.common.cache.RemovalNotification#getValue()

The following examples show how to use com.google.common.cache.RemovalNotification#getValue() . 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: QuarkMetaImpl.java    From quark 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;
  }
  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);
  }
}
 
Example 2
Source File: QuicksqlServerMeta.java    From Quicksql with MIT License 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;
    }
    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);
    }
}
 
Example 3
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 4
Source File: NettyPistachioClientHandler.java    From Pistachio with Apache License 2.0 5 votes vote down vote up
@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"));
    }
}
 
Example 5
Source File: SimpleKafkaConsumer.java    From twill with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
      }
    }
  };
}
 
Example 6
Source File: JdbcMeta.java    From calcite-avatica with Apache License 2.0 5 votes vote down vote up
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);
  }
}
 
Example 7
Source File: PartitionedDatasetWriter.java    From kite with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 8
Source File: AbstractFileOutputOperator.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
        }
      }
    }
  };
}
 
Example 9
Source File: ShardRequestCache.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 10
Source File: CachedTenantRegistryWrapper.java    From metamodel-membrane with Apache License 2.0 5 votes vote down vote up
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);
        }
    };
}
 
Example 11
Source File: SingleChannelPublisher.java    From rxrabbit with MIT License 5 votes vote down vote up
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"));
            });
        }
    }
}
 
Example 12
Source File: JavaSourceLoader.java    From meghanada-server with GNU General Public License v3.0 5 votes vote down vote up
@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);
    }
  }
}
 
Example 13
Source File: DefaultPlaceExecutorRegistry.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Override
public void onRemoval(RemovalNotification<UUID, CacheEntry> notification) {
   CacheEntry entry = notification.getValue();
   if(entry.isPresent()) {
      stopExecutor(entry.getExecutor());
   }
}
 
Example 14
Source File: DataStaxSessionFactory.java    From cassandra-jdbc-driver with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 15
Source File: ZKUtil.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example 16
Source File: QuicksqlServerMeta.java    From Quicksql with MIT License 5 votes vote down vote up
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);
    }
}
 
Example 17
Source File: MitmProxyManager.java    From browserup-proxy with Apache License 2.0 5 votes vote down vote up
@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;
    }
}
 
Example 18
Source File: FcgProvider.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private void graphDataCacheRemoved(RemovalNotification<Function, FcgData> notification) {
	FcgData data = notification.getValue();
	data.dispose();
}
 
Example 19
Source File: DefaultViewsRepositoryStorage.java    From metasfresh-webui-api-legacy with GNU General Public License v3.0 4 votes vote down vote up
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();
}
 
Example 20
Source File: SchedulingURLBuffer.java    From storm-crawler with Apache License 2.0 4 votes vote down vote up
@Override
public void onRemoval(RemovalNotification<String, Object[]> notification) {
    String key = (String) notification.getValue()[1];
    addTiming(maxTimeMSec, key);
}