Programmatically setting properties for maps in Hazelcast?

Is there a way to programmatically set the "time to live" property (or virtually any property) for a distributed card in Hazelcast?

I want to avoid having to modify the Hazelcast XML for this.

I am using Hazelcast version 1.7.1

+5
source share
1 answer

You can install everything programmatically in Hazelcast, starting with version 1.7.1. You need to create a Config object and pass it.

Here's how you do it in Hazelcast 1.7.1

If you use Hazelcast static methods to get a map, for example Hazelcast.getMap ("myMapName"), then this is the way:

//You need to do this once on each JVM(Hazelcast node) at the begining  
Config myConfig = new Config();
Map<String, MapConfig> myHazelcastMapConfigs = myConfig.getMapMapConfigs();
MapConfig myMapConfig = new MapConfig();
myMapConfig.setName("myMapName");
myMapConfig.setTimeToLiveSeconds(1000);
myHazelcastMapConfigs.put("myMapName", myMapConfig);
Hazelcast.init(myConfig);

Hazelcast Hazelcast.newHazelcastInstance, . . , hazelcast JVM.

HazelcastInstance h = Hazelcast.newHazelcastInstance(myConfig);

h.getMap("myMapName");

hazelcast :

Config config = new XmlConfigBuilder().build();
config.getMapConfig("myMapName").setTimeToLiveSeconds(10000);

, Hazelcast 1.8.1 - . .

...

+9

All Articles