com.hazelcast.core.DistributedObject Java Examples

The following examples show how to use com.hazelcast.core.DistributedObject. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestDataHelper.java    From spring-data-hazelcast with Apache License 2.0 6 votes vote down vote up
@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));

}
 
Example #2
Source File: AtomicLongTest.java    From hazelcast-simulator with Apache License 2.0 6 votes vote down vote up
@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 += getAtomicLong(key).get();
        }
    }

    assertEquals(totalCounter.get(), actual);
}
 
Example #3
Source File: HazelcastMemoryService.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@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);
    }
}
 
Example #4
Source File: HazelcastMemoryService.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@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();
            }
        }
    }
}
 
Example #5
Source File: HazelcastMemoryService.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@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);
    }
}
 
Example #6
Source File: HazelcastMemoryService.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@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();
            }
        }
    }
}
 
Example #7
Source File: TestDataHelper.java    From spring-data-hazelcast with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    assertThat("Correct Hazelcast instance", this.hazelcastInstance.getName(), equalTo(TestConstants.CLIENT_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);
    
    this.cityMap = this.hazelcastInstance.getMap(TestConstants.CITY_MAP_NAME);
    loadCities(this.cityMap);

    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));
}
 
Example #8
Source File: WebConfigurerTest.java    From flair-engine with Apache License 2.0 4 votes vote down vote up
@Override
public Collection<DistributedObject> getDistributedObjects() {
    return null;
}
 
Example #9
Source File: WebConfigurerTest.java    From flair-engine with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends DistributedObject> T getDistributedObject(String s, String s1) {
    return null;
}
 
Example #10
Source File: HazelcastSlidingWindowSyncRequestRequestRateLimiterPerformanceTest.java    From ratelimitj with Apache License 2.0 4 votes vote down vote up
@AfterEach
void afterEach() {
    hz.getDistributedObjects().forEach(DistributedObject::destroy);
}
 
Example #11
Source File: HazelcastRequestRateLimiterInternalTest.java    From ratelimitj with Apache License 2.0 4 votes vote down vote up
@AfterEach
void afterEach() {
    hz.getDistributedObjects().forEach(DistributedObject::destroy);
}
 
Example #12
Source File: HazelcastSlidingWindowSyncRequestRateLimiterTest.java    From ratelimitj with Apache License 2.0 4 votes vote down vote up
@AfterEach
void afterEach() {
    hz.getDistributedObjects().forEach(DistributedObject::destroy);
}
 
Example #13
Source File: TranslationService.java    From modernmt with Apache License 2.0 4 votes vote down vote up
/**
 * This method returns a local proxy to the TranslationService.
 */
@Override
public DistributedObject createDistributedObject(String objectName) {
    return new TranslationServiceProxy(nodeEngine, this, objectName);
}
 
