Search in sources :

Example 1 with LoadingCache

use of com.google.common.cache.LoadingCache in project buck by facebook.

the class HaskellPrebuiltLibraryDescription method createBuildRule.

@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, final A args) throws NoSuchBuildTargetException {
    return new PrebuiltHaskellLibrary(params) {

        private final LoadingCache<CxxPreprocessables.CxxPreprocessorInputCacheKey, ImmutableMap<BuildTarget, CxxPreprocessorInput>> transitiveCxxPreprocessorInputCache = CxxPreprocessables.getTransitiveCxxPreprocessorInputCache(this);

        @Override
        public HaskellCompileInput getCompileInput(CxxPlatform cxxPlatform, Linker.LinkableDepType depType) throws NoSuchBuildTargetException {
            return HaskellCompileInput.builder().addAllFlags(args.exportedCompilerFlags).addPackages(HaskellPackage.builder().setInfo(HaskellPackageInfo.of(getBuildTarget().getShortName(), args.version, args.id.orElse(String.format("%s-%s", getBuildTarget().getShortName(), args.version)))).setPackageDb(args.db).addAllInterfaces(args.importDirs).addAllLibraries(depType == Linker.LinkableDepType.SHARED ? args.sharedLibs.values() : args.staticLibs).build()).build();
        }

        @Override
        public Iterable<? extends NativeLinkable> getNativeLinkableDeps() {
            return ImmutableList.of();
        }

        @Override
        public Iterable<? extends NativeLinkable> getNativeLinkableExportedDeps() {
            return FluentIterable.from(getDeclaredDeps()).filter(NativeLinkable.class);
        }

        @Override
        public NativeLinkableInput getNativeLinkableInput(CxxPlatform cxxPlatform, Linker.LinkableDepType type) {
            NativeLinkableInput.Builder builder = NativeLinkableInput.builder();
            builder.addAllArgs(StringArg.from(args.exportedLinkerFlags));
            if (type == Linker.LinkableDepType.SHARED) {
                builder.addAllArgs(SourcePathArg.from(args.sharedLibs.values()));
            } else {
                builder.addAllArgs(SourcePathArg.from(args.staticLibs));
            }
            return builder.build();
        }

        @Override
        public Linkage getPreferredLinkage(CxxPlatform cxxPlatform) {
            return Linkage.ANY;
        }

        @Override
        public ImmutableMap<String, SourcePath> getSharedLibraries(CxxPlatform cxxPlatform) {
            return args.sharedLibs;
        }

        @Override
        public Iterable<? extends CxxPreprocessorDep> getCxxPreprocessorDeps(CxxPlatform cxxPlatform) {
            return FluentIterable.from(getDeps()).filter(CxxPreprocessorDep.class);
        }

        @Override
        public Optional<HeaderSymlinkTree> getExportedHeaderSymlinkTree(CxxPlatform cxxPlatform) {
            return Optional.empty();
        }

        @Override
        public CxxPreprocessorInput getCxxPreprocessorInput(CxxPlatform cxxPlatform, HeaderVisibility headerVisibility) throws NoSuchBuildTargetException {
            CxxPreprocessorInput.Builder builder = CxxPreprocessorInput.builder();
            for (SourcePath headerDir : args.cxxHeaderDirs) {
                builder.addIncludes(CxxHeadersDir.of(CxxPreprocessables.IncludeType.SYSTEM, headerDir));
            }
            return builder.build();
        }

        @Override
        public ImmutableMap<BuildTarget, CxxPreprocessorInput> getTransitiveCxxPreprocessorInput(CxxPlatform cxxPlatform, HeaderVisibility headerVisibility) throws NoSuchBuildTargetException {
            return transitiveCxxPreprocessorInputCache.getUnchecked(ImmutableCxxPreprocessorInputCacheKey.of(cxxPlatform, headerVisibility));
        }
    };
}
Also used : HeaderSymlinkTree(com.facebook.buck.cxx.HeaderSymlinkTree) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) SourcePath(com.facebook.buck.rules.SourcePath) NativeLinkableInput(com.facebook.buck.cxx.NativeLinkableInput) CxxPreprocessables(com.facebook.buck.cxx.CxxPreprocessables) BuildTarget(com.facebook.buck.model.BuildTarget) LoadingCache(com.google.common.cache.LoadingCache) CxxPreprocessorInput(com.facebook.buck.cxx.CxxPreprocessorInput) HeaderVisibility(com.facebook.buck.cxx.HeaderVisibility)

Example 2 with LoadingCache

use of com.google.common.cache.LoadingCache in project pinot by linkedin.

the class ThirdEyeCacheRegistry method initCaches.

