Class HazelcastMapAdapter<T>
java.lang.Object
com.norconex.crawler.core.cluster.impl.hazelcast.HazelcastMapAdapter<T>
- Type Parameters:
T- the type of values stored in the cache view
- All Implemented Interfaces:
CacheMap<T>
Hazelcast IMap-based implementation of the Cache interface.
Adapter performs transparent conversion between values exposed as
type
T and the values actually stored in Hazelcast which
may be plain String JSON (or raw String) or actual objects.
This allows persisting everything as strings in the DB-backed
MapStore while presenting typed objects to callers.-
Constructor Summary
ConstructorsConstructorDescriptionHazelcastMapAdapter(com.hazelcast.map.IMap<String, ?> hzMap, com.hazelcast.core.HazelcastInstance hzInstance, Class<T> type) -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()computeIfAbsent(String key, Function<String, ? extends T> mappingFunction) computeIfPresent(String key, BiFunction<String, ? super T, ? extends T> remappingFunction) booleancontainsKey(String key) longcount(QueryFilter filter) Counts the number of entries matching the given query filter.voiddelete(QueryFilter filter) Deletes entries matching the given query filter.voidforEach(BiConsumer<String, ? super T> action) getName()Gets the name of this cache.getOrDefault(String key, T defaultValue) booleanisEmpty()booleanReturns whether this cache persists data across restarts.keys()Returns all keys in this cache.voidloadAll()Eagerly loads all entries from the backing store (e.g., JDBC) into this cache.voidvoidputIfAbsent(String key, T value) If the specified key is not already associated with a value, associates it with the given value.query(QueryFilter filter) Queries the cache for entries matching the given query filter.queryIterator(QueryFilter filter) Queries the cache for entries matching the given filter and returns an iterator for memory-efficient processing of results.voidbooleanlongsize()Counts the number of entries in this cache.vendor()Return the underlying Hazelcast IMap as typed view.
-
Constructor Details
-
HazelcastMapAdapter
-
-
Method Details
-
isEmpty
public boolean isEmpty() -
put
-
putAll
-
get
-
remove
-
clear
public void clear() -
computeIfAbsent
- Specified by:
computeIfAbsentin interfaceCacheMap<T>
-
computeIfPresent
public Optional<T> computeIfPresent(String key, BiFunction<String, ? super T, ? extends T> remappingFunction) - Specified by:
computeIfPresentin interfaceCacheMap<T>
-
compute
-
merge
-
containsKey
- Specified by:
containsKeyin interfaceCacheMap<T>
-
getOrDefault
- Specified by:
getOrDefaultin interfaceCacheMap<T>
-
putIfAbsent
Description copied from interface:CacheMapIf the specified key is not already associated with a value, associates it with the given value. This is equivalent to, for this cache:if (!cache.containsKey(key)) return map.put(key, value); else return map.get(key);except that the action is performed atomically.- Specified by:
putIfAbsentin interfaceCacheMap<T>- Parameters:
key- key with which the specified value is to be associatedvalue- value to be associated with the specified key- Returns:
- the previous value associated with the specified key, or
nullif there was no mapping for the key.
-
replace
-
query
Description copied from interface:CacheMapQueries the cache for entries matching the given query filter. Note: This method loads all results into memory at once. For large result sets, consider usingCacheMap.queryIterator(com.norconex.crawler.core.cluster.QueryFilter)instead. -
queryIterator
Description copied from interface:CacheMapQueries the cache for entries matching the given filter and returns an iterator for memory-efficient processing of results. This avoids loading all results into memory at once.- Specified by:
queryIteratorin interfaceCacheMap<T>- Parameters:
filter- the query filter- Returns:
- an iterator over the matching entries
-
count
Description copied from interface:CacheMapCounts the number of entries matching the given query filter. -
size
public long size()Description copied from interface:CacheMapCounts the number of entries in this cache. -
delete
Description copied from interface:CacheMapDeletes entries matching the given query filter. -
forEach
-
keys
Description copied from interface:CacheMapReturns all keys in this cache. For distributed caches, this includes keys from all nodes in the cluster, not just locally-owned keys. -
loadAll
public void loadAll()Description copied from interface:CacheMapEagerly loads all entries from the backing store (e.g., JDBC) into this cache. For caches configured withLAZYinitial load mode, this ensures subÂsequentCacheMap.size(),CacheMap.forEach(java.util.function.BiConsumer<java.lang.String, ? super T>), andCacheMap.keys()calls return correct results. If the cache already has its data loaded (e.g.,EAGERmode), this is a no-op. -
vendor
Return the underlying Hazelcast IMap as typed view. Use with caution: underlying values are stored as Objects/Strings.- Returns:
- hazelcast IMap
-
isPersistent
public boolean isPersistent()Description copied from interface:CacheMapReturns whether this cache persists data across restarts.- Specified by:
isPersistentin interfaceCacheMap<T>- Returns:
- true if the cache is persistent, false if ephemeral
-
getName
Description copied from interface:CacheMapGets the name of this cache.
-