Refine search
public TableNameCompleter(QueryRunner queryRunner) { this.queryRunner = requireNonNull(queryRunner, "queryRunner session was null!"); tableCache = CacheBuilder.newBuilder() .refreshAfterWrite(RELOAD_TIME_MINUTES, TimeUnit.MINUTES) .build(asyncReloading(CacheLoader.from(this::listTables), executor)); functionCache = CacheBuilder.newBuilder() .build(asyncReloading(CacheLoader.from(this::listFunctions), executor)); }
@Override public Map<K, V> loadAll(Iterable<? extends K> keys) throws Exception { return loader.loadAll(keys); } };
private CachingHiveMetastore(ExtendedHiveMetastore delegate, ExecutorService executor, OptionalLong expiresAfterWriteMillis, OptionalLong refreshMills, long maximumSize) this.delegate = requireNonNull(delegate, "delegate is null"); requireNonNull(executor, "executor is null"); .build(asyncReloading(CacheLoader.from(this::loadAllDatabases), executor)); .build(asyncReloading(CacheLoader.from(this::loadDatabase), executor)); .build(asyncReloading(CacheLoader.from(this::loadAllTables), executor)); .build(asyncReloading(new CacheLoader<HiveTableName, PartitionStatistics>() .build(asyncReloading(new CacheLoader<HivePartitionName, PartitionStatistics>() .build(asyncReloading(CacheLoader.from(this::loadTable), executor)); .build(asyncReloading(CacheLoader.from(this::loadAllViews), executor)); .build(asyncReloading(CacheLoader.from(this::loadPartitionNames), executor)); .build(asyncReloading(CacheLoader.from(this::loadPartitionNamesByParts), executor)); .build(asyncReloading(new CacheLoader<HivePartitionName, Optional<Partition>>() .build(asyncReloading(CacheLoader.from(this::loadRoles), executor)); .build(asyncReloading(CacheLoader.from(key -> loadTablePrivileges(key.getUser(), key.getDatabase(), key.getTable())), executor));
cache = CacheBuilder.newBuilder() .maximumSize(cacheConfig.getSize()) .build(CacheLoader.from(CachingAsyncAtomicMultimap.super::get)); cacheUpdater = event -> { V oldValue = event.oldValue(); cache.put(event.key(), CompletableFuture.completedFuture(new Versioned<>(oldVersioned.value() .stream() .filter(value -> !Objects.equals(value, oldValue)) .collect(Collectors.toSet()), oldVersioned.version(), oldVersioned.creationTime()))); } else { cache.put(event.key(), future.thenApply(versioned -> new Versioned<>(versioned.value() .stream() .filter(value -> !Objects.equals(value, oldValue)) .collect(Collectors.toSet()), versioned.version(), versioned.creationTime())));
/** * converts a map to a loading cache. */ public static <K, V> LoadingCache<K, V> convertMapToLoadingCache(Map<K, V> in) { return CacheBuilder.newBuilder().build(CacheLoader.from(Functions.forMap(in))); }
public ObservableCachingLayout(Layout<V, E> delegate) { super(delegate); Function<V, Point2D> chain = Functions.<V, Point2D, Point2D> compose( new Function<Point2D, Point2D>() { public Point2D apply(Point2D p) { return (Point2D) p.clone(); } }, delegate); this.locations = CacheBuilder.newBuilder().build(CacheLoader.from(chain)); }
public V get(K key) throws ExecutionException { Objects.requireNonNull(key); if (config.isEnabled()) { return delegate.get(key); } try { return cacheLoader.load(key); } catch (Throwable t) { throw new RuntimeException(t); } }
@Inject public GrokPatternRegistry(EventBus serverEventBus, GrokPatternService grokPatternService, @Named("daemonScheduler") ScheduledExecutorService daemonExecutor) { this.grokPatternService = grokPatternService; grokCache = CacheBuilder.newBuilder() .expireAfterAccess(1, TimeUnit.MINUTES) // prevent from hanging on to memory forever .build(asyncReloading(new GrokReloader(false), daemonExecutor)); grokCacheNamedOnly = CacheBuilder.newBuilder() .expireAfterAccess(1, TimeUnit.MINUTES) // prevent from hanging on to memory forever .build(asyncReloading(new GrokReloader(true), daemonExecutor)); // trigger initial loading reload(); serverEventBus.register(this); }
@VisibleForTesting static Comparator<ActualProperties> streamingExecutionPreference(PreferredProperties preferred) { // Calculating the matches can be a bit expensive, so cache the results between comparisons LoadingCache<List<LocalProperty<Symbol>>, List<Optional<LocalProperty<Symbol>>>> matchCache = CacheBuilder.newBuilder() .build(CacheLoader.from(actualProperties -> LocalProperties.match(actualProperties, preferred.getLocalProperties()))); return (actual1, actual2) -> { List<Optional<LocalProperty<Symbol>>> matchLayout1 = matchCache.getUnchecked(actual1.getLocalProperties()); List<Optional<LocalProperty<Symbol>>> matchLayout2 = matchCache.getUnchecked(actual2.getLocalProperties()); return ComparisonChain.start() .compareTrueFirst(hasLocalOptimization(preferred.getLocalProperties(), matchLayout1), hasLocalOptimization(preferred.getLocalProperties(), matchLayout2)) .compareTrueFirst(meetsPartitioningRequirements(preferred, actual1), meetsPartitioningRequirements(preferred, actual2)) .compare(matchLayout1, matchLayout2, matchedLayoutPreference()) .result(); }; }
public <K, V> LoadingCache<K, V> build(CacheLoader<K, V> loader) { LoadingCache<K, V> cache; if (isCaffeine()) { cache = isAsync() ? caffeine.buildAsync(loader).synchronous() : caffeine.build(loader); } else { cache = new GuavaLoadingCache<>(guava.build( com.google.common.cache.CacheLoader.asyncReloading( new SingleLoader<>(loader), executor)), ticker, isRecordingStats()); } this.cache = cache; return cache; }
@SuppressWarnings("unchecked") @Override protected void bindCacheLoaders() { bind(new TypeLiteral<CacheLoader<URI, VAppTemplate>>() { }).toInstance(CacheLoader.class.cast(CacheLoader.from(Functions.constant(VAppTemplateHandlerTest.parseTemplate())))); bind(new TypeLiteral<CacheLoader<URI, Envelope>>() { }).toInstance(CacheLoader.class.cast(CacheLoader.from(Functions.constant(EnvelopeHandlerTest.parseEnvelope())))); }
assertEquals(0, loadAllCount.get()); baseLoader.load(new Object()); @SuppressWarnings("unused") // go/futurereturn-lsc Future<?> possiblyIgnoredError = baseLoader.reload(new Object(), new Object()); baseLoader.loadAll(ImmutableList.of(new Object())); assertEquals(1, loadCount.get()); assertEquals(1, reloadCount.get()); CacheLoader<Object, Object> asyncReloader = CacheLoader.asyncReloading(baseLoader, executor); asyncReloader.load(new Object()); @SuppressWarnings("unused") // go/futurereturn-lsc Future<?> possiblyIgnoredError1 = asyncReloader.reload(new Object(), new Object()); asyncReloader.loadAll(ImmutableList.of(new Object())); assertEquals(2, loadCount.get()); assertEquals(1, reloadCount.get());
@Override public V load(K key) throws Exception { return loader.load(key); }
@Override public V reload(K key, V oldValue) { try { V value = Futures.getUnchecked(cacheLoader.reload(key, oldValue)); if (value == null) { throw new InvalidCacheLoadException("null value"); } return value; } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new CacheLoaderException(e); } catch (Exception e) { Throwables.throwIfUnchecked(e); throw new RuntimeException(e); } } }
public CacheNodeStoreModule(Map<String, Node> backing) { this(CacheBuilder.newBuilder().<String, Node>build(CacheLoader.from(Functions.forMap(backing)))); for (String node : backing.keySet()) this.backing.getUnchecked(node); }
public CachingLayout(Layout<V, E> delegate) { super(delegate); Function<V, Point2D> chain = Functions.<V,Point2D,Point2D>compose( new Function<Point2D,Point2D>() { public Point2D apply(Point2D p) { return (Point2D)p.clone(); }}, delegate); this.locations = CacheBuilder.newBuilder().build(CacheLoader.from(chain)); }
@Inject public GrokPatternRegistry(EventBus serverEventBus, GrokPatternService grokPatternService, @Named("daemonScheduler") ScheduledExecutorService daemonExecutor) { this.grokPatternService = grokPatternService; grokCache = CacheBuilder.newBuilder() .expireAfterAccess(1, TimeUnit.MINUTES) // prevent from hanging on to memory forever .build(asyncReloading(new GrokReloader(false), daemonExecutor)); grokCacheNamedOnly = CacheBuilder.newBuilder() .expireAfterAccess(1, TimeUnit.MINUTES) // prevent from hanging on to memory forever .build(asyncReloading(new GrokReloader(true), daemonExecutor)); // trigger initial loading reload(); serverEventBus.register(this); }