Example #14
Source File: HazelcastMemoryService.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
@Override
public String getStatus() {
    // MIRRORS the OLD status report
    final StringBuilder buf = new StringBuilder();
    buf.append("** Memory report\n");
    buf.append("freeMemory: ").append(Runtime.getRuntime().freeMemory());
    buf.append(" totalMemory: "); buf.append(Runtime.getRuntime().totalMemory());
    buf.append(" maxMemory: "); buf.append(Runtime.getRuntime().maxMemory());
    buf.append("\n\n");

    Collection<DistributedObject> distributedObjects = hcInstance.getDistributedObjects();
    TreeMap<String, IMap> caches = new TreeMap<String, IMap>();
    for (DistributedObject distributedObject : distributedObjects) {
        if (distributedObject instanceof IMap) {
            caches.put(distributedObject.getName(), (IMap) distributedObject);
        }
    }

    // summary (cache descriptions)
    for (Map.Entry<String, IMap> entry : caches.entrySet()) {
        Cache c = new HazelcastCache(entry.getValue());
        buf.append(c.getDescription()).append("\n");
    }

    /* TODO figure out how to get the configs from the IMap
    // config report
    buf.append("\n** Current Cache Configurations\n");
    // determine whether to use old or new form keys
    boolean legacyKeys = true; // set true for a 2.9/BasicMemoryService compatible set of keys
    String maxKey = "maxEntries";
    String ttlKey = "timeToLive";
    String ttiKey = "timeToIdle";
    String eteKey = "eternal";
    //noinspection ConstantConditions
    if (legacyKeys) {
        maxKey = "maxElementsInMemory";
        ttlKey = "timeToLiveSeconds";
        ttiKey = "timeToIdleSeconds";
    }
    // DEFAULT cache config
    CacheConfiguration defaults = cacheManager.getConfiguration().getDefaultCacheConfiguration();
    long maxEntriesDefault = defaults.getMaxEntriesLocalHeap();
    long ttlSecsDefault = defaults.getTimeToLiveSeconds();
    long ttiSecsDefault = defaults.getTimeToIdleSeconds();
    boolean eternalDefault = defaults.isEternal();
    buf.append("# DEFAULTS: ").append(maxKey).append("=").append(maxEntriesDefault).append(",").append(ttlKey).append("=").append(ttlSecsDefault).append(",").append(ttiKey).append("=").append(ttiSecsDefault).append(",").append(eteKey).append("=").append(eternalDefault).append("\n");
    // new: timeToLive=600,timeToIdle=360,maxEntries=5000,eternal=false
    // old: timeToLiveSeconds=3600,timeToIdleSeconds=900,maxElementsInMemory=20000,eternal=false
    for (Ehcache cache : caches) {
        long maxEntries = cache.getCacheConfiguration().getMaxEntriesLocalHeap();
        long ttlSecs = cache.getCacheConfiguration().getTimeToLiveSeconds();
        long ttiSecs = cache.getCacheConfiguration().getTimeToIdleSeconds();
        boolean eternal = cache.getCacheConfiguration().isEternal();
        if (maxEntries == maxEntriesDefault && ttlSecs == ttlSecsDefault && ttiSecs == ttiSecsDefault && eternal == eternalDefault) {
            // Cache ONLY uses the defaults
            buf.append("# memory.").append(cache.getName()).append(" *ALL DEFAULTS*\n");
        } else {
            // NOT only defaults cache, show the settings that differ from the defaults
            buf.append("memory.").append(cache.getName()).append("=");
            boolean first = true;
            if (maxEntries != maxEntriesDefault) {
                //noinspection ConstantConditions
                first = addKeyValueToConfig(buf, maxKey, maxEntries, first);
            }
            if (ttlSecs != ttlSecsDefault) {
                first = addKeyValueToConfig(buf, ttlKey, ttlSecs, first);
            }
            if (ttiSecs != ttiSecsDefault) {
                first = addKeyValueToConfig(buf, ttiKey, ttiSecs, first);
            }
            if (eternal != eternalDefault) {
                addKeyValueToConfig(buf, eteKey, eternal, first);
            }
            buf.append("\n");
            // TODO remove the overflow to disk check
            //noinspection deprecation
            if (cache.getCacheConfiguration().isOverflowToDisk()) {
                // overflowToDisk. maxEntriesLocalDisk
                buf.append("# NOTE: ").append(cache.getName()).append(" is configured for Overflow(disk), ").append(cache.getCacheConfiguration().getMaxEntriesLocalDisk()).append(" entries\n");
            }
        }
    }
    */

    final String rv = buf.toString();
    log.info(rv);

    return rv;
}
 
Example #15
Source File: NodeSequencerService.java    From snowcast with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public DistributedObject createDistributedObject(@Nonnull String objectName) {
    return new DummyProxy(objectName);
}
 
