What is Hazelcast MapLoader?
Hazelcast distributed map implementation is an in-memory data store, but it can be backed by any type of data store such as RDBMS, OODBMS, NOSQL, or simply a file-based data store.
MapLoader implementation provides feature to load data from external filesystem or storage to Hazelcast in-memory map.
IMap.get(Object)
Normally returns the value that is available in-memory. If the entry doesn’t exist in-memory, Hazelcast returns null. If a Loader implementation is provided then, instead of returning null, Hazelcast will attempt to load the unknown entry by calling the implementation’s load(Object) or loadAll(Collection) methods. Loaded entries will be placed into the distributed map and they will stay in-memory until they are explicitly removed or implicitly evicted.
Hazelcast MapLoader implementations are executed by a partition thread, therefore care should be taken not to block the thread with an expensive operation or an operation that may potentially never return, the partition thread does not time out the operation. Whilst the partition thread is executing the MapLoader it is unable to respond to requests for data on any other structure that may reside in the same partition, or to respond to other partitions mapped to the same partition thread.
Hazelcast MapLoader Mathods :
- V load(K key) – Load the value from external storage to Map by given key
- Map<K, V> loadAll(Collection<K> keys) – Load the value from eternal storage by given Collections of key.
- void loadAllKeys() – Loads all of the keys from the store.
Configuration of MapLoder
Similar like a MapStore config, Hazelcast MapLoader can be configured from hazelcast.xml, and the above method can be implemented in custom MapLoader class.
<map name="myMap">

<backup-count>1</backup-count>

<time-to-live-seconds>0</time-to-live-seconds>

<max-idle-seconds>0</max-idle-seconds>


<map-store enabled="true">

<class-name>com.example.MyMapLoader</class-name>

<write-delay-seconds>0</write-delay-seconds>

</map-store>

</map>
The below java code snipet are demonstrating the implmentation of MapLoader. by using DataSource connection. For more details about Hazelcast data source I will explain it in the separate post.
@Override

public Iterable<Integer> loadAllKeys() {

.....
}
@Override
public Employee load(Integer empId) {
....
}
@Override
public Map<Integer, String> loadAll(Collection collection) {
....
}
Conclusion
Similar like Hazelcast MapStore, Hazelcast MapLoader implementation can be customized. The code snippet can be reffered on github.
Pingback: How to integrate Hazelcast with Spring Boot? - Java Tech ARC 3i
Pingback: Hazelcast Hikari connection pooling
Pingback: Understanding of Hazelcast MapStore - Java Tech ARC 3i
Pingback: Understanding Hazelcast Serialization and Deserialization : A Complete Guide JavaTechARC3i
Pingback: Understanding Hazelcast MapStore: A Comprehensive Guide - How To Integrate Java - Tech ARC 3i