Class MapSinkBuilder<T,K,V>
- Type Parameters:
T
- specifies type of input that will be written to sinkK
- specifies key type of map sinkV
- specifies value type of map sink
Builds a local Map sink unless one of dataConnectionRef
or
clientConfig
is provided, in which case a remote sink is built.
The required parameters are:
- mapName
- toKeyFn - key-extracting function
- one of toValue/updateFn - key ex
This sink provides the exactly-once guarantee thanks to idempotent updates. It means that the value with the same key is not appended, but overwritten. After the job is restarted from snapshot, duplicate items will not change the state in the target map.
- Since:
- 5.4
-
Constructor Summary
ConstructorDescriptionMapSinkBuilder
(String mapName) CreatesMapSinkBuilder
to build a local or remote Map sink -
Method Summary
Modifier and TypeMethodDescriptionbuild()
Build the sink.clientConfig
(ClientConfig clientConfig) Sets theClientConfig
with configuration for a Hazelcast client to use for remote Map sink.dataConnectionRef
(DataConnectionRef dataConnectionRef) Sets theDataConnectionRef
reference to a HazelcastDataConnection to use for remote Map sink.mergeFn
(BinaryOperatorEx<V> mergeFn) Set the function to merge the existing value with new value.toKeyFn
(FunctionEx<? super T, ? extends K> toKeyFn) Set the key-extracting function.toValueFn
(FunctionEx<? super T, ? extends V> toValueFn) Set the function to extract a value from the incoming items.updateFn
(BiFunctionEx<? super V, ? super T, ? extends V> updateFn) Set the function to update the value in Hazelcast IMap.
-
Constructor Details
-
MapSinkBuilder
CreatesMapSinkBuilder
to build a local or remote Map sink- Parameters:
mapName
- name of the map to sink into
-
-
Method Details
-
dataConnectionRef
Sets theDataConnectionRef
reference to a HazelcastDataConnection to use for remote Map sink.Only one of
dataConnectionRef
andclientConfig
can be set.- Parameters:
dataConnectionRef
- reference to aHazelcastDataConnection
-
clientConfig
Sets theClientConfig
with configuration for a Hazelcast client to use for remote Map sink.Only one of
dataConnectionRef
andclientConfig
can be set.- Parameters:
clientConfig
- remote Hazelcast client configuration
-
toKeyFn
Set the key-extracting function. The resulting value will be used as the key in the sink IMap.The function must be
Serializable
.- Parameters:
toKeyFn
- function to extract key from incoming items
-
toValueFn
Set the function to extract a value from the incoming items. The value will be put into the IMap under key extracted usingtoKeyFn
.Only one of
toValueFn
orupdateFn
can be set. OptionallymergeFn
can be set together with `toValueFn`.The function must be
Serializable
.The given functions must be stateless and cooperative.
- Parameters:
toValueFn
- function to extract value from incoming items
-
updateFn
Set the function to update the value in Hazelcast IMap.For each item it receives, it applies
toKeyFn
to get the key and then appliesupdateFn
to the existing value in the map and the received item to acquire the new value to associate with the key. If the new value isnull
, it removes the key from the map. Expressed as code, the sink performs the equivalent of the following for each item:K key = toKeyFn.apply(item); V oldValue = map.get(key); V newValue = updateFn.apply(oldValue, item); if (newValue == null) map.remove(key); else map.put(key, newValue);
Note: This operation is NOT lock-aware, it will process the entries no matter if they are locked or not. Use
MapSinkEntryProcessorBuilder
if you need locking.The function must be
Serializable
.The given functions must be stateless and cooperative.
- Parameters:
updateFn
- function that receives the existing map value and the item and returns the new map value
-
mergeFn
Set the function to merge the existing value with new value.If the map already contains the key, it applies the given
mergeFn
to resolve the existing and the proposed value into the value to use. If the value comes out asnull
, it removes the key from the map. Expressed as code, the sink performs the equivalent of the following for each item:K key = toKeyFn.apply(item); V oldValue = map.get(key); V newValue = toValueFn.apply(item); V resolved = (oldValue == null) ? newValue : mergeFn.apply(oldValue, newValue); if (value == null) map.remove(key); else map.put(key, value);
Note: This operation is NOT lock-aware, it will process the entries no matter if they are locked or not. UseMapSinkEntryProcessorBuilder
if you need locking.The function must be
Serializable
.The given functions must be stateless and cooperative.
- Parameters:
mergeFn
- function that merges the existing value with the value acquired from the received item
-
build
Build the sink.The default local parallelism for this sink is 1.
- Returns:
- the sink
-