org.infinispan.functional.impl.FunctionalMapImpl Java Examples
The following examples show how to use
org.infinispan.functional.impl.FunctionalMapImpl.
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: InfinispanJCacheCacheResolver.java From bucket4j-spring-boot-starter with Apache License 2.0 | 5 votes |
public ProxyManager<String> resolve(String cacheName) { Cache<Object, Object> cache = cacheContainer.getCache(cacheName); if (cache == null) { throw new JCacheNotFoundException(cacheName); } FunctionalMapImpl functionalMap = FunctionalMapImpl.create(cache.getAdvancedCache()); return Bucket4j.extension(Infinispan.class).proxyManagerForMap(ReadWriteMapImpl.create(functionalMap)); }
Example #2
Source File: Bucket4jInfinispanApplication.java From spring-cloud-zuul-ratelimit with Apache License 2.0 | 5 votes |
@Bean @Qualifier("RateLimit") public ReadWriteMap<String, GridBucketState> map() { 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); return ReadWriteMapImpl.create(functionalMap); }
Example #3
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 #4
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 #5
Source File: InfinispanTest.java From bucket4j with Apache License 2.0 | 4 votes |
private static FunctionalMap.ReadWriteMap<String, GridBucketState> toMap(Cache<String, GridBucketState> cache) { org.infinispan.Cache<String, GridBucketState> nativeCache = cache.unwrap(org.infinispan.Cache.class); FunctionalMapImpl<String, GridBucketState> functionalMap = FunctionalMapImpl.create(nativeCache.getAdvancedCache()); return ReadWriteMapImpl.create(functionalMap); }
Example #6
Source File: InfinispanTest.java From bucket4j with Apache License 2.0 | 4 votes |
private static ReadWriteMap<String, GridBucketState> toMap(Cache<String, GridBucketState> cache) { FunctionalMapImpl<String, GridBucketState> functionalMap = FunctionalMapImpl.create(cache.getAdvancedCache()); return ReadWriteMapImpl.create(functionalMap); }