- Type Parameters:
K- type of the MapLoader key
V- type of the MapLoader value
- All Known Subinterfaces:
- All Known Implementing Classes:
public interface MapLoader<K,V>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, or simply a file-based data store.
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 MapLoader implementation is provided, then instead of returning
null, Hazelcast will attempt to load the unknown entry by calling the implementation's
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 (if eviction is configured).
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. While 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. For example a very slow MapLoader for one map could block a request for data on another map, or even a queue. It is therefore strongly recommended not to use MapLoader to call across a WAN or to a system which will take on average longer than a few milliseconds to respond.
MapLoaders should not be used to perform cascading operations on other data structures via a
HazelcastInstance, the MapLoader should only concern itself with the operation on the assigned map. If the MapLoader attempts to access another data structure on a different partition to the key used in the MapLoader, a
IllegalThreadStateExceptionis thrown. A MapLoader can only interact with other data structures that reside on the same partition.
If a blocked partition thread is called from a Hazelcast Client the caller will also block indefinitely, for example
IMap.get(Object). If the same call is made from another cluster member the operation will eventually time out with an
All Methods Instance Methods Abstract Methods Modifier and Type Method Description
load(K key)Loads the value of a given key.
loadAll(java.util.Collection<K> keys)Loads given keys.
loadAllKeys()Loads all of the keys from the store.
V load(K key)Loads the value of a given key. If distributed map doesn't contain the value for the given key then Hazelcast will call implementation's load (key) method to obtain the value. Implementation can use any means of loading the given key; such as an O/R mapping tool, simple SQL or reading a file etc.
key- , cannot be
- value of the key; returning
nullvalue signals value missing in the underlying store
java.util.Map<K,V> loadAll(java.util.Collection<K> keys)Loads given keys. This is batch load operation so that implementation can optimize the multiple loads.
For any key in the input keys, there should be a single mapping in the resulting map. Also the resulting map should not have any keys that are not part of the input keys.
The given collection should not contain any
nullkeys. The returned Map should not contain any
nullkeys or values.
Loading other items than what provided in
keysprevents the map from being filled from the map store.
keys- keys of the values entries to load
- map of loaded key-value pairs.
java.lang.Iterable<K> loadAllKeys()Loads all of the keys from the store. The returned
Iterablemay return the keys lazily by loading them in batches. The
Iterablemay implement the
Closeableinterface in which case it will be closed once iteration is over. This is intended for releasing resources such as closing a JDBC result set.
The returned Iterable should not contain any
- all the keys. Keys inside the Iterable cannot be