@Override public void setOperational(ProcessId processId) { operationalLocalProcesses.put(processId, true); operationalProcesses.put(new ClusterProcess(hzMember.getUuid(), processId), Boolean.TRUE); }
@Override public void close() { esConnector.stop(); if (hzMember != null) { if (healthStateSharing != null) { healthStateSharing.stop(); } try { // Removing listeners operationalProcesses.removeEntryListener(operationalProcessListenerUUID); hzMember.getCluster().removeMembershipListener(nodeDisconnectedListenerUUID); // Removing the operationalProcess from the replicated map operationalProcesses.keySet().forEach( clusterNodeProcess -> { if (clusterNodeProcess.getNodeUuid().equals(hzMember.getUuid())) { operationalProcesses.remove(clusterNodeProcess); } }); // Shutdown Hazelcast properly hzMember.close(); } catch (HazelcastInstanceNotActiveException e) { // hazelcastCluster may be already closed by the shutdown hook LOGGER.debug("Unable to close Hazelcast cluster", e); } } }
public ClusterAppStateImpl(AppSettings settings, HazelcastMember hzMember, EsConnector esConnector) { this.hzMember = hzMember; // Get or create the replicated map operationalProcesses = (ReplicatedMap) hzMember.getReplicatedMap(OPERATIONAL_PROCESSES); operationalProcessListenerUUID = operationalProcesses.addEntryListener(new OperationalProcessListener()); nodeDisconnectedListenerUUID = hzMember.getCluster().addMembershipListener(new NodeDisconnectedListener()); if (ClusterSettings.isLocalElasticsearchEnabled(settings)) { this.healthStateSharing = new HealthStateSharingImpl(hzMember, new SearchNodeHealthProvider(settings.getProps(), this, NetworkUtilsImpl.INSTANCE)); this.healthStateSharing.start(); } this.esConnector = esConnector; }
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"); }
@Override public V get(K key) { return map.get(key); }
public void removeQueries(Set<Integer> qKeys) { for (Integer qKey: qKeys) { xqCache.remove(qKey); } }
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; }
this.replicatedMap = hazelcastInstance.getReplicatedMap(username+"-dubbo-registered"); this.nodeId = hazelcastInstance.getCluster().getLocalMember().getUuid(); replicatedMap.put(nodeId, new LinkedHashSet<String>()); replicatedMap.addEntryListener(new EntryAdapter<String, Set<String>>() { @Override public void onEntryEvent(EntryEvent<String, Set<String>> event) {
@Override public void clientDisconnected(Client client) { String clientId = client.getUuid(); logger.trace("clientDisconnected.enter; client: {}", clientId); // check and destroy client's resources for (Map.Entry<String, Properties> entry: clientsCache.entrySet()) { Properties props = entry.getValue(); String uuid = props.getProperty(pn_client_memberId); if (clientId.equals(uuid)) { clientsCache.remove(entry.getKey()); } } }
@Override public void clear() { map.clear(); }
public Set<Integer> getQueriesForPaths(Collection<Integer> pathIds, boolean checkIndexed) { // TODO: also specify: do we care about unique indexes or not.. logger.trace("getQueriesForPaths.enter; got pathIds: {}; query cache size: {}", pathIds, xqCache.size()); Set<Integer> result = new HashSet<>(); for (Map.Entry<Integer, Query> e: xqCache.entrySet()) { if (intersects(e.getValue(), pathIds, checkIndexed)) { result.add(e.getKey()); } } logger.trace("getQueriesForPaths.exit; returning: {}", result); return result; }
@Override public boolean isPathIndexed(int pathId) { // how near cache does works on cache miss!? does is go to // original cache? // shouldn't we also check index.isEnabled() here? //return idxDict.get(pathId) != null; return idxDict.containsKey(pathId); }
@Override public int size() { return map.size(); }
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(); }
@Override public V get(K key) { return map.get(key); }
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); }
public V remove(K key) { return map.remove(key); }
@Override public void clear() { map.clear(); }
@Override public boolean containsKey(K key) { return map.containsKey(key); }