@Override public void setOperational(ProcessId processId) { operationalLocalProcesses.put(processId, true); operationalProcesses.put(new ClusterProcess(hzMember.getUuid(), processId), Boolean.TRUE); }
@Override public V put(K key, V value) { return map.put(key, value); }
@Override public V put(K key, V value) { return map.put(key, value); }
public void addClient(String clientId, String userName) { Properties props = new Properties(); props.setProperty(pn_schema_user, userName); clientsCache.put(clientId, props); }
private void put(Object oid, Exchange exchange) { Object body = exchange.getIn().getBody(); this.cache.put(oid, body); }
private static void executeReplicatedMap() { System.out.println("### ReplicatedMap Execution Started... ###"); int key = RANDOM.nextInt(100); int value = RANDOM.nextInt(100); ReplicatedMap<Integer, Integer> replicatedMap = (ReplicatedMap<Integer, Integer>) context .getBean("replicatedMap", ReplicatedMap.class); replicatedMap.put(key, value); System.out.println("A random pair is added to replicatedMap."); System.out.println("Added value: " + replicatedMap.get(key) + "\n"); }
private Collection<Index> getPathIndices(int pathId, String path) { Set<Index> result = new HashSet<>(1); Index idx = idxDict.get(pathId); if (idx != null) { result.add(idx); } else { if (!patterns.isEmpty()) { for (Map.Entry<Index, Pattern> e: patterns.entrySet()) { Matcher m = e.getValue().matcher(path); boolean match = m.matches(); if (match) { result.add(e.getKey()); // TODO: do we put multiple indexes for the same path?! think about it.. idxDict.put(pathId, e.getKey()); result.add(e.getKey()); } logger.trace("getPathIndexes; pattern {} {}matched for path {}", e.getValue().pattern(), match ? "" : "not ", path); } } } return result; }
@Override public void setOperational(ProcessId processId) { operationalLocalProcesses.put(processId, true); operationalProcesses.put(new ClusterProcess(hzMember.getUuid(), processId), Boolean.TRUE); }
@TimeStep(prob = 0.45) public void put(ThreadState state) { int key = state.randomInt(keyCount); String value = state.randomValue(); map.put(key, value); }
public static void main(String[] args) { // Start the Embedded Hazelcast Cluster Member. HazelcastInstance hz = Hazelcast.newHazelcastInstance(); // Get a Replicated Map called "my-replicated-map" ReplicatedMap<String, String> map = hz.getReplicatedMap("my-replicated-map"); // Put and Get a value from the Replicated Map // key/value replicated to all members map.put("key", "value"); // the value retrieved from local member map.get("key"); // Shutdown the Hazelcast Cluster Member hz.shutdown(); } }
public static void main(String[] args) { HazelcastInstance hz = Hazelcast.newHazelcastInstance(); ReplicatedMap<String, Person> binaryMap = hz.getReplicatedMap("binaryMap"); ReplicatedMap<String, Person> objectMap = hz.getReplicatedMap("objectMap"); Person person = new Person(); binaryMap.put("peter", person); objectMap.put("peter", person); System.out.println(person == binaryMap.get("peter")); System.out.println(binaryMap.get("peter") == binaryMap.get("peter")); System.out.println(person == objectMap.get("peter")); System.out.println(objectMap.get("peter") == objectMap.get("peter")); hz.shutdown(); }
private void addClient(final ClientContainer cc, final String clientId, Properties props) { HazelcastInstance hzClient = cc.hzInstance; if (cc.addClient(clientId)) { ReplicatedMap<String, Properties> clientProps = hzClient.getReplicatedMap(CN_XDM_CLIENT); HazelcastClientProxy proxy = (HazelcastClientProxy) hzClient; props.setProperty(pn_client_memberId, proxy.client.getClientClusterService().getLocalClient().getUuid()); props.setProperty(pn_client_connectedAt, new java.util.Date(proxy.getCluster().getClusterTime()).toString()); clientProps.put(clientId, props); logger.debug("addClient; got new connection for clientId: {}", clientId); } else { logger.trace("addClient; got existing connection for clientId: {}", clientId); } }
private boolean addQuery(Query query) { Integer qKey = getQueryKey(query.getQuery()); //logger.trace("addQuery.enter; got code: {}; query cache size: {}", qCode, xQueries.size()); //boolean result = xqCache.putIfAbsent(qCode, new XDMQuery(query, readOnly, xdmQuery)) == null; if (!xqCache.containsKey(qKey)) { // throws exception: Failed to serialize 'com.bagri.core.model.Query' try { xqCache.put(qKey, query); } catch (Exception ex) { logger.error("addQuery.error", ex); } return true; } return false; }
public static void main(String[] args) { // Start the Hazelcast Client and connect to an already running Hazelcast Cluster on 127.0.0.1 HazelcastInstance hz = HazelcastClient.newHazelcastClient(); // Get a Replicated Map called "my-replicated-map" ReplicatedMap<String, String> map = hz.getReplicatedMap("my-replicated-map"); // Put and Get a value from the Replicated Map String replacedValue = map.put("key", "value"); // key/value replicated to all members System.out.println("replacedValue = " + replacedValue); // Will be null as its first update String value = map.get("key"); // the value is retrieved from a random member in the cluster System.out.println("value for key = " + value); // Shutdown this Hazelcast Client hz.shutdown(); } }
@TimeStep(prob = 0.7) public void putTTL(ThreadState state) { try { int key = state.randomInt(keyCount); int value = state.randomInt(); int delayMs = minTTLExpiryMs; if (maxTTLExpiryMs > 0) { delayMs += state.randomInt(maxTTLExpiryMs); } map.put(key, value, delayMs, TimeUnit.MILLISECONDS); state.count.putTTLCount.incrementAndGet(); } catch (DistributedObjectDestroyedException e) { EmptyStatement.ignore(e); } }
@Override protected void doRegister(URL url) { if (logger.isInfoEnabled()) { logger.info("Register: " + url); } Set<String> urls = replicatedMap.get(nodeId); urls.add(url.toFullString()); ILock lock = hazelcastInstance.getLock(nodeId); lock.lock(); try { replicatedMap.put(nodeId, urls); } finally { lock.unlock(); } }
public static void testEventDrivenForReplicatedMapEntryEvents( final ReplicatedMap<Integer, HazelcastIntegrationTestUser> replicatedMap, final PollableChannel channel, final String cacheName) { replicatedMap .put(1, new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1")); Message<?> msg = channel.receive(TIMEOUT); verifyEntryEvent(msg, cacheName, EntryEventType.ADDED); replicatedMap.put(1, new HazelcastIntegrationTestUser(1, "TestName1", "TestSurnameUpdated")); msg = channel.receive(TIMEOUT); verifyEntryEvent(msg, cacheName, EntryEventType.UPDATED); replicatedMap.remove(1); msg = channel.receive(TIMEOUT); verifyEntryEvent(msg, cacheName, EntryEventType.REMOVED); replicatedMap .put(2, new HazelcastIntegrationTestUser(2, "TestName2", "TestSurname2")); msg = channel.receive(TIMEOUT); verifyEntryEvent(msg, cacheName, EntryEventType.ADDED); }
@Test public void testEventDrivenForOnlyREMOVEDEntryEvent() { edReplicatedMap3 .put(1, new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1")); edReplicatedMap3 .put(2, new HazelcastIntegrationTestUser(2, "TestName2", "TestSurname2")); edReplicatedMap3.remove(2); Message<?> msg = edReplicatedMapChannel3 .receive(HazelcastInboundChannelAdapterTestUtils.TIMEOUT); Assert.assertNotNull(msg); Assert.assertNotNull(msg.getPayload()); Assert.assertTrue(msg.getPayload() instanceof EntryEventMessagePayload); Assert.assertNotNull(msg.getHeaders().get(HazelcastHeaders.MEMBER)); Assert.assertEquals(EntryEventType.REMOVED.name(), msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE)); Assert.assertEquals("edReplicatedMap3", msg.getHeaders().get(HazelcastHeaders.CACHE_NAME)); Assert.assertEquals(Integer.valueOf(2), ((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg .getPayload()).key); Assert.assertEquals(2, (((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg .getPayload()).oldValue).getId()); Assert.assertEquals("TestName2", (((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg .getPayload()).oldValue).getName()); Assert.assertEquals("TestSurname2", (((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg .getPayload()).oldValue).getSurname()); }
@Test public void testEventDrivenForOnlyADDEDEntryEvent() { edReplicatedMap1 .put(1, new HazelcastIntegrationTestUser(1, "TestName1", "TestSurname1")); Message<?> msg = edReplicatedMapChannel1 .receive(HazelcastInboundChannelAdapterTestUtils.TIMEOUT); Assert.assertNotNull(msg); Assert.assertNotNull(msg.getPayload()); Assert.assertTrue(msg.getPayload() instanceof EntryEventMessagePayload); Assert.assertNotNull(msg.getHeaders().get(HazelcastHeaders.MEMBER)); Assert.assertEquals(EntryEventType.ADDED.name(), msg.getHeaders().get(HazelcastHeaders.EVENT_TYPE)); Assert.assertEquals("edReplicatedMap1", msg.getHeaders().get(HazelcastHeaders.CACHE_NAME)); Assert.assertEquals(Integer.valueOf(1), ((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg .getPayload()).key); Assert.assertEquals(1, (((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg .getPayload()).value).getId()); Assert.assertEquals("TestName1", (((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg .getPayload()).value).getName()); Assert.assertEquals("TestSurname1", (((EntryEventMessagePayload<Integer, HazelcastIntegrationTestUser>) msg .getPayload()).value).getSurname()); }