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(); }
throw new InvalidConfigurationException(e.getMessage()); config.addCacheConfig(cacheConfig);
throw new InvalidConfigurationException(e.getMessage()); config.addCacheConfig(cacheConfig);
private static Config getConfig() { Config config = new Config(); config.addCacheConfig(new CacheSimpleConfig().setName(CACHE_NAME)); // Add an event journal config for cache which has custom capacity of 1000 (default 10_000) // and time to live seconds as 10 seconds (default 0 which means infinite) config.addEventJournalConfig(new EventJournalConfig().setEnabled(true) .setCacheName(CACHE_NAME) .setCapacity(1000) .setTimeToLiveSeconds(10)); return config; }
private static JetConfig getJetConfig() { JetConfig cfg = new JetConfig(); cfg.getHazelcastConfig().addCacheConfig(new CacheSimpleConfig().setName(CACHE_NAME)); // Add an event journal config for cache which has custom capacity of 1000 (default 10_000) // and time to live seconds as 10 seconds (default 0 which means infinite) cfg.getHazelcastConfig() .getCacheEventJournalConfig(CACHE_NAME) .setEnabled(true) .setCapacity(1000) .setTimeToLiveSeconds(10); return cfg; }
.addCacheConfig(new CacheSimpleConfig().setName(SOURCE_NAME)) .addCacheConfig(new CacheSimpleConfig().setName(SINK_NAME));