org.apache.flink.shaded.guava18.com.google.common.cache.RemovalListener Java Examples

The following examples show how to use org.apache.flink.shaded.guava18.com.google.common.cache.RemovalListener. 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: CompletedOperationCache.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
CompletedOperationCache(final Ticker ticker) {
	completedOperations = CacheBuilder.newBuilder()
		.expireAfterWrite(COMPLETED_OPERATION_RESULT_CACHE_DURATION_SECONDS, TimeUnit.SECONDS)
		.removalListener((RemovalListener<K, ResultAccessTracker<R>>) removalNotification -> {
			if (removalNotification.wasEvicted()) {
				Preconditions.checkState(removalNotification.getKey() != null);
				Preconditions.checkState(removalNotification.getValue() != null);

				// When shutting down the cache, we wait until all results are accessed.
				// When a result gets evicted from the cache, it will not be possible to access
				// it any longer, and we might be in the process of shutting down, so we mark
				// the result as accessed to avoid waiting indefinitely.
				removalNotification.getValue().markAccessed();

				LOGGER.info("Evicted result with trigger id {} because its TTL of {}s has expired.",
					removalNotification.getKey().getTriggerId(),
					COMPLETED_OPERATION_RESULT_CACHE_DURATION_SECONDS);
			}
		})
		.ticker(ticker)
		.build();
}
 
Example #2
Source File: CompletedOperationCache.java    From flink with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
CompletedOperationCache(final Ticker ticker) {
	completedOperations = CacheBuilder.newBuilder()
		.expireAfterWrite(COMPLETED_OPERATION_RESULT_CACHE_DURATION_SECONDS, TimeUnit.SECONDS)
		.removalListener((RemovalListener<K, ResultAccessTracker<R>>) removalNotification -> {
			if (removalNotification.wasEvicted()) {
				Preconditions.checkState(removalNotification.getKey() != null);
				Preconditions.checkState(removalNotification.getValue() != null);

				// When shutting down the cache, we wait until all results are accessed.
				// When a result gets evicted from the cache, it will not be possible to access
				// it any longer, and we might be in the process of shutting down, so we mark
				// the result as accessed to avoid waiting indefinitely.
				removalNotification.getValue().markAccessed();

				LOGGER.info("Evicted result with trigger id {} because its TTL of {}s has expired.",
					removalNotification.getKey().getTriggerId(),
					COMPLETED_OPERATION_RESULT_CACHE_DURATION_SECONDS);
			}
		})
		.ticker(ticker)
		.build();
}
 
Example #3
Source File: CompletedOperationCache.java    From flink with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
CompletedOperationCache(final Ticker ticker) {
	completedOperations = CacheBuilder.newBuilder()
		.expireAfterWrite(COMPLETED_OPERATION_RESULT_CACHE_DURATION_SECONDS, TimeUnit.SECONDS)
		.removalListener((RemovalListener<K, ResultAccessTracker<R>>) removalNotification -> {
			if (removalNotification.wasEvicted()) {
				Preconditions.checkState(removalNotification.getKey() != null);
				Preconditions.checkState(removalNotification.getValue() != null);

				// When shutting down the cache, we wait until all results are accessed.
				// When a result gets evicted from the cache, it will not be possible to access
				// it any longer, and we might be in the process of shutting down, so we mark
				// the result as accessed to avoid waiting indefinitely.
				removalNotification.getValue().markAccessed();

				LOGGER.info("Evicted result with trigger id {} because its TTL of {}s has expired.",
					removalNotification.getKey().getTriggerId(),
					COMPLETED_OPERATION_RESULT_CACHE_DURATION_SECONDS);
			}
		})
		.ticker(ticker)
		.build();
}
 
Example #4
Source File: FileArchivedExecutionGraphStore.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
public FileArchivedExecutionGraphStore(
		File rootDir,
		Time expirationTime,
		long maximumCacheSizeBytes,
		ScheduledExecutor scheduledExecutor,
		Ticker ticker) throws IOException {

	final File storageDirectory = initExecutionGraphStorageDirectory(rootDir);

	LOG.info(
		"Initializing {}: Storage directory {}, expiration time {}, maximum cache size {} bytes.",
		FileArchivedExecutionGraphStore.class.getSimpleName(),
		storageDirectory,
		expirationTime.toMilliseconds(),
		maximumCacheSizeBytes);

	this.storageDir = Preconditions.checkNotNull(storageDirectory);
	Preconditions.checkArgument(
		storageDirectory.exists() && storageDirectory.isDirectory(),
		"The storage directory must exist and be a directory.");
	this.jobDetailsCache = CacheBuilder.newBuilder()
		.expireAfterWrite(expirationTime.toMilliseconds(), TimeUnit.MILLISECONDS)
		.removalListener(
			(RemovalListener<JobID, JobDetails>) notification -> deleteExecutionGraphFile(notification.getKey()))
		.ticker(ticker)
		.build();

	this.archivedExecutionGraphCache = CacheBuilder.newBuilder()
		.maximumWeight(maximumCacheSizeBytes)
		.weigher(this::calculateSize)
		.build(new CacheLoader<JobID, ArchivedExecutionGraph>() {
			@Override
			public ArchivedExecutionGraph load(JobID jobId) throws Exception {
				return loadExecutionGraph(jobId);
			}});

	this.cleanupFuture = scheduledExecutor.scheduleWithFixedDelay(
		jobDetailsCache::cleanUp,
		expirationTime.toMilliseconds(),
		expirationTime.toMilliseconds(),
		TimeUnit.MILLISECONDS);

	this.shutdownHook = ShutdownHookUtil.addShutdownHook(this, getClass().getSimpleName(), LOG);

	this.numFinishedJobs = 0;
	this.numFailedJobs = 0;
	this.numCanceledJobs = 0;
}
 
