当前位置: 首页>>代码示例>>Java>>正文


Java Suppliers.memoizeWithExpiration方法代码示例

本文整理汇总了Java中com.google.common.base.Suppliers.memoizeWithExpiration方法的典型用法代码示例。如果您正苦于以下问题:Java Suppliers.memoizeWithExpiration方法的具体用法?Java Suppliers.memoizeWithExpiration怎么用?Java Suppliers.memoizeWithExpiration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.base.Suppliers的用法示例。


在下文中一共展示了Suppliers.memoizeWithExpiration方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: GSuiteGroupAuthorizationFilter

import com.google.common.base.Suppliers; //导入方法依赖的package包/类
public GSuiteGroupAuthorizationFilter(final GSuiteDirectoryService gsuiteDirService, AppConfiguration config) {
    this.config = config;
    this.externalAccountsCache = Suppliers.memoizeWithExpiration(
            () -> {
                String allowGroup = config.getExternalAccountsGroup();
                Set<String> result = Collections.emptySet();
                try {
                    GroupMembership membership = gsuiteDirService.getGroupMembers(allowGroup);
                    result = membership.getMembers() == null ? Collections.emptySet()
                    : membership.getMembers().stream().map(m -> m.getEmail()).collect(Collectors.toSet());
                } catch (ResourceNotFoundException e) {
                    log.warn("Group for external accounts {} does not exists", allowGroup);
                }
                return result;
            }, 15, TimeUnit.MINUTES);
}
 
开发者ID:hlavki,项目名称:g-suite-identity-sync,代码行数:17,代码来源:GSuiteGroupAuthorizationFilter.java

示例2: main

import com.google.common.base.Suppliers; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException {
    // {{start:memoize}}
    log.info("Memoized");
    Supplier<String> memoized = Suppliers.memoize(SuppliersExamples::helloWorldSupplier);
    log.info(memoized.get());
    log.info(memoized.get());
    // {{end:memoize}}

    // {{start:memoizeWithExpiration}}
    log.info("Memoized with Expiration");
    Supplier<String> memoizedExpiring = Suppliers.memoizeWithExpiration(
        SuppliersExamples::helloWorldSupplier, 50, TimeUnit.MILLISECONDS);
    log.info(memoizedExpiring.get());
    log.info(memoizedExpiring.get());
    log.info("sleeping");
    TimeUnit.MILLISECONDS.sleep(100);
    log.info(memoizedExpiring.get());
    log.info(memoizedExpiring.get());
    log.info("sleeping");
    TimeUnit.MILLISECONDS.sleep(100);
    log.info(memoizedExpiring.get());
    log.info(memoizedExpiring.get());
    // {{end:memoizeWithExpiration}}
}
 
开发者ID:StubbornJava,项目名称:StubbornJava,代码行数:25,代码来源:SuppliersExamples.java

示例3: ConfigService

import com.google.common.base.Suppliers; //导入方法依赖的package包/类
public ConfigService(List<ConfigurationProvider> configurationProviders, Authorizer authorizer, long maximumCacheSize, long cacheTtlMillis) {
    this.authorizer = authorizer;
    this.objectMapper = new ObjectMapper();
    if (configurationProviders == null || configurationProviders.size() == 0) {
        throw new IllegalArgumentException("Expected at least one configuration provider");
    }
    this.configurationProviderInfo = Suppliers.memoizeWithExpiration(() -> initContentTypeInfo(configurationProviders), cacheTtlMillis, TimeUnit.MILLISECONDS);
    CacheBuilder<Object, Object> cacheBuilder = CacheBuilder.newBuilder();
    if (maximumCacheSize >= 0) {
        cacheBuilder = cacheBuilder.maximumSize(maximumCacheSize);
    }
    if (cacheTtlMillis >= 0) {
        cacheBuilder = cacheBuilder.refreshAfterWrite(cacheTtlMillis, TimeUnit.MILLISECONDS);
    }
    this.configurationCache = cacheBuilder
            .build(new CacheLoader<ConfigurationProviderKey, ConfigurationProviderValue>() {
                @Override
                public ConfigurationProviderValue load(ConfigurationProviderKey key) throws Exception {
                    return initConfigurationProviderValue(key);
                }
            });
}
 
开发者ID:apache,项目名称:nifi-minifi,代码行数:23,代码来源:ConfigService.java

示例4: refresh

