org.infinispan.functional.FunctionalMap Java Examples
The following examples show how to use
org.infinispan.functional.FunctionalMap.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Bucket4jInfinispanRateLimiterTest.java From spring-cloud-zuul-ratelimit with Apache License 2.0 | 5 votes |
@BeforeEach public void setUp() { MockitoAnnotations.initMocks(this); DefaultCacheManager cacheManager = new DefaultCacheManager(); cacheManager.defineConfiguration("rateLimit", new ConfigurationBuilder().build()); AdvancedCache<String, GridBucketState> cache = cacheManager.<String, GridBucketState>getCache("rateLimit").getAdvancedCache(); FunctionalMapImpl<String, GridBucketState> functionalMap = FunctionalMapImpl.create(cache); FunctionalMap.ReadWriteMap<String, GridBucketState> readWriteMap = ReadWriteMapImpl.create(functionalMap); target = new Bucket4jInfinispanRateLimiter(readWriteMap); }
Example #2
Source File: InfinispanFunctional.java From infinispan-simple-tutorials with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws Exception { DefaultCacheManager cacheManager = new DefaultCacheManager(); cacheManager.defineConfiguration("local", new ConfigurationBuilder().build()); AdvancedCache<String, String> cache = cacheManager.<String, String>getCache("local").getAdvancedCache(); FunctionalMapImpl<String, String> functionalMap = FunctionalMapImpl.create(cache); FunctionalMap.WriteOnlyMap<String, String> writeOnlyMap = WriteOnlyMapImpl.create(functionalMap); FunctionalMap.ReadOnlyMap<String, String> readOnlyMap = ReadOnlyMapImpl.create(functionalMap); // Execute two parallel write-only operation to store key/value pairs CompletableFuture<Void> writeFuture1 = writeOnlyMap.eval("key1", "value1", (v, writeView) -> writeView.set(v)); CompletableFuture<Void> writeFuture2 = writeOnlyMap.eval("key2", "value2", (v, writeView) -> writeView.set(v)); // When each write-only operation completes, execute a read-only operation to retrieve the value CompletableFuture<String> readFuture1 = writeFuture1.thenCompose(r -> readOnlyMap.eval("key1", EntryView.ReadEntryView::get)); CompletableFuture<String> readFuture2 = writeFuture2.thenCompose(r -> readOnlyMap.eval("key2", EntryView.ReadEntryView::get)); // When the read-only operation completes, print it out System.out.printf("Created entries: %n"); CompletableFuture<Void> end = readFuture1.thenAcceptBoth(readFuture2, (v1, v2) -> System.out.printf("key1 = %s%nkey2 = %s%n", v1, v2)); // Wait for this read/write combination to finish end.get(); // Create a read-write map FunctionalMap.ReadWriteMap<String, String> readWriteMap = ReadWriteMapImpl.create(functionalMap); // Use read-write multi-key based operation to write new values // together with lifespan and return previous values Map<String, String> data = new HashMap<>(); data.put("key1", "newValue1"); data.put("key2", "newValue2"); Traversable<String> previousValues = readWriteMap.evalMany(data, (v, readWriteView) -> { String prev = readWriteView.find().orElse(null); readWriteView.set(v, new MetaLifespan(Duration.ofHours(1).toMillis())); return prev; }); // Use read-only multi-key operation to read current values for multiple keys Traversable<EntryView.ReadEntryView<String, String>> entryViews = readOnlyMap.evalMany(data.keySet(), readOnlyView -> readOnlyView); System.out.printf("Updated entries: %n"); entryViews.forEach(view -> System.out.printf("%s%n", view)); // Finally, print out the previous entry values System.out.printf("Previous entry values: %n"); previousValues.forEach(prev -> System.out.printf("%s%n", prev)); }
Example #3
Source File: InfinispanProxyManager.java From bucket4j with Apache License 2.0 | 4 votes |
InfinispanProxyManager(FunctionalMap.ReadWriteMap<K, GridBucketState> readWriteMap) { if (readWriteMap == null) { throw new IllegalArgumentException("map must not be null"); } this.gridProxy = new InfinispanProxy<>(readWriteMap); }
Example #4
Source File: InfinispanBucketBuilder.java From bucket4j with Apache License 2.0 | 2 votes |
/** * Constructs an instance of {@link GridBucket} which state actually stored inside in-memory data-grid, * semantic of this method is fully equals to {@link io.github.bucket4j.grid.jcache.JCacheBucketBuilder#build(Cache, Serializable, RecoveryStrategy)} * * @return new distributed bucket */ public <K extends Serializable> Bucket build(FunctionalMap.ReadWriteMap<K, GridBucketState> readWriteMap, K key, RecoveryStrategy recoveryStrategy) { BucketConfiguration configuration = buildConfiguration(); InfinispanProxy<K> gridProxy = new InfinispanProxy<>(readWriteMap); return GridBucket.createInitializedBucket(key, configuration, gridProxy, recoveryStrategy); }