private boolean removeClient(String clientId) { String qName = "client:" + clientId; boolean removed = false; java.util.Collection<DistributedObject> all = hzInstance.getDistributedObjects(); int sizeBefore = all.size(); for (DistributedObject obj: all) { if (qName.equals(obj.getName()) && QueueService.SERVICE_NAME.equals(obj.getServiceName())) { // remove queue obj.destroy(); removed = true; break; } } int sizeAfter = hzInstance.getDistributedObjects().size(); logger.debug("removeClient.exit; queue {} {} for client: {}; size before: {}, after: {}", qName, removed ? "destroyed" : "skipped", clientId, sizeBefore, sizeAfter); return removed; }
@After public void tearDown() { for (String mapName : TestConstants.OSCAR_MAP_NAMES) { IMap<String, ?> iMap = this.hazelcastInstance.getMap(mapName); iMap.clear(); } checkMapsEmpty("tearDown"); Collection<DistributedObject> distributedObjects = this.hazelcastInstance.getDistributedObjects(); for (DistributedObject distributedObject : distributedObjects) { assertThat(distributedObject.getName(), distributedObject, instanceOf(IMap.class)); assertThat(distributedObject.getName(), isIn(TestConstants.OSCAR_MAP_NAMES)); } assertThat("Correct number of distributed objects", distributedObjects.size(), equalTo(TestConstants.OSCAR_MAP_NAMES.length)); }
@Verify public void verify() { String serviceName = totalCounter.getServiceName(); String totalName = totalCounter.getName(); long actual = 0; for (DistributedObject distributedObject : targetInstance.getDistributedObjects()) { String key = distributedObject.getName(); if (serviceName.equals(distributedObject.getServiceName()) && key.startsWith(name) && !key.equals(totalName)) { actual += targetInstance.getAtomicLong(key).get(); } } assertEquals(totalCounter.get(), actual); }
public List<String> getMapNames() { return hazelcastInstance .getDistributedObjects() .stream() .filter(e -> e.getServiceName().equals(MapService.SERVICE_NAME)) .map(DistributedObject::getName) .collect(Collectors.toList()); }
public void clearAllCaches(){ final Collection<DistributedObject> distributedObjects = hazelcastInstance.getDistributedObjects(); for (DistributedObject distributedObject : distributedObjects) { if (distributedObject instanceof IMap) { final IMap<?, ?> map = (IMap) distributedObject; map.clear(); } } }
public void clearAllCachesExcept(List<String> cacheRegions){ final Collection<DistributedObject> distributedObjects = hazelcastInstance.getDistributedObjects(); for (DistributedObject distributedObject : distributedObjects) { if (distributedObject instanceof IMap) { final IMap<?, ?> map = (IMap) distributedObject; String region = map.getName(); boolean exists = cacheRegions.stream().filter(s->region.contains(s)).count()>0; if(!exists) { map.clear(); } } } }
@RequestMapping(method = RequestMethod.GET) public ResponseEntity<?> read(@RequestBody(required = false) String input) { StringBuilder sb = new StringBuilder(); sb.append("{"); for (HazelcastInstance hazelInst : Hazelcast.getAllHazelcastInstances()) { Iterator<Member> iter = hazelInst.getCluster().getMembers().iterator(); while (iter.hasNext()) { sb.append("\"member\": \""); sb.append(iter.next().getAddress()); sb.append("\""); } sb.append(",\"name\": \""); sb.append(hazelInst.getName()); sb.append("\""); // IMap map = hz.getMap( "test" ); Collection<DistributedObject> objects = hazelInst.getDistributedObjects(); for (DistributedObject distributedObject : objects) { if (distributedObject instanceof IMap) { sb.append(",\"mapName\": \""); sb.append(distributedObject.getName()); sb.append("\""); } } } sb.append("}"); return ResponseEntity.ok(sb.toString()); }
public static void sendDashboardNotificationEventIfExists(DashboardNotificationEvent dashboardNotificationEvent) { Collection<DistributedObject> instances = hazelcastInstance.getDistributedObjects(); for (DistributedObject instance : instances) { if (instance.getServiceName().equals("hz:impl:topicService") && instance.getName().equals(dashboardNotificationEvent.getReceiverName())) { sendDashboardNotificationEvent(dashboardNotificationEvent); } } }
/** * Reads an entry from the multi-map * invoke: HzClient.readValuesFromMultiMap("my-distributed-map", "sample-key"); * * @return the values of the entry. */ public static Collection<DistributedObject> getDistributedObjects() { Collection<DistributedObject> distributedObjects = clientInstance.getDistributedObjects(); for (DistributedObject distributedObject: distributedObjects) { logger.info(distributedObject.getName()); } return distributedObjects; }
@Override public Iterable<String> getCacheNames() { if (this.hcInstance != null) { Collection<DistributedObject> distributedObjects = hcInstance.getDistributedObjects(); ArrayList<String> names = new ArrayList<String>(distributedObjects.size()); for (DistributedObject distributedObject : distributedObjects) { names.add(distributedObject.getName()); } return names; } else { return new ArrayList<String>(0); } }
@Override public void resetCachers() { if (!getSecurityService().isSuperUser()) { throw new SecurityException("Only super admin can reset cachers, current user not super admin"); } if (this.hcInstance != null) { Collection<DistributedObject> distributedObjects = hcInstance.getDistributedObjects(); for (DistributedObject distributedObject : distributedObjects) { if (distributedObject instanceof IMap) { ((IMap)distributedObject).clear(); } } } }
private boolean findDistributedObject(String serviceName, String objectName) { HazelcastInstance hzi = ((SchemaRepositoryImpl) xRepo).getHzInstance(); for (DistributedObject svc: hzi.getDistributedObjects()) { if (objectName.equals(svc.getName())) { if (serviceName == null) { return true; } else if (serviceName.equals(svc.getServiceName())) { return true; } } } return false; }
@Before public void setUp() { assertThat("Correct Hazelcast instance", this.hazelcastInstance.getName(), equalTo(Constants.HAZELCAST_INSTANCE_NAME)); checkMapsEmpty("setUp"); this.makeupMap = this.hazelcastInstance.getMap(TestConstants.MAKEUP_MAP_NAME); loadMakeup(this.makeupMap); this.movieMap = this.hazelcastInstance.getMap(TestConstants.MOVIE_MAP_NAME); loadMovie(this.movieMap); this.personMap = this.hazelcastInstance.getMap(TestConstants.PERSON_MAP_NAME); loadPerson(this.personMap); this.songMap = this.hazelcastInstance.getMap(TestConstants.SONG_MAP_NAME); loadSong(this.songMap); checkMapsNotEmpty("setUp"); /* As Hazelcast will create objects on demand, check no more are present * than should be. */ Collection<DistributedObject> distributedObjects = this.hazelcastInstance.getDistributedObjects(); assertThat("Correct number of distributed objects", distributedObjects.size(), equalTo(TestConstants.OSCAR_MAP_NAMES.length)); }
@Verify public void verify() { if (isClient(targetInstance)) { return; } final String serviceName = totalCounter.getServiceName(); final long expected = totalCounter.get(); // since the operations are asynchronous, we have no idea when they complete assertTrueEventually(new AssertTask() { @Override public void run() throws Exception { // hack to prevent overloading the system with get calls, else it is done many times a second sleepSeconds(10); long actual = 0; for (DistributedObject distributedObject : targetInstance.getDistributedObjects()) { String key = distributedObject.getName(); if (serviceName.equals(distributedObject.getServiceName()) && key.startsWith(name)) { actual += targetInstance.getAtomicLong(key).get(); } } assertEquals(expected, actual); } }, assertEventuallySeconds); }
@Override public void subscribe(final HazelcastInstance hzInstance,final HzEventBusTerminal terminal) { m_hzInstance = hzInstance; m_terminal = terminal; if(m_terminal != null && m_hzInstance != null) { m_hzInstance.addDistributedObjectListener(this); } for(DistributedObject object : m_hzInstance.getDistributedObjects()) { if(object instanceof ITopic) { subscribeTopic(object); } } }
@Override public void unsubscribe(final HazelcastInstance hzInstance,final HzEventBusTerminal terminal) { for(DistributedObject object : hzInstance.getDistributedObjects()) { if(object instanceof ITopic) { unsubscribeTopic(object); } } m_hzInstance = null; m_terminal = null; }
@Override @SuppressWarnings("uncheked") public void distributedObjectCreated(DistributedObjectEvent event) { DistributedObject object = event.getDistributedObject(); if(object instanceof ITopic) { subscribeTopic(object); } }
@Override @SuppressWarnings("uncheked") public void distributedObjectDestroyed(DistributedObjectEvent event) { DistributedObject object = event.getDistributedObject(); if(object instanceof ITopic) { unsubscribeTopic(object); } }
/** * * @param object the objects */ @SuppressWarnings("unchecked") private void subscribeTopic(DistributedObject object) { String name = object.getName(); for(String topicName : m_topicNames) { if(name.matches(topicName)) { LOGGER.debug("Subscribing to <{}>",name); m_subKeys.put( topicName, ((ITopic<EventMessage>) object).addMessageListener(m_terminal)); } } }
/** * * @param object the objects */ @SuppressWarnings("unchecked") private void unsubscribeTopic(DistributedObject object) { String name = object.getName(); for(String topicName : m_topicNames) { if(name.matches(topicName)) { LOGGER.debug("Unsubscribing from <{}>",name); String key = m_subKeys.remove(topicName); if(StringUtils.isNotEmpty(key)) { ((ITopic<EventMessage>)object).removeMessageListener(key); } } } }
@Override public Collection<DistributedObject> getDistributedObjects() { return null; }
@Override public <T extends DistributedObject> T getDistributedObject(String s, String s1) { return null; }
@AfterEach void afterEach() { hz.getDistributedObjects().forEach(DistributedObject::destroy); }
@Nonnull @Override public DistributedObject createDistributedObject(@Nonnull String objectName) { return new DummyProxy(objectName); }
@Override public DistributedObject createDistributedObject(String objectId) { return new TreeSetProxyImpl(objectId, nodeEngine, this); }
@Override public DistributedObject createDistributedObject(String objectName) { return new LocalCacheProxy(objectName, nodeEngine, this); }
@Override public Collection<DistributedObject> getDistributedObjects() { return getHazelcastInstance().getDistributedObjects(); }
@Override public <T extends DistributedObject> T getDistributedObject(final String serviceName, final Object id) { throw new DeprecatedError(); }
@Override public <T extends DistributedObject> T getDistributedObject(final String serviceName, final String name) { return getHazelcastInstance().getDistributedObject(serviceName, name); }