import com.google.common.base.Suppliers; //导入方法依赖的package包/类
@Override
public void refresh() {
    _cache = Suppliers.memoizeWithExpiration(new Supplier<CachedInfo>() {
        @Override
        public CachedInfo get() {
            Map<String, DataCenter> dataCenters = _dataCenterDao.loadAll();
            if (!_ignoredDataCenters.isEmpty()) {
                ImmutableMap.Builder<String, DataCenter> dataCentersBuilder = ImmutableMap.builder();
                for (Map.Entry<String, DataCenter> entry : dataCenters.entrySet()) {
                    if (!_ignoredDataCenters.contains(entry.getKey())) {
                        dataCentersBuilder.put(entry);
                    } else if (_loggedIgnored.add(entry.getKey())) {
                        // Only want to log that we're ignoring the data center once
                        _log.info("Ignoring data center: {}", entry.getKey());
                    }
                }
                dataCenters = dataCentersBuilder.build();
            }
            return new CachedInfo(dataCenters);
        }
    }, 10, TimeUnit.MINUTES);
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:23,代码来源:DefaultDataCenters.java

示例5: StandardStashReader

import com.google.common.base.Suppliers; //导入方法依赖的package包/类
@VisibleForTesting
StandardStashReader(URI stashRoot, AmazonS3 s3, long refreshLatestMs) {
    super(stashRoot, s3);

    Supplier<String> s3LatestRootSupplier = new Supplier<String>() {
        @Override
        public String get() {
            String latest = readLatestStash();
            return String.format("%s/%s", _rootPath, latest);
        }
    };

    if (refreshLatestMs > 0) {
        // Cache the latest stash directory and periodically recheck
        _latestRootSupplier = Suppliers.memoizeWithExpiration(s3LatestRootSupplier, refreshLatestMs, TimeUnit.MILLISECONDS);
    } else {
        _latestRootSupplier = s3LatestRootSupplier;
    }
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:20,代码来源:StandardStashReader.java

示例6: ShardSizeExpression

import com.google.common.base.Suppliers; //导入方法依赖的package包/类
@Inject
public ShardSizeExpression(final IndexShard indexShard) {
    sizeSupplier = Suppliers.memoizeWithExpiration(new Supplier<Long>() {
        @Override
        public Long get() {
            return indexShard.storeStats().getSizeInBytes();
        }
    }, 10, TimeUnit.SECONDS);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:10,代码来源:ShardSizeExpression.java

示例7: BlobShardSizeExpression

import com.google.common.base.Suppliers; //导入方法依赖的package包/类
@Inject
public BlobShardSizeExpression(final BlobShard blobShard) {
    totalUsageSupplier = Suppliers.memoizeWithExpiration(new Supplier<Long>() {
        @Override
        public Long get() {
            return blobShard.blobStats().totalUsage();
        }
    }, 10, TimeUnit.SECONDS);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:10,代码来源:BlobShardSizeExpression.java

示例8: configure

import com.google.common.base.Suppliers; //导入方法依赖的package包/类
private void configure() {
    log.info("Configuring GSuiteDirectoryService ...");
    long tokenLifetime = config.getServiceAccountTokenLifetime();
    log.info("Token lifetime set to {}", tokenLifetime);
    this.tokenCache = Suppliers.memoizeWithExpiration(() -> getAccessToken(), tokenLifetime - 3, TimeUnit.SECONDS);
    this.membershipCache = Suppliers.memoizeWithExpiration(() -> getAllGroupMembershipInternal(), 3, TimeUnit.MINUTES);
    try {
        privateKey = config.getServiceAccountKey();
        log.info("Service account private key {}loaded", privateKey != null ? "" : "was not ");
    } catch (NoPrivateKeyException e) {
        log.error(e.getMessage(), e.getCause());
    }
}
 
开发者ID:hlavki,项目名称:g-suite-identity-sync,代码行数:14,代码来源:GSuiteDirectoryServiceImpl.java

示例9: fromSupplierWithExpiration

import com.google.common.base.Suppliers; //导入方法依赖的package包/类
public static InMemorySitemap fromSupplierWithExpiration(
        Supplier<Map<String, List<String>>> supplier,
        long duration,
        TimeUnit unit) {
    Supplier<Map<String, String>> sup = mapSupplier(supplier);
    Supplier<Map<String, String>> memoized = Suppliers.memoizeWithExpiration(sup::get, duration, unit);
    return new InMemorySitemap(memoized);
}
 
开发者ID:StubbornJava,项目名称:StubbornJava,代码行数:9,代码来源:InMemorySitemap.java

示例10: ServiceConfigFetcher

import com.google.common.base.Suppliers; //导入方法依赖的package包/类
@VisibleForTesting
ServiceConfigFetcher(Supplier<Service> supplier) {
  this.serviceSupplier = Suppliers.memoizeWithExpiration(supplier, 10, TimeUnit.MINUTES);
}
 
开发者ID:cloudendpoints,项目名称:endpoints-management-java,代码行数:5,代码来源:ServiceConfigFetcher.java

示例11: DefaultJobService

import com.google.common.base.Suppliers; //导入方法依赖的package包/类
@Inject
public DefaultJobService(LifeCycleRegistry lifeCycleRegistry,
                         QueueService queueService,
                         @JobQueueName String queueName,
                         JobHandlerRegistryInternal jobHandlerRegistry,
                         JobStatusDAO jobStatusDAO,
                         @JobZooKeeper CuratorFramework curator,
                         @JobConcurrencyLevel Integer concurrencyLevel,
                         @QueueRefreshTime Duration queueRefreshTime,
                         final @QueuePeekLimit Integer queuePeekLimit,
                         @NotOwnerRetryDelay Duration notOwnerRetryDelay) {
    _queueService = checkNotNull(queueService, "queueService");
    _queueName = checkNotNull(queueName, "queueName");
    _jobHandlerRegistry = checkNotNull(jobHandlerRegistry, "jobHandlerRegistry");
    _jobStatusDAO = checkNotNull(jobStatusDAO, "jobStatusDAO");
    _curator = checkNotNull(curator, "curator");
    _concurrencyLevel = checkNotNull(concurrencyLevel, "concurrencyLevel");
    checkArgument(_concurrencyLevel >= 0, "Concurrency level cannot be negative");
    _notOwnerRetryDelay = checkNotNull(notOwnerRetryDelay, "notOwnerRetryDelay");
    checkNotNull(queuePeekLimit, "queuePeekLimit");
    checkNotNull(lifeCycleRegistry, "lifecycleRegistry");

    _recentNotOwnerDelays = CacheBuilder.newBuilder()
            .expireAfterWrite(notOwnerRetryDelay.getMillis(), TimeUnit.MILLISECONDS)
            .build();

    Supplier<Queue<Message>> sourceMessageSupplier = new Supplier<Queue<Message>>() {
        @Override
        public Queue<Message> get() {
            return Queues.synchronizedQueue(Queues.newArrayDeque(_queueService.peek(_queueName, queuePeekLimit)));
        }
    };

    checkNotNull(queueRefreshTime, "queueRefreshTime");
    if (queueRefreshTime.getMillis() == 0) {
        _messageSupplier = sourceMessageSupplier;
    } else {
        _messageSupplier = Suppliers.memoizeWithExpiration(
                sourceMessageSupplier, queueRefreshTime.getMillis(), TimeUnit.MILLISECONDS);
    }

    lifeCycleRegistry.manage(this);
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:44,代码来源:DefaultJobService.java

示例12: memoizeWithRandomExpiration

import com.google.common.base.Suppliers; //导入方法依赖的package包/类
/**
 * Memoization similar to {@link Suppliers#memoizeWithExpiration(Supplier, long, TimeUnit)} except the expiration
 * is randomly selected to be a value within provided bounds.  For example:
 *
 * <code>
 *     Supplier&lt;Object&t; supplier = MoreSuppliers.memoizeWithRandomExpiration(delegate, 5, 10, TimeUnit.SECONDS);
 * </code>
 *
 * returns a Supplier that will memoize the delegate's response for a random number of nanoseconds between 5
 * (inclusive) to 10 (exclusive) seconds.
 *
 * This is useful when numerous memoized values are typically computed independently but used within the same operation.
 * If all values were computed and memoized together then each call that refreshes from delegate could take longer
 * than desirable.  Similarly, if each value were memomized independently using the same expiration then herding
 * behavior would result in the same long calls at expiration time.  A random expiration allows each value to be
 * cached but spread out the refresh cycle so that it is unlikely that any single call will refresh the entire value
 * set, so long as the call frequency is significantly below <code>minDuration</code>.
 */
public static <T> Supplier<T> memoizeWithRandomExpiration(Supplier<T> delegate, long minDuration, long maxDuration, TimeUnit units) {
    if (minDuration == maxDuration) {
        // This case resolves to standard expiration
        return Suppliers.memoizeWithExpiration(delegate, minDuration, units);
    }
    return new RandomExpirationSupplier<T>(delegate, minDuration, maxDuration, units);
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:26,代码来源:MoreSuppliers.java


注:本文中的com.google.common.base.Suppliers.memoizeWithExpiration方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。