// works for 3.7 Collection<DistributedObject> distributedObjects = hazelcastInstance.getDistributedObjects(); for (DistributedObject distributedObject : distributedObjects) { if (distributedObject instanceof ICache) { System.out.println("Found cache with name " + distributedObject.getName()); } }
private static void validateCacheEventsByDistributedObject(DistributedObject distributedObject, Set<String> cacheEventTypeSet, List<String> supportedCacheEventTypes) { if (!supportedCacheEventTypes.containsAll(cacheEventTypeSet)) { throw new IllegalArgumentException("'cache-events' attribute of " + distributedObject.getName() + " can be set as " + supportedCacheEventTypes); } }
@Override public final String getName() { return getDistributedObject().getName(); }
@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); } }
@SuppressWarnings({"unchecked", "rawtypes"}) @CliCommand(value = "LIST", help = "List map keys") public void listIMaps() { Set<String> iMapNames = this.hazelcastInstance.getDistributedObjects().stream() .filter(distributedObject -> distributedObject instanceof IMap) .filter(distributedObject -> !distributedObject.getName().startsWith(Jet.INTERNAL_JET_OBJECTS_PREFIX)) .map(distributedObject -> distributedObject.getName()).collect(Collectors.toCollection(TreeSet::new)); iMapNames.stream().forEach(name -> { IMap<?, ?> iMap = this.hazelcastInstance.getMap(name); System.out.println(""); System.out.printf("IMap: '%s'%n", name); // Sort if possible Set<?> keys = iMap.keySet(); if (!keys.isEmpty() && keys.iterator().next() instanceof Comparable) { keys = new TreeSet(keys); } keys.stream().forEach(key -> { System.out.printf(" -> '%s' -> %s%n", key, iMap.get(key)); }); System.out.printf("[%d entr%s]%n", iMap.size(), (iMap.size() == 1 ? "y" : "ies")); }); System.out.println(""); }
return ((PrefixedDistributedObject) distributedObject).getPrefixedName(); } else { return distributedObject.getName();
return ((PrefixedDistributedObject) distributedObject).getPrefixedName(); } else { return distributedObject.getName();
/** * List the distributed objects in the grid. */ @SuppressWarnings("resource") @CliCommand(value = "list", help = "List distributed objects") public void list() { log.info("-----------------------"); Collection<DistributedObject> distributedObjects = this.hazelcastInstance.getDistributedObjects(); for (DistributedObject distributedObject : distributedObjects) { log.info("Distributed Object => name '{}'", distributedObject.getName()); if (distributedObject instanceof ICache) { ICache<?, ?> iCache = (ICache<?, ?>) distributedObject; log.info(" -> ICACHE => size {}", iCache.size()); } } if (distributedObjects.size() > 0) { log.info("-----------------------"); } log.info("[{} distributed object{}]", distributedObjects.size(), (distributedObjects.size() == 1 ? "" : "s") ); log.info("-----------------------"); } }
Set<String> iMapNames = this.hazelcastInstance.getDistributedObjects().stream() .filter(distributedObject -> distributedObject instanceof IMap) .filter(distributedObject -> !distributedObject.getName().startsWith(Jet.INTERNAL_JET_OBJECTS_PREFIX)) .map(distributedObject -> distributedObject.getName()).collect(Collectors.toCollection(TreeSet::new));
log.error(distributedObject.getName(), e);
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(); boolean r2 = repo.removeXQProcessor(clientId); logger.debug("removeClient.exit; queue {} {} for client: {}; size before: {}, after: {}; processor removed: {}", qName, removed ? "destroyed" : "skipped", clientId, sizeBefore, sizeAfter, r2); return removed; }
String distributedObjectName = distributedObject.getName(); String distributedObjectServiceName = distributedObject.getServiceName();
for (DistributedObject distributedObject : distributedObjects) { if (distributedObject instanceof IMap) { caches.put(distributedObject.getName(), (IMap) distributedObject);
Partition partition = partitionService.getPartition(distObj.getName()); if (partition.getOwner().localMember()) {
@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);
@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 static void main(String[] args) { Config config = new Config().addCacheConfig(createCacheSimpleConfig(BASE_CACHE_NAME + "_1")); HazelcastInstance instance = Hazelcast.newHazelcastInstance(config); CachingProvider cachingProvider = HazelcastServerCachingProvider.createCachingProvider(instance); CacheManager cacheManager = cachingProvider.getCacheManager(); // ICacheManager is Hazelcast-specific interface, not to be confused with JCache's CacheManager. // An instance of the ICacheManager can be obtained from a HazelcastInstance and used to get // a reference to an existing cache. ICacheManager hazelcastCacheManager = instance.getCacheManager(); ICache cache1 = hazelcastCacheManager.getCache(BASE_CACHE_NAME + "_1"); ICache cache2a = (ICache) cacheManager.createCache(BASE_CACHE_NAME + "_2", new CacheConfig(BASE_CACHE_NAME + "_2")); ICache cache2b = hazelcastCacheManager.getCache(BASE_CACHE_NAME + "_2"); System.out.println("cache2a (through CacheManager) == cache2b (through HazelcastInstance): " + (cache2a == cache2b)); System.out.println("Distributed objects before destroy:"); for (DistributedObject distributedObject : instance.getDistributedObjects()) { System.out.println("\t- Distributed object with name " + distributedObject.getName()); } cache1.destroy(); cache2a.destroy(); System.out.println("Distributed objects after destroy:"); for (DistributedObject distributedObject : instance.getDistributedObjects()) { System.out.println("\tDistributed object with name " + distributedObject.getName()); } instance.shutdown(); }
private static void verifyDistributedObjectEvent(final Message<?> msg, final DistributedObjectEvent.EventType eventType, final String distributedObjectName) { assertNotNull(msg); assertNotNull(msg.getPayload()); assertTrue(msg.getPayload() instanceof DistributedObjectEvent); assertEquals(eventType, ((DistributedObjectEvent) msg.getPayload()).getEventType()); assertNotNull((((DistributedObjectEvent) msg.getPayload()).getDistributedObject()) .getName(), distributedObjectName); }
@Override public Collection<DistributedObject> getDistributedObjects() { try { ClientMessage request = ClientGetDistributedObjectsCodec.encodeRequest(); final Future<ClientMessage> future = new ClientInvocation(this, request, getName()).invoke(); ClientMessage response = future.get(); ClientGetDistributedObjectsCodec.ResponseParameters resultParameters = ClientGetDistributedObjectsCodec.decodeResponse(response); Collection<? extends DistributedObject> distributedObjects = proxyManager.getDistributedObjects(); Set<DistributedObjectInfo> localDistributedObjects = new HashSet<DistributedObjectInfo>(); for (DistributedObject localInfo : distributedObjects) { localDistributedObjects.add(new DistributedObjectInfo(localInfo.getServiceName(), localInfo.getName())); } Collection<DistributedObjectInfo> newDistributedObjectInfo = resultParameters.response; for (DistributedObjectInfo distributedObjectInfo : newDistributedObjectInfo) { localDistributedObjects.remove(distributedObjectInfo); getDistributedObject(distributedObjectInfo.getServiceName(), distributedObjectInfo.getName()); } for (DistributedObjectInfo distributedObjectInfo : localDistributedObjects) { proxyManager.destroyProxyLocally(distributedObjectInfo.getServiceName(), distributedObjectInfo.getName()); } return (Collection<DistributedObject>) proxyManager.getDistributedObjects(); } catch (Exception e) { throw rethrow(e); } }
@Override public Collection<DistributedObject> getDistributedObjects() { try { ClientMessage request = ClientGetDistributedObjectsCodec.encodeRequest(); final Future<ClientMessage> future = new ClientInvocation(this, request, getName()).invoke(); ClientMessage response = future.get(); ClientGetDistributedObjectsCodec.ResponseParameters resultParameters = ClientGetDistributedObjectsCodec.decodeResponse(response); Collection<? extends DistributedObject> distributedObjects = proxyManager.getDistributedObjects(); Set<DistributedObjectInfo> localDistributedObjects = new HashSet<DistributedObjectInfo>(); for (DistributedObject localInfo : distributedObjects) { localDistributedObjects.add(new DistributedObjectInfo(localInfo.getServiceName(), localInfo.getName())); } Collection<DistributedObjectInfo> newDistributedObjectInfo = resultParameters.response; for (DistributedObjectInfo distributedObjectInfo : newDistributedObjectInfo) { localDistributedObjects.remove(distributedObjectInfo); getDistributedObject(distributedObjectInfo.getServiceName(), distributedObjectInfo.getName()); } for (DistributedObjectInfo distributedObjectInfo : localDistributedObjects) { proxyManager.destroyProxyLocally(distributedObjectInfo.getServiceName(), distributedObjectInfo.getName()); } return (Collection<DistributedObject>) proxyManager.getDistributedObjects(); } catch (Exception e) { throw rethrow(e); } }