Class MapStoreAdapter<K,V>

java.lang.Object
com.hazelcast.map.MapStoreAdapter<K,V>
Type Parameters:
K - key of the map entry
V - value of the map entry.
All Implemented Interfaces:
MapLoader<K,V>, MapStore<K,V>

public class MapStoreAdapter<K,V> extends Object implements MapStore<K,V>
Adapter for MapStore.
See Also:
  • Constructor Details

    • MapStoreAdapter

      public MapStoreAdapter()
  • Method Details

    • delete

      public void delete(K key)
      Deletes the entry with the given key from the external store.

      Invocation semantics depend on configuration:

      • Write-through: invoked synchronously as part of IMap.remove().
      • Write-behind: invoked asynchronously on a background thread.

      Hazelcast provides at-least-once delivery semantics. Implementations must tolerate retries and duplicate invocations. Deleting a non-existent entry should be treated as a successful no-op.

      Specified by:
      delete in interface MapStore<K,V>
      Parameters:
      key - the key to delete from the store
    • store

      public void store(K key, V value)
      Stores the key-value pair in the external store.

      Invocation semantics depend on configuration:

      • Write-through (writeDelaySeconds == 0): this method is invoked synchronously as part of the IMap.put() call. If this method throws an exception, the map operation fails.
      • Write-behind (writeDelaySeconds > 0): this method may be invoked asynchronously on a background thread, potentially long after the original map operation has completed.

      Under normal circumstances Hazelcast provides at-least-once delivery semantics for calls to this method. Implementations must therefore be idempotent and tolerate retries, reordering, and duplicate invocations.

      Specified by:
      store in interface MapStore<K,V>
      Parameters:
      key - key of the entry to store
      value - value of the entry to store
    • storeAll

      public void storeAll(Map<K,V> map)
      Stores multiple entries in the external store.

      This method is primarily used with write-behind enabled (writeDelaySeconds > 0) when batching is applicable. Hazelcast may still invoke MapStore.store(Object, Object) instead of this method depending on runtime conditions (for example, batch size, write coalescing, or number of distinct keys in the current write window). Implementations must not rely on this method being invoked for every flush.

      Error handling and retries:

      • If this method throws an exception, Hazelcast treats the batch as failed and starts retry handling.
      • If the provided map has not been modified (no entries removed to signal partial success), Hazelcast retries storeAll(map) up to three times, waiting about 1 second between attempts.
      • After the final batch attempt fails, Hazelcast falls back to calling MapStore.store(Object, Object) for the remaining entries, one by one.
      • If the implementation removes entries from map as they are stored (before throwing), Hazelcast treats removed entries as successful and does not retry them; only the entries still present in map are retried and/or passed to the per-entry fallback.

      This allows implementations to signal partial success explicitly. Entries left in the map after an exception will be retried individually; removed entries will not be passed to subsequent calls.

      Hazelcast does not provide transactional guarantees across entries. Batch boundaries do not imply atomicity.

      Specified by:
      storeAll in interface MapStore<K,V>
      Parameters:
      map - map of entries to store
    • deleteAll

      public void deleteAll(Collection<K> keys)
      Deletes multiple entries from the external store.

      This method is primarily used with write-behind enabled (writeDelaySeconds > 0) when batching is applicable. Hazelcast may still invoke MapStore.delete(Object) instead of this method depending on configuration and runtime conditions. Implementations must not rely on this method being invoked for every flush.

      Error handling and retries:

      • If this method throws an exception, Hazelcast initiates retry handling.
      • On retry, Hazelcast invokes MapStore.delete(Object) one-by-one for the remaining keys.
      • If the implementation removes successfully deleted keys from the provided keys collection before throwing, those keys are treated as successful and are not retried.

      This allows implementations to signal partial success explicitly. Keys left in the keys collection after an exception will be retried individually; removed keys will not be passed to subsequent calls.

      Batch deletion does not imply atomicity or ordering guarantees.

      Specified by:
      deleteAll in interface MapStore<K,V>
      Parameters:
      keys - the keys of the entries to delete
    • load

      public 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.
      Specified by:
      load in interface MapLoader<K,V>
      Parameters:
      key - cannot be null
      Returns:
      value of the key; returning null value signals value missing in the underlying store
    • loadAll

      public Map<K,V> loadAll(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 null keys. The returned Map should not contain any null keys or values.

      Loading other items than what provided in keys prevents the map from being filled from the map store.

      Specified by:
      loadAll in interface MapLoader<K,V>
      Parameters:
      keys - keys of the values entries to load
      Returns:
      map of loaded key-value pairs.
    • loadAllKeys

      public Iterable<K> loadAllKeys()
      Loads all the keys from the store. The returned Iterable may return the keys lazily by loading them in batches. The Iterator of this Iterable may implement the Closeable interface 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 null keys.

      Specified by:
      loadAllKeys in interface MapLoader<K,V>
      Returns:
      all the keys. Keys inside the Iterable cannot be null.