private static void initCaches(ThirdEyeConfiguration config) {
    ThirdEyeCacheRegistry cacheRegistry = ThirdEyeCacheRegistry.getInstance();
    RemovalListener<PinotQuery, ResultSetGroup> listener = new RemovalListener<PinotQuery, ResultSetGroup>() {

        @Override
        public void onRemoval(RemovalNotification<PinotQuery, ResultSetGroup> notification) {
            LOGGER.info("Expired {}", notification.getKey().getPql());
        }
    };
    // ResultSetGroup Cache. The size of this cache is limited by the total number of buckets in all ResultSetGroup.
    // We estimate that 1 bucket (including overhead) consumes 1KB and this cache is allowed to use up to 50% of max
    // heap space.
    long maxBucketNumber = getApproximateMaxBucketNumber(DEFAULT_HEAP_PERCENTAGE_FOR_RESULTSETGROUP_CACHE);
    LoadingCache<PinotQuery, ResultSetGroup> resultSetGroupCache = CacheBuilder.newBuilder().removalListener(listener).expireAfterAccess(1, TimeUnit.HOURS).maximumWeight(maxBucketNumber).weigher((pinotQuery, resultSetGroup) -> {
        int resultSetCount = resultSetGroup.getResultSetCount();
        int weight = 0;
        for (int idx = 0; idx < resultSetCount; ++idx) {
            com.linkedin.pinot.client.ResultSet resultSet = resultSetGroup.getResultSet(idx);
            weight += (resultSet.getColumnCount() * resultSet.getRowCount());
        }
        return weight;
    }).build(new ResultSetGroupCacheLoader(pinotThirdeyeClientConfig));
    cacheRegistry.registerResultSetGroupCache(resultSetGroupCache);
    LOGGER.info("Max bucket number for ResultSetGroup cache is set to {}", maxBucketNumber);
    // CollectionMaxDataTime Cache
    LoadingCache<String, Long> collectionMaxDataTimeCache = CacheBuilder.newBuilder().refreshAfterWrite(5, TimeUnit.MINUTES).build(new CollectionMaxDataTimeCacheLoader(resultSetGroupCache, datasetConfigDAO));
    cacheRegistry.registerCollectionMaxDataTimeCache(collectionMaxDataTimeCache);
    // Query Cache
    QueryCache queryCache = new QueryCache(thirdEyeClient, Executors.newFixedThreadPool(10));
    cacheRegistry.registerQueryCache(queryCache);
    // Dimension Filter cache
    LoadingCache<String, String> dimensionFiltersCache = CacheBuilder.newBuilder().build(new DimensionFiltersCacheLoader(cacheRegistry.getQueryCache()));
    cacheRegistry.registerDimensionFiltersCache(dimensionFiltersCache);
    // Dashboards cache
    LoadingCache<String, String> dashboardsCache = CacheBuilder.newBuilder().build(new DashboardsCacheLoader(dashboardConfigDAO));
    cacheRegistry.registerDashboardsCache(dashboardsCache);
    // Collections cache
    CollectionsCache collectionsCache = new CollectionsCache(datasetConfigDAO, config);
    cacheRegistry.registerCollectionsCache(collectionsCache);
    // DatasetConfig cache
    LoadingCache<String, DatasetConfigDTO> datasetConfigCache = CacheBuilder.newBuilder().build(new DatasetConfigCacheLoader(datasetConfigDAO));
    cacheRegistry.registerDatasetConfigCache(datasetConfigCache);
    // MetricConfig cache
    LoadingCache<MetricDataset, MetricConfigDTO> metricConfigCache = CacheBuilder.newBuilder().build(new MetricConfigCacheLoader(metricConfigDAO));
    cacheRegistry.registerMetricConfigCache(metricConfigCache);
    // DashboardConfigs cache
    LoadingCache<String, List<DashboardConfigDTO>> dashboardConfigsCache = CacheBuilder.newBuilder().build(new DashboardConfigCacheLoader(dashboardConfigDAO));
    cacheRegistry.registerDashboardConfigsCache(dashboardConfigsCache);
}
Also used : ResultSetGroup(com.linkedin.pinot.client.ResultSetGroup) MetricConfigDTO(com.linkedin.thirdeye.datalayer.dto.MetricConfigDTO) LoadingCache(com.google.common.cache.LoadingCache) DimensionFiltersCacheLoader(com.linkedin.thirdeye.client.cache.DimensionFiltersCacheLoader) PinotQuery(com.linkedin.thirdeye.client.pinot.PinotQuery) DashboardConfigManager(com.linkedin.thirdeye.datalayer.bao.DashboardConfigManager) LoggerFactory(org.slf4j.LoggerFactory) ThirdEyeConfiguration(com.linkedin.thirdeye.common.ThirdEyeConfiguration) DatasetConfigManager(com.linkedin.thirdeye.datalayer.bao.DatasetConfigManager) MetricDataset(com.linkedin.thirdeye.client.cache.MetricDataset) MetricConfigManager(com.linkedin.thirdeye.datalayer.bao.MetricConfigManager) PinotThirdEyeClient(com.linkedin.thirdeye.client.pinot.PinotThirdEyeClient) QueryCache(com.linkedin.thirdeye.client.cache.QueryCache) CollectionMaxDataTimeCacheLoader(com.linkedin.thirdeye.client.cache.CollectionMaxDataTimeCacheLoader) MetricConfigCacheLoader(com.linkedin.thirdeye.client.cache.MetricConfigCacheLoader) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) CacheResource(com.linkedin.thirdeye.dashboard.resources.CacheResource) DashboardConfigCacheLoader(com.linkedin.thirdeye.client.cache.DashboardConfigCacheLoader) RemovalNotification(com.google.common.cache.RemovalNotification) CollectionsCache(com.linkedin.thirdeye.client.cache.CollectionsCache) Logger(org.slf4j.Logger) PinotThirdEyeClientConfig(com.linkedin.thirdeye.client.pinot.PinotThirdEyeClientConfig) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) DatasetConfigCacheLoader(com.linkedin.thirdeye.client.cache.DatasetConfigCacheLoader) List(java.util.List) DashboardsCacheLoader(com.linkedin.thirdeye.client.cache.DashboardsCacheLoader) ResultSetGroupCacheLoader(com.linkedin.thirdeye.client.cache.ResultSetGroupCacheLoader) DashboardConfigDTO(com.linkedin.thirdeye.datalayer.dto.DashboardConfigDTO) RemovalListener(com.google.common.cache.RemovalListener) CacheBuilder(com.google.common.cache.CacheBuilder) DatasetConfigDTO(com.linkedin.thirdeye.datalayer.dto.DatasetConfigDTO) ResultSetGroupCacheLoader(com.linkedin.thirdeye.client.cache.ResultSetGroupCacheLoader) QueryCache(com.linkedin.thirdeye.client.cache.QueryCache) DatasetConfigDTO(com.linkedin.thirdeye.datalayer.dto.DatasetConfigDTO) DatasetConfigCacheLoader(com.linkedin.thirdeye.client.cache.DatasetConfigCacheLoader) DimensionFiltersCacheLoader(com.linkedin.thirdeye.client.cache.DimensionFiltersCacheLoader) List(java.util.List) MetricConfigDTO(com.linkedin.thirdeye.datalayer.dto.MetricConfigDTO) DashboardConfigCacheLoader(com.linkedin.thirdeye.client.cache.DashboardConfigCacheLoader) RemovalListener(com.google.common.cache.RemovalListener) ResultSetGroup(com.linkedin.pinot.client.ResultSetGroup) DashboardsCacheLoader(com.linkedin.thirdeye.client.cache.DashboardsCacheLoader) MetricDataset(com.linkedin.thirdeye.client.cache.MetricDataset) CollectionMaxDataTimeCacheLoader(com.linkedin.thirdeye.client.cache.CollectionMaxDataTimeCacheLoader) PinotQuery(com.linkedin.thirdeye.client.pinot.PinotQuery) MetricConfigCacheLoader(com.linkedin.thirdeye.client.cache.MetricConfigCacheLoader) RemovalNotification(com.google.common.cache.RemovalNotification) CollectionsCache(com.linkedin.thirdeye.client.cache.CollectionsCache)

