Refine search
@Test public void testLocalMaps() { LocalMap<String, String> map = sharedData.getLocalMap("test-map"); assertNotNull(map); assertTrue(map.isEmpty()); assertEquals(map.size(), 0); assertEquals(map.entrySet().size(), 0); assertEquals(map.values().size(), 0); assertEquals(map.keySet().size(), 0); assertEquals(map.getOrDefault("foo", "miss"), "miss"); assertNull(map.putIfAbsent("foo", "there")); assertNotNull(map.putIfAbsent("foo", "there")); assertEquals(map.getOrDefault("foo", "miss"), "there"); assertEquals(map.get("foo"), "there"); assertNull(map.get("missing")); assertFalse(map.isEmpty()); assertEquals(map.size(), 1); assertEquals(map.entrySet().size(), 1); assertEquals(map.values().size(), 1); assertEquals(map.keySet().size(), 1); assertFalse(map.removeIfPresent("missing", "nope")); assertTrue(map.removeIfPresent("foo", "there")); assertNull(map.put("foo", "there")); assertFalse(map.replaceIfPresent("missing", "nope", "something")); assertTrue(map.replaceIfPresent("foo", "there", "something")); assertEquals(map.get("foo"), "something");
@Test public void deleteElementOnComputeFunctionReturningNull() { LocalMap<String, String> map = sharedData.getLocalMap("foo"); // put an initial value map.put("hello", "world"); // retuning null we should remove the entry map.computeIfPresent("hello", (key, oldValue) -> null); assertFalse(map.containsKey("hello")); // Same for LocalMap#compute and LocalMap#compute map.compute("hello", (key, oldValue) -> null); assertFalse(map.containsKey("hello")); // put a value one more time map.put("hello", "world"); map.merge("hello", "world!!!!!!", (key, oldValue) -> null); assertFalse(map.containsKey("hello")); map.computeIfAbsent("hello", key -> null); assertFalse(map.containsKey("hello")); }
@Test public void testKeys() { LocalMap<String, String> map = sharedData.getLocalMap("foo"); map.put("foo1", "val1"); map.put("foo2", "val2"); map.put("foo3", "val3"); assertEquals(3, map.size()); Set<String> keys = map.keySet(); assertEquals(3, keys.size()); assertTrue(keys.contains("foo1")); assertTrue(keys.contains("foo2")); assertTrue(keys.contains("foo3")); }
@Test public void testValues() { LocalMap<String, String> map = sharedData.getLocalMap("foo"); map.put("foo1", "val1"); map.put("foo2", "val2"); map.put("foo3", "val3"); assertEquals(3, map.size()); Collection<String> values = map.values(); assertEquals(3, values.size()); assertTrue(values.contains("val1")); assertTrue(values.contains("val2")); assertTrue(values.contains("val3")); }
@Override public void put(Session session, Handler<AsyncResult<Void>> resultHandler) { final AbstractSession oldSession = (AbstractSession) localMap.get(session.id()); final AbstractSession newSession = (AbstractSession) session; if (oldSession != null) { // there was already some stored data in this case we need to validate versions if (oldSession.version() != newSession.version()) { resultHandler.handle(Future.failedFuture("Version mismatch")); return; } } newSession.incrementVersion(); localMap.put(session.id(), session); resultHandler.handle(Future.succeededFuture()); }
metrics.close(); Future<Void> f1 = Future.future(); Future<Void> f2 = Future.future(); if (completionHandler != null) { CompositeFuture.all(f1, f2).<Void>map(f -> null).setHandler(completionHandler); map.remove(name); if (map.isEmpty()) { map.close(); completionHandler.handle(Future.succeededFuture());
@Override public void remove(K k, Handler<AsyncResult<V>> handler) { try { V v = local.remove(k); handler.handle(Future.succeededFuture(v)); } catch (Exception e) { handler.handle(Future.failedFuture(e)); } }
@Override public void size(Handler<AsyncResult<Integer>> handler) { try { int size = local.size(); handler.handle(Future.succeededFuture(size)); } catch (Exception e) { handler.handle(Future.failedFuture(e)); } }
@Override public void keys(Handler<AsyncResult<Set<K>>> handler) { try { Set<K> keys = local.keySet(); handler.handle(Future.succeededFuture(keys)); } catch (Exception e) { handler.handle(Future.failedFuture(e)); } }
@Override public void clear(Handler<AsyncResult<Void>> handler) { try { local.clear(); handler.handle(Future.succeededFuture()); } catch (Exception e) { handler.handle(Future.failedFuture(e)); } }
public void deleteMessage(String topic) { String key = topic; LocalMap<String, byte[]> map = vertx.sharedData().getLocalMap(tenant); if(map.keySet().contains(key)) { map.remove(key); } }
@Override public void size(Handler<AsyncResult<Integer>> resultHandler) { resultHandler.handle(Future.succeededFuture(localMap.size())); }
@Override public void clear(Handler<AsyncResult<Void>> resultHandler) { localMap.clear(); resultHandler.handle(Future.succeededFuture()); }
@Override public void get(String id, Handler<AsyncResult<Session>> resultHandler) { resultHandler.handle(Future.succeededFuture(localMap.get(id))); }
@Override public void delete(String id, Handler<AsyncResult<Void>> resultHandler) { localMap.remove(id); resultHandler.handle(Future.succeededFuture()); }
void shutdown() { super.close(); // We must call this or handlers don't get unregistered and we get a leak if (heartbeatID != -1) { vertx.cancelTimer(heartbeatID); } if (timeoutTimerID != -1) { vertx.cancelTimer(timeoutTimerID); } if (id != null) { // Can be null if websocket session sessions.remove(id); } if (!closed) { closed = true; if (endHandler != null) { endHandler.handle(null); } } }
@Override public void keys(Handler<AsyncResult<Set<K>>> resultHandler) { resultHandler.handle(Future.succeededFuture(map.keySet())); }