@Override public void entryUpdated(EntryEvent<K, V> entry) { K k = entry.getKey(); ChoosableSet<V> entries = cache.get(k); if (entries != null) { entries.add(entry.getValue()); } }
private void addEntry(K k, V v) { ChoosableSet<V> entries = cache.get(k); if (entries == null) { entries = new ChoosableSet<>(1); ChoosableSet<V> prev = cache.putIfAbsent(k, entries); if (prev != null) { entries = prev; } } entries.add(v); }
@Override public void get(final K k, final Handler<AsyncResult<ChoosableIterable<V>>> resultHandler) { ChoosableSet<V> entries = cache.get(k); Future<ChoosableIterable<V>> result = Future.future(); if (entries != null && entries.isInitialised()) { result.setResult(entries).setHandler(resultHandler); } else { vertx.executeBlocking( () -> map.get(k), (AsyncResult<Collection<V>> res2) -> { Future<ChoosableIterable<V>> sresult = Future.future(); if (res2.succeeded()) { Collection<V> entries2 = res2.result(); ChoosableSet<V> sids; if (entries2 != null) { sids = new ChoosableSet<>(entries2.size()); for (V hid : entries2) { sids.add(hid); } } else { sids = new ChoosableSet<>(0); } ChoosableSet<V> prev = cache.putIfAbsent(k, sids); if (prev != null) { // Merge them prev.merge(sids); sids = prev; } sids.setInitialised(); sresult.setResult(sids); } else { sresult.setFailure(result.cause()); } sresult.setHandler(resultHandler); }); } }