Example 3 with LoadingCache

use of com.google.common.cache.LoadingCache in project cdap by caskdata.

the class AggregatedMetricsCollectionService method getMetrics.

private Iterator<MetricValues> getMetrics(final long timestamp) {
    // NOTE : emitters.asMap does not reset the access time in cache,
    // so it's the preferred way to access the cache entries. as we access and emit metrics every second.
    final Iterator<Map.Entry<Map<String, String>, LoadingCache<String, AggregatedMetricsEmitter>>> iterator = emitters.asMap().entrySet().iterator();
    return new AbstractIterator<MetricValues>() {

        @Override
        protected MetricValues computeNext() {
            while (iterator.hasNext()) {
                Map.Entry<Map<String, String>, LoadingCache<String, AggregatedMetricsEmitter>> entry = iterator.next();
                Map<String, AggregatedMetricsEmitter> metricEmitters = entry.getValue().asMap();
                // +1 because we add extra metric about how many metric values did we emit in this context (see below)
                List<MetricValue> metricValues = Lists.newArrayListWithCapacity(metricEmitters.size() + 1);
                for (Map.Entry<String, AggregatedMetricsEmitter> emitterEntry : metricEmitters.entrySet()) {
                    MetricValue metricValue = emitterEntry.getValue().emit();
                    // skip increment by 0
                    if (metricValue.getType() == MetricType.COUNTER && metricValue.getValue() == 0) {
                        continue;
                    }
                    metricValues.add(metricValue);
                }
                if (metricValues.isEmpty()) {
                    // skip if there are no metric values to send
                    continue;
                }
                // number of emitted metrics
                metricValues.add(new MetricValue("metrics.emitted.count", MetricType.COUNTER, metricValues.size() + 1));
                LOG.trace("Emit metric {}", metricValues);
                return new MetricValues(entry.getKey(), timestamp, metricValues);
            }
            return endOfData();
        }
    };
}
Also used : MetricValues(co.cask.cdap.api.metrics.MetricValues) MetricValue(co.cask.cdap.api.metrics.MetricValue) LoadingCache(com.google.common.cache.LoadingCache) AbstractIterator(com.google.common.collect.AbstractIterator) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map)

