List of usage examples for com.google.common.cache RemovalCause COLLECTED
RemovalCause COLLECTED
To view the source code for com.google.common.cache RemovalCause COLLECTED.
Click Source Link
From source file:com.infinities.skyport.distributed.impl.hazelcast.hazeltask.executor.DistributedFutureTracker.java
public DistributedFutureTracker(final IExecutorTopologyService topologyService, long maxFutureWaitTime, TimeUnit unit) {//from w w w . j a v a2s .com this.topologyService = topologyService; futures = CacheBuilder.newBuilder() // no future will wait for more than this time .expireAfterAccess(maxFutureWaitTime, unit) .removalListener(new RemovalListener<String, DistributedFuture<Object>>() { @Override public void onRemoval(RemovalNotification<String, DistributedFuture<Object>> notification) { if (notification.getCause() == RemovalCause.EXPIRED) { DistributedFuture<Object> future = notification.getValue(); long waitTimeMillis = System.currentTimeMillis() - future.getCreatedTime(); notification.getValue() .setException(new TimeoutException("Future timed out waiting. Waited " + (TimeUnit.MILLISECONDS.toMinutes(waitTimeMillis)) + " minutes")); topologyService.cancelTask(future.getTaskId()); topologyService.removePendingTask(future.getTaskId()); } else if (notification.getCause() == RemovalCause.COLLECTED) { // future was GC'd because we didn't // want to track it logger.debug("Future {} was garabge collected and removed from the tracker", notification.getKey()); } } }).build(); }