Example #5
Source File: FileArchivedExecutionGraphStore.java    From flink with Apache License 2.0 4 votes vote down vote up
public FileArchivedExecutionGraphStore(
		File rootDir,
		Time expirationTime,
		long maximumCacheSizeBytes,
		ScheduledExecutor scheduledExecutor,
		Ticker ticker) throws IOException {

	final File storageDirectory = initExecutionGraphStorageDirectory(rootDir);

	LOG.info(
		"Initializing {}: Storage directory {}, expiration time {}, maximum cache size {} bytes.",
		FileArchivedExecutionGraphStore.class.getSimpleName(),
		storageDirectory,
		expirationTime.toMilliseconds(),
		maximumCacheSizeBytes);

	this.storageDir = Preconditions.checkNotNull(storageDirectory);
	Preconditions.checkArgument(
		storageDirectory.exists() && storageDirectory.isDirectory(),
		"The storage directory must exist and be a directory.");
	this.jobDetailsCache = CacheBuilder.newBuilder()
		.expireAfterWrite(expirationTime.toMilliseconds(), TimeUnit.MILLISECONDS)
		.removalListener(
			(RemovalListener<JobID, JobDetails>) notification -> deleteExecutionGraphFile(notification.getKey()))
		.ticker(ticker)
		.build();

	this.archivedExecutionGraphCache = CacheBuilder.newBuilder()
		.maximumWeight(maximumCacheSizeBytes)
		.weigher(this::calculateSize)
		.build(new CacheLoader<JobID, ArchivedExecutionGraph>() {
			@Override
			public ArchivedExecutionGraph load(JobID jobId) throws Exception {
				return loadExecutionGraph(jobId);
			}});

	this.cleanupFuture = scheduledExecutor.scheduleWithFixedDelay(
		jobDetailsCache::cleanUp,
		expirationTime.toMilliseconds(),
		expirationTime.toMilliseconds(),
		TimeUnit.MILLISECONDS);

	this.shutdownHook = ShutdownHookUtil.addShutdownHook(this, getClass().getSimpleName(), LOG);

	this.numFinishedJobs = 0;
	this.numFailedJobs = 0;
	this.numCanceledJobs = 0;
}
 
Example #6
Source File: FileArchivedExecutionGraphStore.java    From flink with Apache License 2.0 4 votes vote down vote up
public FileArchivedExecutionGraphStore(
		File rootDir,
		Time expirationTime,
		int maximumCapacity,
		long maximumCacheSizeBytes,
		ScheduledExecutor scheduledExecutor,
		Ticker ticker) throws IOException {

	final File storageDirectory = initExecutionGraphStorageDirectory(rootDir);

	LOG.info(
		"Initializing {}: Storage directory {}, expiration time {}, maximum cache size {} bytes.",
		FileArchivedExecutionGraphStore.class.getSimpleName(),
		storageDirectory,
		expirationTime.toMilliseconds(),
		maximumCacheSizeBytes);

	this.storageDir = Preconditions.checkNotNull(storageDirectory);
	Preconditions.checkArgument(
		storageDirectory.exists() && storageDirectory.isDirectory(),
		"The storage directory must exist and be a directory.");
	this.jobDetailsCache = CacheBuilder.newBuilder()
		.expireAfterWrite(expirationTime.toMilliseconds(), TimeUnit.MILLISECONDS)
		.maximumSize(maximumCapacity)
		.removalListener(
			(RemovalListener<JobID, JobDetails>) notification -> deleteExecutionGraphFile(notification.getKey()))
		.ticker(ticker)
		.build();

	this.archivedExecutionGraphCache = CacheBuilder.newBuilder()
		.maximumWeight(maximumCacheSizeBytes)
		.weigher(this::calculateSize)
		.build(new CacheLoader<JobID, ArchivedExecutionGraph>() {
			@Override
			public ArchivedExecutionGraph load(JobID jobId) throws Exception {
				return loadExecutionGraph(jobId);
			}});

	this.cleanupFuture = scheduledExecutor.scheduleWithFixedDelay(
		jobDetailsCache::cleanUp,
		expirationTime.toMilliseconds(),
		expirationTime.toMilliseconds(),
		TimeUnit.MILLISECONDS);

	this.shutdownHook = ShutdownHookUtil.addShutdownHook(this, getClass().getSimpleName(), LOG);

	this.numFinishedJobs = 0;
	this.numFailedJobs = 0;
	this.numCanceledJobs = 0;
}