Example 4 with LoadingCache

use of com.google.common.cache.LoadingCache in project FoamFix by asiekierka.

the class ProxyClient method onWorldUnload.

@SubscribeEvent(priority = EventPriority.LOWEST)
public void onWorldUnload(WorldEvent.Unload event) {
    if (FoamFixShared.config.clClearCachesOnUnload && event.getWorld() instanceof WorldClient && REGION_CACHE_GETTER != null) {
        try {
            LoadingCache cache = (LoadingCache) (REGION_CACHE_GETTER.invoke());
            cache.invalidateAll();
            cache.cleanUp();
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
}
Also used : LoadingCache(com.google.common.cache.LoadingCache) WorldClient(net.minecraft.client.multiplayer.WorldClient) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 5 with LoadingCache

use of com.google.common.cache.LoadingCache in project meghanada-server by mopemope.

the class JavaCompletion method completionPackage.

private Collection<? extends CandidateUnit> completionPackage() {
    final GlobalCache globalCache = GlobalCache.getInstance();
    final LoadingCache<File, Source> sourceCache = globalCache.getSourceCache(project);
    return sourceCache.asMap().values().stream().map(source -> ClassIndex.createPackage(source.getPackageName())).collect(Collectors.toSet());
}
Also used : FieldDescriptor(meghanada.reflect.FieldDescriptor) LoadingCache(com.google.common.cache.LoadingCache) AccessSymbol(meghanada.analyze.AccessSymbol) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Variable(meghanada.analyze.Variable) Map(java.util.Map) CandidateUnit(meghanada.reflect.CandidateUnit) MethodCall(meghanada.analyze.MethodCall) ClassScope(meghanada.analyze.ClassScope) GlobalCache(meghanada.cache.GlobalCache) ClassIndex(meghanada.reflect.ClassIndex) Collection(java.util.Collection) Set(java.util.Set) IOException(java.io.IOException) CachedASMReflector(meghanada.reflect.asm.CachedASMReflector) Collectors(java.util.stream.Collectors) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) MemberDescriptor(meghanada.reflect.MemberDescriptor) List(java.util.List) Stream(java.util.stream.Stream) Logger(org.apache.logging.log4j.Logger) ClassNameUtils(meghanada.utils.ClassNameUtils) Optional(java.util.Optional) Project(meghanada.project.Project) Source(meghanada.analyze.Source) Objects.nonNull(java.util.Objects.nonNull) Comparator(java.util.Comparator) Collections(java.util.Collections) TypeScope(meghanada.analyze.TypeScope) Config(meghanada.config.Config) LogManager(org.apache.logging.log4j.LogManager) GlobalCache(meghanada.cache.GlobalCache) File(java.io.File) Source(meghanada.analyze.Source)

Aggregations

LoadingCache (com.google.common.cache.LoadingCache)14 Map (java.util.Map)7 List (java.util.List)6 CacheLoader (com.google.common.cache.CacheLoader)5 Optional (java.util.Optional)5 CacheBuilder (com.google.common.cache.CacheBuilder)4 ExecutionException (java.util.concurrent.ExecutionException)3 Collectors (java.util.stream.Collectors)3 BuildTarget (com.facebook.buck.model.BuildTarget)2 ImmutableList (com.google.common.collect.ImmutableList)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 Nonnull (javax.annotation.Nonnull)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 FailurePolicy (co.cask.cdap.api.flow.flowlet.FailurePolicy)1 FailureReason (co.cask.cdap.api.flow.flowlet.FailureReason)1 InputContext (co.cask.cdap.api.flow.flowlet.InputContext)1 MetricValue (co.cask.cdap.api.metrics.MetricValue)1 MetricValues (co.cask.cdap.api.metrics.MetricValues)1