@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 testKeysCopied() { LocalMap<JsonObject, String> map = sharedData.getLocalMap("foo"); JsonObject json1 = new JsonObject().put("foo1", "val1"); JsonObject json2 = new JsonObject().put("foo2", "val1"); JsonObject json3 = new JsonObject().put("foo3", "val1"); map.put(json1, "val1"); map.put(json2, "val2"); map.put(json3, "val3"); assertEquals(3, map.size()); Set<JsonObject> keys = map.keySet(); assertEquals(3, keys.size()); assertTrue(keys.contains(json1)); assertTrue(keys.contains(json2)); assertTrue(keys.contains(json3)); // copied assertFalse(containsExact(keys, json1)); assertFalse(containsExact(keys, json2)); assertFalse(containsExact(keys, json3)); }
@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 testKeysCopied() { LocalMap<JsonObject, String> map = sharedData.getLocalMap("foo"); JsonObject json1 = new JsonObject().put("foo1", "val1"); JsonObject json2 = new JsonObject().put("foo2", "val1"); JsonObject json3 = new JsonObject().put("foo3", "val1"); map.put(json1, "val1"); map.put(json2, "val2"); map.put(json3, "val3"); assertEquals(3, map.size()); Set<JsonObject> keys = map.keySet(); assertEquals(3, keys.size()); assertTrue(keys.contains(json1)); assertTrue(keys.contains(json2)); assertTrue(keys.contains(json3)); // copied assertFalse(containsExact(keys, json1)); assertFalse(containsExact(keys, json2)); assertFalse(containsExact(keys, json3)); }
@Override public List<Destination> getDestinations() { return new ArrayList<>(destinations.keySet()); }
@Override public void keys(Handler<AsyncResult<Set<K>>> resultHandler) { resultHandler.handle(Future.succeededFuture(map.keySet())); }
@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 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)); } }
/** * Gets the destination with the given name.. * * @param destination the destination * @return the {@link Destination}, {@code null} if not found. */ public Destination getDestination(String destination) { for (Destination d : destinations.keySet()) { if (d.matches(destination)) { return d; } } return null; }
public void clientIDExists(String clientID, Handler<Boolean> handler) { LocalMap<String, Object> m = vertx.sharedData().getLocalMap("clientIDs"); if(m!=null) { handler.handle(m.keySet().contains(clientID)); } else { handler.handle(false); } } public void removeClientID(String clientID) {
public void getClientIDs(Handler<Set<String>> handler) { LocalMap<String, Object> m = vertx.sharedData().getLocalMap(tenant + "persistence.clients"); handler.handle( m.keySet() ); }
private void resetRouterBrokenState() { if (getRouterStateMap().keySet().contains(ROUTER_BROKEN_KEY)) { log.info("reset router broken state. Routing is not broken anymore"); } getRouterStateMap().remove(ROUTER_BROKEN_KEY); }
/** get subscribed topics by clientID from session*/ public void getSubscriptionsByClientID(String clientID, Handler<List<Subscription>> handler) { ArrayList<Subscription> ret = new ArrayList<>(); LocalMap<String, Object> subscriptions = vertx.sharedData().getLocalMap(tenant + clientID); for(String item : subscriptions.keySet()) { Subscription s = new Subscription(); s.fromString(item); ret.add(s); } handler.handle(ret); }
private void decrementID(String k) { Integer currentID=0; LocalMap<String, Integer> seq = seq(); if(seq.keySet().contains(k)) { currentID = seq.get(k); if (currentID > 0) { seq.put(k, currentID - 1); } } }
private Integer currentID(String k) { Integer currentID=0; LocalMap<String, Integer> seq = seq(); if(!seq.keySet().contains(k)) { seq.put(k, 0); } currentID = seq.get(k); return currentID; } private void incrementID(String k) {
public void deleteMessage(String topic) { String key = topic; LocalMap<String, byte[]> map = vertx.sharedData().getLocalMap(tenant); if(map.keySet().contains(key)) { map.remove(key); } }
/** get and delete topic/message */ public void popMessage(String topic, String clientID, Handler<byte[]> handler) { String key = clientID+topic; String k = ""+currentID(key); LocalMap<String, byte[]> set = vertx.sharedData().getLocalMap(tenant + key); if(set.keySet().contains(k)) { byte[] removed = set.remove(k); decrementID(key); handler.handle( removed ); } else { handler.handle(null); } }
/** remove topic from session */ public void deleteSubcription(String topic, String clientID) { LocalMap<String, Object> subscriptionsMap = vertx.sharedData().getLocalMap(tenant + clientID); Set<String> subscriptions = subscriptionsMap.keySet(); Set<String> copyOfSubscriptions = new LinkedHashSet<>(subscriptions); for(String item : copyOfSubscriptions) { Subscription s = new Subscription(); s.fromString(item); if(s.getTopicFilter().equals(topic)) { subscriptions.remove(item); } } if(subscriptions.isEmpty()) { vertx.sharedData().getLocalMap(tenant + "persistence.clients").remove(clientID); } }