private Supplier<ImmutableMap<String, String>> formSupplier() { return Suppliers.memoize(new Supplier<ImmutableMap<String, String>>() { @Override public ImmutableMap<String, String> get() { Optional<ImmutableMap<String, String>> forms = new FormsRequestExtractor().extract(DefaultHttpRequest.this); return forms.or(emptyMapSupplier()); } }); }
@GwtIncompatible // SerializationTester public void testSerialization() { assertEquals(Integer.valueOf(5), reserialize(Suppliers.ofInstance(5)).get()); assertEquals( Integer.valueOf(5), reserialize(Suppliers.compose(Functions.identity(), Suppliers.ofInstance(5))).get()); assertEquals(Integer.valueOf(5), reserialize(Suppliers.memoize(Suppliers.ofInstance(5))).get()); assertEquals( Integer.valueOf(5), reserialize(Suppliers.memoizeWithExpiration(Suppliers.ofInstance(5), 30, TimeUnit.SECONDS)) .get()); assertEquals( Integer.valueOf(5), reserialize(Suppliers.synchronizedSupplier(Suppliers.ofInstance(5))).get()); }
private Supplier<ImmutableMap<String, String>> cookieSupplier() { return Suppliers.memoize(new Supplier<ImmutableMap<String, String>>() { @Override public ImmutableMap<String, String> get() { Optional<ImmutableMap<String, String>> cookies = new CookiesRequestExtractor().extract(DefaultHttpRequest.this); return cookies.or(emptyMapSupplier()); } }); }
@Override public Supplier<Boolean> apply(Supplier<Boolean> supplier) { return Suppliers.memoize(supplier); } };
SystemTransactionHandle( ConnectorId connectorId, TransactionId transactionId, Function<TransactionId, ConnectorTransactionHandle> transactionHandleFunction) { this.connectorId = requireNonNull(connectorId, "connectorId is null"); this.transactionId = requireNonNull(transactionId, "transactionId is null"); requireNonNull(transactionHandleFunction, "transactionHandleFunction is null"); this.connectorTransactionHandle = Suppliers.memoize(() -> transactionHandleFunction.apply(transactionId)); }
public NativeCassandraSession(String connectorId, JsonCodec<List<ExtraColumnMetadata>> extraColumnMetadataCodec, Cluster cluster, Duration noHostAvailableRetryTimeout) { this.connectorId = requireNonNull(connectorId, "connectorId is null"); this.extraColumnMetadataCodec = requireNonNull(extraColumnMetadataCodec, "extraColumnMetadataCodec is null"); this.cluster = requireNonNull(cluster, "cluster is null"); this.noHostAvailableRetryTimeout = requireNonNull(noHostAvailableRetryTimeout, "noHostAvailableRetryTimeout is null"); this.session = memoize(cluster::connect); }
public OutputBufferMemoryManager(long maxBufferedBytes, Supplier<LocalMemoryContext> systemMemoryContextSupplier, Executor notificationExecutor) { requireNonNull(systemMemoryContextSupplier, "systemMemoryContextSupplier is null"); checkArgument(maxBufferedBytes > 0, "maxBufferedBytes must be > 0"); this.maxBufferedBytes = maxBufferedBytes; this.systemMemoryContextSupplier = Suppliers.memoize(systemMemoryContextSupplier::get); this.notificationExecutor = requireNonNull(notificationExecutor, "notificationExecutor is null"); bufferBlockedFuture = SettableFuture.create(); bufferBlockedFuture.set(null); }
@VisibleForTesting void invalidate() { this.indexSetConfigs.set(Suppliers.memoize(this.indexSetService::findAll)); }
@Inject IndexSetsCache(IndexSetService indexSetService, EventBus serverEventBus) { this.indexSetService = requireNonNull(indexSetService); this.indexSetConfigs = new AtomicReference<>(Suppliers.memoize(this.indexSetService::findAll)); serverEventBus.register(this); }
public LazyAccumulatorFactoryBinder(AggregationMetadata metadata, DynamicClassLoader classLoader) { binder = Suppliers.memoize(() -> AccumulatorCompiler.generateAccumulatorFactoryBinder(metadata, classLoader)); }
@Inject public ExampleClient(ExampleConfig config, JsonCodec<Map<String, List<ExampleTable>>> catalogCodec) { requireNonNull(config, "config is null"); requireNonNull(catalogCodec, "catalogCodec is null"); schemas = Suppliers.memoize(schemasSupplier(catalogCodec, config.getMetadata())); }
@Inject RedisMetadata( RedisConnectorId connectorId, RedisConnectorConfig redisConnectorConfig, Supplier<Map<SchemaTableName, RedisTableDescription>> redisTableDescriptionSupplier) { this.connectorId = requireNonNull(connectorId, "connectorId is null").toString(); requireNonNull(redisConnectorConfig, "redisConfig is null"); hideInternalColumns = redisConnectorConfig.isHideInternalColumns(); log.debug("Loading redis table definitions from %s", redisConnectorConfig.getTableDescriptionDir().getAbsolutePath()); this.redisTableDescriptionSupplier = Suppliers.memoize(redisTableDescriptionSupplier::get)::get; }
private void memoizeExceptionThrownTest(ThrowingSupplier throwingSupplier) { Supplier<Integer> memoizedSupplier = Suppliers.memoize(throwingSupplier); // call get() twice to make sure that memoization doesn't interfere // with throwing the exception for (int i = 0; i < 2; i++) { try { memoizedSupplier.get(); fail("failed to throw NullPointerException"); } catch (NullPointerException e) { // this is what should happen } } }
@Inject public HdfsDataSegmentPusher(HdfsDataSegmentPusherConfig config, Configuration hadoopConfig, ObjectMapper jsonMapper) { this.hadoopConfig = hadoopConfig; this.jsonMapper = jsonMapper; Path storageDir = new Path(config.getStorageDirectory()); this.fullyQualifiedStorageDirectory = Suppliers.memoize( () -> { try { return FileSystem.newInstance(storageDir.toUri(), hadoopConfig) .makeQualified(storageDir) .toUri() .toString(); } catch (Exception e) { throw new RuntimeException(e); } } ); log.info("Configured HDFS as deep storage"); }
private void memoizeTest(CountingSupplier countingSupplier) { Supplier<Integer> memoizedSupplier = Suppliers.memoize(countingSupplier); checkMemoize(countingSupplier, memoizedSupplier); }
@GwtIncompatible // SerializableTester public void testMemoizeSerializable() throws Exception { SerializableCountingSupplier countingSupplier = new SerializableCountingSupplier(); Supplier<Integer> memoizedSupplier = Suppliers.memoize(countingSupplier); assertThat(memoizedSupplier.toString()).isEqualTo("Suppliers.memoize(CountingSupplier)"); checkMemoize(countingSupplier, memoizedSupplier); // Calls to the original memoized supplier shouldn't affect its copy. memoizedSupplier.get(); assertThat(memoizedSupplier.toString()) .isEqualTo("Suppliers.memoize(<supplier that returned 10>)"); Supplier<Integer> copy = reserialize(memoizedSupplier); memoizedSupplier.get(); CountingSupplier countingCopy = (CountingSupplier) ((Suppliers.MemoizingSupplier<Integer>) copy).delegate; checkMemoize(countingCopy, copy); }
public ConfigurationRepositoryImpl(AnalysisMetadataHolder analysisMetadataHolder, ProjectConfigurationFactory f) { this.configuration = Suppliers.memoize(() -> f.newProjectConfiguration(analysisMetadataHolder.getProject().getKey(), analysisMetadataHolder.getBranch())); }
@GwtIncompatible // SerializableTester public void testMemoizeNonSerializable() throws Exception { CountingSupplier countingSupplier = new CountingSupplier(); Supplier<Integer> memoizedSupplier = Suppliers.memoize(countingSupplier); assertThat(memoizedSupplier.toString()).isEqualTo("Suppliers.memoize(CountingSupplier)"); checkMemoize(countingSupplier, memoizedSupplier); // Calls to the original memoized supplier shouldn't affect its copy. memoizedSupplier.get(); assertThat(memoizedSupplier.toString()) .isEqualTo("Suppliers.memoize(<supplier that returned 10>)"); // Should get an exception when we try to serialize. try { reserialize(memoizedSupplier); fail(); } catch (RuntimeException ex) { assertThat(ex).hasCauseThat().isInstanceOf(java.io.NotSerializableException.class); } }
private static Supplier<CodeTransformer> scansPlugins( ScannerSupplier scannerSupplier, ErrorProneOptions errorProneOptions, Context context) { return Suppliers.memoize( () -> { // we can't load plugins from the processorpath until the filemanager has been // initialized, so do it lazily try { return ErrorProneScannerTransformer.create( ErrorPronePlugins.loadPlugins(scannerSupplier, context) .applyOverrides(errorProneOptions) .get()); } catch (InvalidCommandLineOptionException e) { throw new PropagatedException(e); } }); }