Book Image

Getting Started with Hazelcast, Second Edition

By : Matthew Johns
Book Image

Getting Started with Hazelcast, Second Edition

By: Matthew Johns

Overview of this book

Table of Contents (19 chapters)
Getting Started with Hazelcast Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Map configuration


This is used to configure how map data is stored within the cluster, either individual named maps or a cluster-wide default.

Maximum size and eviction

Maximum size policies include:

  • PER_NODE

  • PER_PARTITION

  • USED_HEAP_SIZE

  • USED_HEAP_PERCENTAGE

  • FREE_HEAP_SIZE

  • FREE_HEAP_PERCENTAGE

Eviction policies include:

  • LRU: Least Recently Used

  • LFU: Least Frequently Used

  • NONE

<map name="default">
 <max-size policy="PER_NODE">10</max-size>
 <eviction-policy>LFU</eviction-policy>
 <eviction-percentage>20</eviction-percentage>
</map>

config.getMapConfig("default")
 .setMaxSizeConfig(new MaxSizeConfig(10, MaxSizePolicy.PER_NODE))
 .setEvictionPolicy(EvictionPolicy.LFU)
 .setEvictionPercentage(20);

Backup copies

Backup = Synchronous copies

Async = Asynchronous copies

Total copies = 1 Main + Backup + Async

<map name="default">
 <backup-count>1</backup-count>
 <async-backup-count>1</async-backup-count>
</map>

config.getMapConfig("default")
 .setBackupCount(1)
 .setAsyncBackupCount(1);

Age expiry and idle expiry times

This configures when entries will be by default automatically removed:

<map name="default">
 <time-to-live-seconds>86400</time-to-live-seconds>
 <max-idle-seconds>3600</max-idle-seconds>
</map>

config.getMapConfig("default")
 .setTimeToLiveSeconds(86400)
 .setMaxIdleSeconds(3600);

Map merge policy

Default merge policy classes

  • com.hazelcast.map.merge.PassThroughMergePolicy

  • com.hazelcast.map.merge.PutIfAbsentMapMergePolicy

  • com.hazelcast.map.merge.HigherHitsMapMergePolicy

  • com.hazelcast.map.merge.LatestUpdateMapMergePolicy

    <map name="default">
     <merge-policy>
      com.hazelcast.map.merge.LatestUpdateMapMergePolicy
     </merge-policy>
    </map>
    
    config.getMapConfig("default")
     .setMergePolicy(
      LatestUpdateMapMergePolicy.class.getCanonicalName()
     );

Selected WAN replication configuration

<map name="default">
 <wan-replication-ref name="our-global-cluster">
  <merge-policy>
   com.hazelcast.map.merge.LatestUpdateMapMergePolicy
  </merge-policy>
 </wan-replication-ref>
</map>

WanReplicationRef wrr = new WanReplicationRef();
wrr.setName("our-global-cluster");
wrr.setMergePolicy(
 LatestUpdateMapMergePolicy.class.getCanonicalName()
);
config.getMapConfig("default")
 .setWanReplicationRef(wrr);

Indexes on values

<map name="default">
 <indexes>
  <index ordered="false">name</index>
  <index ordered="true">population</index>
 </indexes>
</map>

config.getMapConfig("default")
 .addMapIndexConfig(new MapIndexConfig("name", false))
 .addMapIndexConfig(new MapIndexConfig("population", true));