Hazelcast spring configuration

What is the difference between the <hz:map> created in applicationContext and those defined in the <hz:config> segment?

How are they connected?

I know that the <hz:map> in applicationContext will lead to the creation of an IMap bean, and this will not happen when no <hz:map> .

But what does the following configuration do when there is a bean and then has <hz:map> with the same name in the hazel configuration?

 <hz:map id="loggedInUserMap" name="loggedInUserMap" instance-ref="ipds" scope="singleton" /> <hz:hazelcast id="ipds"> <hz:config> <hz:instance-name>${hz.instance.name}</hz:instance-name> <hz:group name="${hz.group.name}" password="${hz.group.password}"/> <hz:map name="loggedInUserMap" backup-count="1" eviction-policy="NONE" in-memory-format="BINARY"> <hz:near-cache time-to-live-seconds="0" max-idle-seconds="60" eviction-policy="LRU" max-size="5000" invalidate-on-change="true"/> </hz:map> </hz:config> </hz:hazelcast> 
+6
source share
1 answer
 <hz:map id="loggedInUserMap" name="loggedInUserMap" instance-ref="ipds" scope="singleton" /> 

This will create a bean named 'loggedInUserMap' (specified by the id attribute). The name of the map in the Hazelcast context will also be "loggedInUserMap" (indicated by the name attribute).

Tag

A <hz:map> inside <hz:config> refers to a specific configuration that can be used when creating an IMap (here referred to as MapConfig ). There may be many such MapConfigs . A single MapConfig can be shared across multiple IMaps using a wildcard * .

If you have a MapConfig with a name that matches the map name used in the hazelcast context, this configuration will be used when creating this IMap. In your case, this is "loggedInUserMap".

If not found, a MapConfig named "default" will be used to create this IMap.

If not found, the default values ​​for IMap will be used when creating this IMap object.

I think the following example will clearly figure it out.

Configuration example

 <hz:config> <hz:instance-name>${hz.instance.name}</hz:instance-name> <hz:group name="${hz.group.name}" password="${hz.group.password}"/> <hz:map name="default" backup-count="2" max-size="0" time-to-live-seconds="25" eviction-percentage="30" eviction-policy="NONE"/> <hz:map name="userMap" backup-count="2" max-size="0" time-to-live-seconds="6000" eviction-percentage="30" eviction-policy="NONE"/> <hz:map name="FruitMap*" backup-count="2" max-size="0" time-to-live-seconds="10" eviction-percentage="30" eviction-policy="NONE"/> </hz:config> <hz:map instance-ref="ipds" id="userMapSpringId" name="userMap" /> <hz:map instance-ref="ipds" id="mangoMapSpringId" name="FruitMap1" /> <hz:map instance-ref="ipds" id="appleMapSpringId" name="FruitMap2" /> <hz:map instance-ref="ipds" id="alientFruitMapSpringId" name="AlienFruit" /> 

Code example

 IMap map1 = (IMap) ctx.getBean("userMapSpringId"); // map1 will make use of the configuration with name "userMap" IMap map2 = (IMap) ctx.getBean("mangoMapSpringId"); IMap map3 = (IMap) ctx.getBean("appleMapSpringId"); // Here two different IMaps objects are created. // However both map2 and map3 will make use of the same configuration "FruitMap*". IMap map4 = (IMap) ctx.getBean("alientFruitMapSpringId"); // In the case of map4, there is no configuration which matches its hazelcast name // (AlienFruit). Hence it will make use of the configuration with name "default". 

I hope the code snippet with comments is self-explanatory.

+3
source

All Articles