keycloakjar.com.github.benmanes.caffeine.cache.LocalAsyncLoadingCache Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of camunda-platform-7-keycloak-all Show documentation
Show all versions of camunda-platform-7-keycloak-all Show documentation
Camunda 7 Keycloak Identity Provider Plugin including all transitive dependencies
/*
* Copyright 2015 Ben Manes. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.benmanes.caffeine.cache;
import static java.util.Objects.requireNonNull;
import java.lang.reflect.Method;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.CancellationException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeoutException;
import java.util.function.Function;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* This class provides a skeletal implementation of the {@link AsyncLoadingCache} interface to
* minimize the effort required to implement a {@link LocalCache}.
*
* @author [email protected] (Ben Manes)
*/
abstract class LocalAsyncLoadingCache
implements LocalAsyncCache, AsyncLoadingCache {
static final Logger logger = Logger.getLogger(LocalAsyncLoadingCache.class.getName());
final boolean canBulkLoad;
final AsyncCacheLoader loader;
@Nullable LoadingCacheView cacheView;
@SuppressWarnings("unchecked")
LocalAsyncLoadingCache(AsyncCacheLoader super K, V> loader) {
this.loader = (AsyncCacheLoader) loader;
this.canBulkLoad = canBulkLoad(loader);
}
/** Returns whether the supplied cache loader has bulk load functionality. */
private static boolean canBulkLoad(AsyncCacheLoader, ?> loader) {
try {
Class> defaultLoaderClass = AsyncCacheLoader.class;
if (loader instanceof CacheLoader, ?>) {
defaultLoaderClass = CacheLoader.class;
Method classLoadAll = loader.getClass().getMethod("loadAll", Iterable.class);
Method defaultLoadAll = CacheLoader.class.getMethod("loadAll", Iterable.class);
if (!classLoadAll.equals(defaultLoadAll)) {
return true;
}
}
Method classAsyncLoadAll = loader.getClass().getMethod(
"asyncLoadAll", Iterable.class, Executor.class);
Method defaultAsyncLoadAll = defaultLoaderClass.getMethod(
"asyncLoadAll", Iterable.class, Executor.class);
return !classAsyncLoadAll.equals(defaultAsyncLoadAll);
} catch (NoSuchMethodException | SecurityException e) {
logger.log(Level.WARNING, "Cannot determine if CacheLoader can bulk load", e);
return false;
}
}
@Override
public CompletableFuture get(K key) {
return get(key, loader::asyncLoad);
}
@Override
public CompletableFuture