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); }
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)// ; }
private HazelcastCache() { final AppConfig config = AppConfig.getInstance(); final Map<String, MapConfig> mapconfigs = new HashMap<>(); GroupConfig groupconfig = new GroupConfig(); groupconfig.setName(config.getString("cluster.name", "gw2live")); groupconfig.setPassword(config.getString("cluster.password", "gw2live")); final MapConfig mapconfig = new MapConfig(); mapconfig.getMaxSizeConfig().setMaxSizePolicy(MaxSizePolicy.PER_PARTITION); mapconfig.getMaxSizeConfig().setSize(0); mapconfig.setEvictionPolicy(MapConfig.DEFAULT_EVICTION_POLICY); mapconfig.setBackupCount(1); mapconfigs.put("*-cache", mapconfig); final NetworkConfig nwconfig = new NetworkConfig(); if(config.containsKey("cluster.interface")) { final InterfacesConfig interfaces = new InterfacesConfig(); interfaces.addInterface(config.getString("cluster.interface")); interfaces.setEnabled(true); nwconfig.setInterfaces(interfaces); } nwconfig.setPort(config.getInteger("cluster.port", 5801)); nwconfig.setPortAutoIncrement(true); final MulticastConfig mcconfig = new MulticastConfig(); mcconfig.setEnabled(true); mcconfig.setMulticastGroup(config.getString("cluster.multicast.group", "224.2.2.3")); mcconfig.setMulticastPort(config.getInteger("cluster.multicast.port", 58011)); mcconfig.setMulticastTimeToLive(MulticastConfig.DEFAULT_MULTICAST_TTL); mcconfig.setMulticastTimeoutSeconds(MulticastConfig.DEFAULT_MULTICAST_TIMEOUT_SECONDS); final JoinConfig join = new JoinConfig(); join.setMulticastConfig(mcconfig); nwconfig.setJoin(join); final ExecutorConfig execconfig = new ExecutorConfig(); execconfig.setName("default"); execconfig.setPoolSize(4); execconfig.setQueueCapacity(100); final Map<String, ExecutorConfig> execmap = new HashMap<>(); execmap.put("default", execconfig); final Config hconfig = new Config(); hconfig.setInstanceName("gw2live"); hconfig.setGroupConfig(groupconfig); hconfig.setMapConfigs(mapconfigs); hconfig.setNetworkConfig(nwconfig); hconfig.setExecutorConfigs(execmap); hconfig.setProperty("hazelcast.shutdownhook.enabled", "false"); hconfig.setProperty("hazelcast.wait.seconds.before.join", "0"); hconfig.setProperty("hazelcast.rest.enabled", "false"); hconfig.setProperty("hazelcast.memcache.enabled", "false"); hconfig.setProperty("hazelcast.mancenter.enabled", "false"); hconfig.setProperty("hazelcast.logging.type", "none"); cache = Hazelcast.newHazelcastInstance(hconfig); LOG.debug("Hazelcast initialized"); }