Example #16
Source File: HazelcastMemoryService.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
@Override
public String getStatus() {
    // MIRRORS the OLD status report
    final StringBuilder buf = new StringBuilder();
    buf.append("** Memory report\n");
    buf.append("freeMemory: ").append(Runtime.getRuntime().freeMemory());
    buf.append(" totalMemory: "); buf.append(Runtime.getRuntime().totalMemory());
    buf.append(" maxMemory: "); buf.append(Runtime.getRuntime().maxMemory());
    buf.append("\n\n");

    Collection<DistributedObject> distributedObjects = hcInstance.getDistributedObjects();
    TreeMap<String, IMap> caches = new TreeMap<String, IMap>();
    for (DistributedObject distributedObject : distributedObjects) {
        if (distributedObject instanceof IMap) {
            caches.put(distributedObject.getName(), (IMap) distributedObject);
        }
    }

    // summary (cache descriptions)
    for (Map.Entry<String, IMap> entry : caches.entrySet()) {
        Cache c = new HazelcastCache(entry.getValue());
        buf.append(c.getDescription()).append("\n");
    }

    /* TODO figure out how to get the configs from the IMap
    // config report
    buf.append("\n** Current Cache Configurations\n");
    // determine whether to use old or new form keys
    boolean legacyKeys = true; // set true for a 2.9/BasicMemoryService compatible set of keys
    String maxKey = "maxEntries";
    String ttlKey = "timeToLive";
    String ttiKey = "timeToIdle";
    String eteKey = "eternal";
    //noinspection ConstantConditions
    if (legacyKeys) {
        maxKey = "maxElementsInMemory";
        ttlKey = "timeToLiveSeconds";
        ttiKey = "timeToIdleSeconds";
    }
    // DEFAULT cache config
    CacheConfiguration defaults = cacheManager.getConfiguration().getDefaultCacheConfiguration();
    long maxEntriesDefault = defaults.getMaxEntriesLocalHeap();
    long ttlSecsDefault = defaults.getTimeToLiveSeconds();
    long ttiSecsDefault = defaults.getTimeToIdleSeconds();
    boolean eternalDefault = defaults.isEternal();
    buf.append("# DEFAULTS: ").append(maxKey).append("=").append(maxEntriesDefault).append(",").append(ttlKey).append("=").append(ttlSecsDefault).append(",").append(ttiKey).append("=").append(ttiSecsDefault).append(",").append(eteKey).append("=").append(eternalDefault).append("\n");
    // new: timeToLive=600,timeToIdle=360,maxEntries=5000,eternal=false
    // old: timeToLiveSeconds=3600,timeToIdleSeconds=900,maxElementsInMemory=20000,eternal=false
    for (Ehcache cache : caches) {
        long maxEntries = cache.getCacheConfiguration().getMaxEntriesLocalHeap();
        long ttlSecs = cache.getCacheConfiguration().getTimeToLiveSeconds();
        long ttiSecs = cache.getCacheConfiguration().getTimeToIdleSeconds();
        boolean eternal = cache.getCacheConfiguration().isEternal();
        if (maxEntries == maxEntriesDefault && ttlSecs == ttlSecsDefault && ttiSecs == ttiSecsDefault && eternal == eternalDefault) {
            // Cache ONLY uses the defaults
            buf.append("# memory.").append(cache.getName()).append(" *ALL DEFAULTS*\n");
        } else {
            // NOT only defaults cache, show the settings that differ from the defaults
            buf.append("memory.").append(cache.getName()).append("=");
            boolean first = true;
            if (maxEntries != maxEntriesDefault) {
                //noinspection ConstantConditions
                first = addKeyValueToConfig(buf, maxKey, maxEntries, first);
            }
            if (ttlSecs != ttlSecsDefault) {
                first = addKeyValueToConfig(buf, ttlKey, ttlSecs, first);
            }
            if (ttiSecs != ttiSecsDefault) {
                first = addKeyValueToConfig(buf, ttiKey, ttiSecs, first);
            }
            if (eternal != eternalDefault) {
                addKeyValueToConfig(buf, eteKey, eternal, first);
            }
            buf.append("\n");
            // TODO remove the overflow to disk check
            //noinspection deprecation
            if (cache.getCacheConfiguration().isOverflowToDisk()) {
                // overflowToDisk. maxEntriesLocalDisk
                buf.append("# NOTE: ").append(cache.getName()).append(" is configured for Overflow(disk), ").append(cache.getCacheConfiguration().getMaxEntriesLocalDisk()).append(" entries\n");
            }
        }
    }
    */

    final String rv = buf.toString();
    log.info(rv);

    return rv;
}