use of org.apache.flink.shaded.guava30.com.google.common.cache.RemovalListener in project kylo by Teradata.
the class JobTrackerService method createCache.
/**
* Creates a job cache.
*/
@Nonnull
private Cache<String, Job<?>> createCache() {
final Cache<String, Job<?>> cache = CacheBuilder.newBuilder().expireAfterWrite(1, TimeUnit.HOURS).removalListener(new RemovalListener<String, Job<?>>() {
@Override
public void onRemoval(@Nonnull final RemovalNotification<String, Job<?>> notification) {
// noinspection ConstantConditions
final Optional<Integer> jobId = notification.getValue().getJobId();
if (jobId.isPresent()) {
jobs.remove(jobId.get());
}
for (final StageInfo stage : notification.getValue().getStages()) {
stages.remove(stage.stageId());
}
// TODO remove temp table
}
}).build();
// Schedule clean-up of groups
executor.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
groups.cleanUp();
}
}, 1, 1, TimeUnit.HOURS);
return cache;
}
use of org.apache.flink.shaded.guava30.com.google.common.cache.RemovalListener in project java-chassis by ServiceComb.
the class ServiceCombLoadBalancerStats method init.
void init() {
// for testing
if (timer != null) {
timer.cancel();
}
if (serverStatsCache != null) {
serverStatsCache.cleanUp();
}
pingView.clear();
serverStatsCache = CacheBuilder.newBuilder().expireAfterAccess(serverExpireInSeconds, TimeUnit.SECONDS).removalListener((RemovalListener<ServiceCombServer, ServiceCombServerStats>) notification -> {
ServiceCombServer server = notification.getKey();
LOGGER.info("stats of instance {} removed, host is {}", server.getInstance().getInstanceId(), server.getHost());
pingView.remove(notification.getKey());
serviceCombServers.remove(notification.getKey());
}).build(new CacheLoader<ServiceCombServer, ServiceCombServerStats>() {
public ServiceCombServerStats load(ServiceCombServer server) {
ServiceCombServerStats stats = new ServiceCombServerStats(server.getMicroserviceName());
pingView.put(server, stats);
serviceCombServers.put(server.getInstance().getInstanceId(), server);
return stats;
}
});
timer = new Timer("LoadBalancerStatsTimer", true);
timer.schedule(new TimerTask() {
private MicroserviceInstancePing ping = SPIServiceUtils.getPriorityHighestService(MicroserviceInstancePing.class);
@Override
public void run() {
try {
Map<ServiceCombServer, ServiceCombServerStats> allServers = pingView;
allServers.entrySet().forEach(serviceCombServerServiceCombServerStatsEntry -> {
ServiceCombServer server = serviceCombServerServiceCombServerStatsEntry.getKey();
ServiceCombServerStats stats = serviceCombServerServiceCombServerStatsEntry.getValue();
if ((System.currentTimeMillis() - stats.getLastVisitTime() > timerIntervalInMillis) && !ping.ping(server.getInstance())) {
LOGGER.info("ping mark server {} failure.", server.getInstance().getInstanceId());
stats.markFailure();
}
});
serverStatsCache.cleanUp();
} catch (Throwable e) {
LOGGER.warn("LoadBalancerStatsTimer error.", e);
}
}
}, timerIntervalInMillis, timerIntervalInMillis);
}
use of org.apache.flink.shaded.guava30.com.google.common.cache.RemovalListener in project incubator-servicecomb-java-chassis by apache.
the class ServiceCombLoadBalancerStats method init.
void init() {
// for testing
if (timer != null) {
timer.cancel();
}
if (serverStatsCache != null) {
serverStatsCache.cleanUp();
}
pingView.clear();
serverStatsCache = CacheBuilder.newBuilder().expireAfterAccess(serverExpireInSeconds, TimeUnit.SECONDS).removalListener((RemovalListener<ServiceCombServer, ServiceCombServerStats>) notification -> {
ServiceCombServer server = notification.getKey();
LOGGER.info("stats of instance {} removed, host is {}", server.getInstance().getInstanceId(), server.getHost());
pingView.remove(notification.getKey());
serviceCombServers.remove(notification.getKey());
}).build(new CacheLoader<ServiceCombServer, ServiceCombServerStats>() {
public ServiceCombServerStats load(ServiceCombServer server) {
ServiceCombServerStats stats = new ServiceCombServerStats(server.getMicroserviceName());
pingView.put(server, stats);
serviceCombServers.put(server.getInstance().getInstanceId(), server);
return stats;
}
});
timer = new Timer("LoadBalancerStatsTimer", true);
timer.schedule(new TimerTask() {
private MicroserviceInstancePing ping = SPIServiceUtils.getPriorityHighestService(MicroserviceInstancePing.class);
@Override
public void run() {
try {
Map<ServiceCombServer, ServiceCombServerStats> allServers = pingView;
allServers.entrySet().forEach(serviceCombServerServiceCombServerStatsEntry -> {
ServiceCombServer server = serviceCombServerServiceCombServerStatsEntry.getKey();
ServiceCombServerStats stats = serviceCombServerServiceCombServerStatsEntry.getValue();
if ((System.currentTimeMillis() - stats.getLastVisitTime() > timerIntervalInMillis) && !ping.ping(server.getInstance())) {
LOGGER.info("ping mark server {} failure.", server.getInstance().getInstanceId());
stats.markFailure();
}
});
serverStatsCache.cleanUp();
} catch (Throwable e) {
LOGGER.warn("LoadBalancerStatsTimer error.", e);
}
}
}, timerIntervalInMillis, timerIntervalInMillis);
}
Aggregations