private MapConfig createMapConfig(final TicketDefinition definition) { final HazelcastProperties hz = casProperties.getTicket().getRegistry().getHazelcast(); final HazelcastProperties.Cluster cluster = hz.getCluster(); final EvictionPolicy evictionPolicy = EvictionPolicy.valueOf(cluster.getEvictionPolicy()); LOGGER.debug("Creating Hazelcast map configuration for [{}] with idle timeout [{}] second(s)", definition.getProperties().getStorageName(), definition.getProperties().getStorageTimeout()); return new MapConfig() .setName(definition.getProperties().getStorageName()) .setMaxIdleSeconds((int) definition.getProperties().getStorageTimeout()) .setBackupCount(cluster.getBackupCount()) .setAsyncBackupCount(cluster.getAsyncBackupCount()) .setEvictionPolicy(evictionPolicy) .setMaxSizeConfig(new MaxSizeConfig() .setMaxSizePolicy(MaxSizeConfig.MaxSizePolicy.valueOf(cluster.getMaxSizePolicy())) .setSize(cluster.getMaxHeapSizePercentage())); }
private MapConfig initializeDefaultMapConfig() { MapConfig mapConfig = new MapConfig(); /* * Number of backups. If 1 is set as the backup-count for example, then all entries of the * map will be copied to another JVM for fail-safety. Valid numbers are 0 (no backup), 1, 2, * 3. */ mapConfig.setBackupCount(1); /* * Valid values are: NONE (no eviction), LRU (Least Recently Used), LFU (Least Frequently * Used). NONE is the default. */ mapConfig.setEvictionPolicy(EvictionPolicy.LRU); /* * Maximum size of the map. When max size is reached, map is evicted based on the policy * defined. Any integer between 0 and Integer.MAX_VALUE. 0 means Integer.MAX_VALUE. Default * is 0. */ mapConfig .setMaxSizeConfig(new MaxSizeConfig(0, MaxSizeConfig.MaxSizePolicy.USED_HEAP_SIZE)); return mapConfig; }
void addMapConfig(Class<?> c) { if(!c.isAnnotationPresent(HzMapConfig.class)) throw new IllegalArgumentException(c+" not annotated with @"+HzMapConfig.class.getSimpleName()); HzMapConfig hc = c.getAnnotation(HzMapConfig.class); MapConfig mapC = new MapConfig(hc.name()); if(hzConfig.getMapConfigs().containsKey(hc.name())) { mapC = hzConfig.getMapConfig(hc.name()); } mapC.setAsyncBackupCount(hc.asyncBackupCount()); mapC.setBackupCount(hc.backupCount()); mapC.setEvictionPercentage(hc.evictPercentage()); mapC.setEvictionPolicy(EvictionPolicy.valueOf(hc.evictPolicy())); mapC.setInMemoryFormat(InMemoryFormat.valueOf(hc.inMemoryFormat())); mapC.setMaxIdleSeconds(hc.idleSeconds()); mapC.setMergePolicy(hc.evictPolicy()); mapC.setMinEvictionCheckMillis(hc.evictCheckMillis()); mapC.setTimeToLiveSeconds(hc.ttlSeconds()); mapC.setMaxSizeConfig(new MaxSizeConfig(hc.maxSize(), MaxSizePolicy.valueOf(hc.maxSizePolicy()))); mapC.setStatisticsEnabled(hc.statisticsOn()); hzConfig.getMapConfigs().put(mapC.getName(), mapC); }
public ClusterManager(HazelcastConnection connection, List<HealthCheck> healthChecks, HttpConfiguration httpConfiguration) throws Exception { this.hazelcastConnection = connection; this.healthChecks = healthChecks; MapConfig mapConfig = new MapConfig(MAP_NAME); mapConfig.setTimeToLiveSeconds(MAP_REFRESH_TIME + 2); //Reduce jitter mapConfig.setBackupCount(1); mapConfig.setAsyncBackupCount(2); mapConfig.setEvictionPolicy(EvictionPolicy.NONE); hazelcastConnection.getHazelcastConfig().getMapConfigs().put(MAP_NAME, mapConfig); String hostname = Inet4Address.getLocalHost().getCanonicalHostName(); executor = Executors.newScheduledThreadPool(1); clusterMember = new ClusterMember(hostname, httpConfiguration.getPort()); }
private MapConfig initializeDefaultMapConfig() { MapConfig mapConfig = new MapConfig(); /* Number of backups. If 1 is set as the backup-count for example, then all entries of the map will be copied to another JVM for fail-safety. Valid numbers are 0 (no backup), 1, 2, 3. */ mapConfig.setBackupCount(0); /* Valid values are: NONE (no eviction), LRU (Least Recently Used), LFU (Least Frequently Used). NONE is the default. */ mapConfig.setEvictionPolicy(EvictionPolicy.LRU); /* Maximum size of the map. When max size is reached, map is evicted based on the policy defined. Any integer between 0 and Integer.MAX_VALUE. 0 means Integer.MAX_VALUE. Default is 0. */ mapConfig.setMaxSizeConfig(new MaxSizeConfig(0, MaxSizeConfig.MaxSizePolicy.USED_HEAP_SIZE)); return mapConfig; }
@Bean public Config hazelCastConfig() { Config config = new Config(); config.setInstanceName("hazelcast-packt-cache"); config.setProperty("hazelcast.jmx", "true"); MapConfig deptCache = new MapConfig(); deptCache.setTimeToLiveSeconds(20); deptCache.setEvictionPolicy(EvictionPolicy.LFU); config.getMapConfigs().put("hazeldept",deptCache); return config; }
@Test public void correctHazelcastInstanceIsCreated() throws Exception { assertNotNull(this.hzInstance); final Config config = this.hzInstance.getConfig(); assertFalse(config.getNetworkConfig().getJoin().getMulticastConfig().isEnabled()); assertEquals(Arrays.asList("localhost"), config.getNetworkConfig().getJoin().getTcpIpConfig().getMembers()); assertTrue(config.getNetworkConfig().isPortAutoIncrement()); assertEquals(5701, config.getNetworkConfig().getPort()); final MapConfig mapConfig = config.getMapConfig("tickets"); assertNotNull(mapConfig); assertEquals(28800, mapConfig.getMaxIdleSeconds()); assertEquals(EvictionPolicy.LRU, mapConfig.getEvictionPolicy()); assertEquals(10, mapConfig.getEvictionPercentage()); }
@Test public void hazelcastInstanceIsCreatedNormally() throws Exception { assertNotNull(this.hzInstance); final Config config = this.hzInstance.getConfig(); assertTrue(config.getNetworkConfig().getJoin().getMulticastConfig().isEnabled()); assertEquals(Arrays.asList("127.0.0.1"), config.getNetworkConfig().getJoin().getTcpIpConfig().getMembers()); assertFalse(config.getNetworkConfig().isPortAutoIncrement()); assertEquals(5801, config.getNetworkConfig().getPort()); final MapConfig mapConfig = config.getMapConfig("tickets-from-external-config"); assertNotNull(mapConfig); assertEquals(20000, mapConfig.getMaxIdleSeconds()); assertEquals(EvictionPolicy.LFU, mapConfig.getEvictionPolicy()); assertEquals(99, mapConfig.getEvictionPercentage()); }
private static MapConfig initializeDefaultMapConfig() { MapConfig mapConfig = new MapConfig(); /* Number of backups. If 1 is set as the backup-count for example, then all entries of the map will be copied to another JVM for fail-safety. Valid numbers are 0 (no backup), 1, 2, 3. */ mapConfig.setBackupCount(0); /* Valid values are: NONE (no eviction), LRU (Least Recently Used), LFU (Least Frequently Used). NONE is the default. */ mapConfig.setEvictionPolicy(EvictionPolicy.LRU); /* Maximum size of the map. When max size is reached, map is evicted based on the policy defined. Any integer between 0 and Integer.MAX_VALUE. 0 means Integer.MAX_VALUE. Default is 0. */ mapConfig.setMaxSizeConfig(new MaxSizeConfig(0, MaxSizeConfig.MaxSizePolicy.USED_HEAP_SIZE)); return mapConfig; }
private MapConfig createDeviceCredentialsCacheConfig() { MapConfig deviceCredentialsCacheConfig = new MapConfig(CacheConstants.DEVICE_CREDENTIALS_CACHE); deviceCredentialsCacheConfig.setTimeToLiveSeconds(cacheDeviceCredentialsTTL); deviceCredentialsCacheConfig.setEvictionPolicy(EvictionPolicy.LRU); deviceCredentialsCacheConfig.setMaxSizeConfig( new MaxSizeConfig( cacheDeviceCredentialsMaxSizeSize, MaxSizeConfig.MaxSizePolicy.valueOf(cacheDeviceCredentialsMaxSizePolicy)) ); return deviceCredentialsCacheConfig; }
private MapConfig initializeDefaultMapConfig() { MapConfig mapConfig = new MapConfig(); /* Number of backups. If 1 is set as the backup-count for example, then all entries of the map will be copied to another JVM for fail-safety. Valid numbers are 0 (no backup), 1, 2, 3. */ mapConfig.setBackupCount(0); /* Valid values are: NONE (no eviction), LRU (Least Recently Used), LFU (Least Frequently Used). NONE is the default. */ mapConfig.setEvictionPolicy(EvictionPolicy.LRU); /* Maximum size of the map. When max size is reached, map is evicted based on the policy defined. Any integer between 0 and Integer.MAX_VALUE. 0 means Integer.MAX_VALUE. Default is 0. */ mapConfig.setMaxSizeConfig(new MaxSizeConfig(0, MaxSizeConfig.MaxSizePolicy.USED_HEAP_SIZE)); /* When max. size is reached, specified percentage of the map will be evicted. Any integer between 0 and 100. If 25 is set for example, 25% of the entries will get evicted. */ mapConfig.setEvictionPercentage(25); return mapConfig; }
private MapConfig initializeDefaultMapConfig() { MapConfig mapConfig = new MapConfig(); /* Number of backups. If 1 is set as the backup-count for example, then all entries of the map will be copied to another JVM for fail-safety. Valid numbers are 0 (no backup), 1, 2, 3. */ mapConfig.setBackupCount(1); /* Valid values are: NONE (no eviction), LRU (Least Recently Used), LFU (Least Frequently Used). NONE is the default. */ mapConfig.setEvictionPolicy(EvictionPolicy.LRU); /* Maximum size of the map. When max size is reached, map is evicted based on the policy defined. Any integer between 0 and Integer.MAX_VALUE. 0 means Integer.MAX_VALUE. Default is 0. */ mapConfig.setMaxSizeConfig(new MaxSizeConfig(0, MaxSizeConfig.MaxSizePolicy.USED_HEAP_SIZE)); /* When max. size is reached, specified percentage of the map will be evicted. Any integer between 0 and 100. If 25 is set for example, 25% of the entries will get evicted. */ mapConfig.setEvictionPercentage(25); return mapConfig; }
public void createBucket(String map, int ttl, int backups, int mib) throws IOException { if (bucketCreation.containsKey(map)) { throw new FileAlreadyExistsException(null, null, "Bucket already exists: " + map); } Map<String, MapConfig> mapConfigs = hazelcast.getConfig() .getMapConfigs(); MapConfig config = new MapConfig(map); config.setTimeToLiveSeconds(ttl); config.setEvictionPolicy(EvictionPolicy.LRU); config.setInMemoryFormat(InMemoryFormat.BINARY); config.setBackupCount(backups); int nodes = hazelcast.getCluster().getMembers().size(); MaxSizeConfig max = new MaxSizeConfig(mib / nodes, MaxSizeConfig.MaxSizePolicy.USED_HEAP_SIZE); config.setMaxSizeConfig(max); mapConfigs.put(map, config); // pre-fill local map configuration timestamp... bucketCreation.putIfAbsent(map, System.currentTimeMillis()); // this should always be the first call to the map... hazelcast.getMap(map); }
private void setCacheConfig(Config config, String name, int timeToLive) { HotRestartConfig hotRestart = new HotRestartConfig(); hotRestart.setEnabled(true); config.getMapConfig(name)// .setTimeToLiveSeconds(timeToLive)// .setMaxIdleSeconds(timeToLive)// .setEvictionPolicy(EvictionPolicy.LRU)// .setMaxSizeConfig(new MaxSizeConfig(5000, MaxSizePolicy.PER_NODE))// .setBackupCount(1)// .setHotRestartConfig(hotRestart)// .setInMemoryFormat(InMemoryFormat.BINARY)// .setStatisticsEnabled(true)// // .setWanReplicationRef(null)// ; }
@Bean public Map<String, Object> cache() { Config config = new Config(); MapConfig mapConfig = new MapConfig(); mapConfig.setEvictionPercentage(50); mapConfig.setEvictionPolicy(EvictionPolicy.LFU); mapConfig.setTimeToLiveSeconds(300); Map<String, MapConfig> mapConfigMap = new HashMap<>(); mapConfigMap.put("cache", mapConfig); config.setMapConfigs(mapConfigMap); HazelcastInstance instance = Hazelcast.newHazelcastInstance(config); return instance.getMap("cache"); }
@Bean public Config hazelcastConfig() { Config config = new Config(); config.addMapConfig(new MapConfig("spring-boot-admin-event-store").setInMemoryFormat(InMemoryFormat.OBJECT) .setBackupCount(1) .setEvictionPolicy(EvictionPolicy.NONE)); config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false); TcpIpConfig tcpIpConfig = config.getNetworkConfig().getJoin().getTcpIpConfig(); tcpIpConfig.setEnabled(true); tcpIpConfig.setMembers(singletonList("127.0.0.1")); return config; }
@Bean public Config hazelcastConfig() { return new Config().setProperty("hazelcast.jmx", "true") .addMapConfig(new MapConfig("spring-boot-admin-application-eventstore").setBackupCount(1) .setEvictionPolicy( EvictionPolicy.NONE)) .addListConfig(new ListConfig("spring-boot-admin-event-eventstore").setBackupCount(1) .setMaxSize(1000)); }
public EvictionPolicy getEvictionPolicy() { return evictionPolicy; }
public KfkaManagerImpl(HazelcastInstance hazelcastInstance, KfkaMapStore<? extends KfkaMessage> mapStore, KfkaCounterStore counterStore, KfkaConfig kfkaCfg) { this.kfkaCfg = kfkaCfg; final MapConfig hzcfg = hazelcastInstance.getConfig().getMapConfig(kfkaCfg.getName()); hzcfg.setEvictionPolicy(EvictionPolicy.NONE); final MapStoreConfig mapCfg = hzcfg.getMapStoreConfig(); mapCfg.setImplementation(mapStore); mapCfg.setEnabled(kfkaCfg.isPersistent()); mapCfg.setWriteBatchSize(kfkaCfg.getBatchSize()); mapCfg.setWriteDelaySeconds(kfkaCfg.getWriteDelay()); mapCfg.setInitialLoadMode(kfkaCfg.getInitialLoadMode()); this.mapStore = mapStore; this.messages = hazelcastInstance.getMap(kfkaCfg.getName()); this.counter = hazelcastInstance.getAtomicLong(kfkaCfg.getName()); messages.addIndex("id", true); messages.addIndex("timestamp", true); messages.addEntryListener(new EntryAddedListener<Long, KfkaMessage>() { @Override public void entryAdded(EntryEvent<Long, KfkaMessage> event) { logger.debug("Received message for dispatch: {}", event.getValue()); final Iterator<Entry<KfkaMessageListener, KfkaPredicate>> iter = msgListeners.entrySet().iterator(); while (iter.hasNext()) { final Entry<KfkaMessageListener, KfkaPredicate> e = iter.next(); final KfkaPredicate predicate = e.getValue(); final KfkaMessage msg = event.getValue(); // Check if message should be included if (predicate.toGuavaPredicate().apply(msg)) { final KfkaMessageListener l = e.getKey(); logger.debug("Sending message {} to {}", event.getValue().getId(), e.getKey()); l.onMessage(event.getValue()); } } } }, true); if (counter.get() == 0) { final long initialValue = counterStore.latest(); logger.info("Setting current KFKA message ID counter to {}", initialValue); counter.compareAndSet(0, initialValue); } }