public static void main(String[] args) { // Start the Embedded Hazelcast Cluster Member. HazelcastInstance hz = Hazelcast.newHazelcastInstance(); // Get the Distributed MultiMap from Cluster. MultiMap<String, String> multiMap = hz.getMultiMap("my-distributed-multimap"); // Put values in the map against the same key multiMap.put("my-key", "value1"); multiMap.put("my-key", "value2"); multiMap.put("my-key", "value3"); // Print out all the values for associated with key called "my-key" Collection<String> values = multiMap.get("my-key"); System.out.println(values); // remove specific key/value pair multiMap.remove("my-key", "value2"); // Shutdown the Hazelcast Cluster Member hz.shutdown(); } }
private static void executeMultiMap() { System.out.println("### MultiMap Execution Started... ###"); int key = RANDOM.nextInt(100); int value = RANDOM.nextInt(100); MultiMap<Integer, Integer> multimap = (MultiMap<Integer, Integer>) context.getBean("multiMap", MultiMap.class); multimap.put(key, value); System.out.println("A random pair is added to multiMap."); System.out.println("Added value: " + multimap.get(key) + "\n"); }
private boolean isEventComingFromNonRegisteredHazelcastInstance( final HazelcastInstance hazelcastInstance, final Set<SocketAddress> localSocketAddressesSet, final InetSocketAddress socketAddressOfEvent) { final MultiMap<SocketAddress, SocketAddress> configMultiMap = hazelcastInstance .getMultiMap(HazelcastLocalInstanceRegistrar.SPRING_INTEGRATION_INTERNAL_CLUSTER_MULTIMAP); return configMultiMap.size() > 0 && !configMultiMap.values().contains(socketAddressOfEvent) && localSocketAddressesSet.contains(configMultiMap.keySet().iterator().next()); }
protected void handleSize(String[] args) { int size = 0; String iteratorStr = args[0]; if (iteratorStr.startsWith("s.")) { size = getSet().size(); } else if (iteratorStr.startsWith("m.")) { size = getMap().size(); } else if (iteratorStr.startsWith("mm.")) { size = getMultiMap().size(); } else if (iteratorStr.startsWith("q.")) { size = getQueue().size(); } else if (iteratorStr.startsWith("l.")) { size = getList().size(); } println("Size = " + size); }
protected void handleContains(String[] args) { String iteratorStr = args[0]; boolean key = lowerCaseInternal(iteratorStr).endsWith("key"); String data = args[1]; boolean result = false; if (iteratorStr.startsWith("s.")) { result = getSet().contains(data); } else if (iteratorStr.startsWith("m.")) { result = (key) ? getMap().containsKey(data) : getMap().containsValue(data); } else if (iteratorStr.startsWith("mmm.")) { result = (key) ? getMultiMap().containsKey(data) : getMultiMap().containsValue(data); } else if (iteratorStr.startsWith("q.")) { result = getQueue().contains(data); } else if (iteratorStr.startsWith("l.")) { result = getList().contains(data); } println("Contains: " + result); }
protected void handleClear(String[] args) { String iteratorStr = args[0]; if (iteratorStr.startsWith("s.")) { getSet().clear(); } else if (iteratorStr.startsWith("m.")) { getMap().clear(); } else if (iteratorStr.startsWith("mm.")) { getMultiMap().clear(); } else if (iteratorStr.startsWith("q.")) { getQueue().clear(); } else if (iteratorStr.startsWith("l.")) { getList().clear(); } println("Cleared all."); }
protected void handleAddListener(String[] args) { String first = args[0]; if (first.startsWith("s.")) { getSet().addItemListener(this, true); } else if (first.startsWith("m.")) { if (args.length > 1) { getMap().addEntryListener(this, args[1], true); } else { getMap().addEntryListener(this, true); } } else if (first.startsWith("mm.")) { if (args.length > 1) { getMultiMap().addEntryListener(this, args[1], true); } else { getMultiMap().addEntryListener(this, true); } } else if (first.startsWith("q.")) { getQueue().addItemListener(this, true); } else if (first.startsWith("t.")) { getTopic().addMessageListener(this); } else if (first.startsWith("l.")) { getList().addItemListener(this, true); } }
it = getSet().iterator(); } else if (iteratorStr.startsWith("m.")) { it = getMap().keySet().iterator(); } else if (iteratorStr.startsWith("mm.")) { it = getMultiMap().keySet().iterator(); } else if (iteratorStr.startsWith("q.")) { it = getQueue().iterator(); } else if (iteratorStr.startsWith("l.")) { it = getList().iterator();
public void run() { map.put(key, new byte[valueSize]); } });
.getMultiMap(HazelcastLocalInstanceRegistrar.SPRING_INTEGRATION_INTERNAL_CLUSTER_MULTIMAP); if (configMultiMap.containsKey(removedMemberSocketAddress)) { SocketAddress newAdminSocketAddress = getNewAdminInstanceSocketAddress( configMultiMap, removedMemberSocketAddress); for (SocketAddress socketAddress : configMultiMap.values()) { if (!socketAddress.equals(removedMemberSocketAddress)) { configMultiMap.put(newAdminSocketAddress, socketAddress); configMultiMap.remove(removedMemberSocketAddress); configMultiMap.remove(configMultiMap.keySet().iterator().next(), removedMemberSocketAddress);
public Collection<HazelcastServerID> action() throws Exception { return map.get(subName); } }.run();
private void delete(Object oid) { this.cache.remove(oid); }
public static void testEventDrivenForMultiMapEntryEvents( final MultiMap<Integer, HazelcastIntegrationTestUser> multiMap, final PollableChannel channel, final String cacheName) { multiMap.put(1, new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1")); Message<?> msg = channel.receive(TIMEOUT); verifyEntryEvent(msg, cacheName, EntryEventType.ADDED); multiMap.put(1, new HazelcastIntegrationTestUser(1, "TestName1", "TestSurnameUpdated")); msg = channel.receive(TIMEOUT); verifyEntryEvent(msg, cacheName, EntryEventType.ADDED); multiMap.remove(1); msg = channel.receive(TIMEOUT); verifyEntryEvent(msg, cacheName, EntryEventType.REMOVED); msg = channel.receive(TIMEOUT); verifyEntryEvent(msg, cacheName, EntryEventType.REMOVED); multiMap.put(2, new HazelcastIntegrationTestUser(2, "TestName2", "TestSurname2")); msg = channel.receive(TIMEOUT); verifyEntryEvent(msg, cacheName, EntryEventType.ADDED); multiMap.clear(); msg = channel.receive(TIMEOUT); verifyEntryEvent(msg, cacheName, EntryEventType.CLEAR_ALL); }
private void syncConfigurationMultiMap(HazelcastInstance hazelcastInstance) { Lock lock = hazelcastInstance.getLock(SPRING_INTEGRATION_INTERNAL_CLUSTER_LOCK); lock.lock(); try { MultiMap<SocketAddress, SocketAddress> multiMap = hazelcastInstance .getMultiMap(SPRING_INTEGRATION_INTERNAL_CLUSTER_MULTIMAP); for (HazelcastInstance localInstance : Hazelcast.getAllHazelcastInstances()) { SocketAddress localInstanceSocketAddress = localInstance.getLocalEndpoint().getSocketAddress(); if (multiMap.size() == 0) { multiMap.put(localInstanceSocketAddress, localInstanceSocketAddress); } else { multiMap.put(multiMap.keySet().iterator().next(), localInstanceSocketAddress); } } } finally { lock.unlock(); } }
private static void verifyMultiMapForPayload( final MultiMap<Integer, HazelcastIntegrationTestUser> multiMap) { int index = 1; assertNotNull(multiMap); assertEquals(true, multiMap.size() == DATA_COUNT); SortedSet<Integer> keys = new TreeSet<>(multiMap.keySet()); for (Integer key : keys) { assertNotNull(key); assertEquals(index, key.intValue()); HazelcastIntegrationTestUser user = multiMap.get(key).iterator().next(); verifyHazelcastIntegrationTestUser(user, index); index++; } }
@Override public List<String> getJobGroupNames() throws JobPersistenceException { return newArrayList(jobsByGroup.keySet()); }