Class CachePublisherImpl<K,V>
- All Implemented Interfaces:
CachePublisher<K,V>
-
Constructor Summary
ConstructorsConstructorDescriptionCachePublisherImpl(CacheImpl<K, V> cache, long flags) CachePublisherImpl(ClusterPublisherManager<K, V> clusterPublisherManager) -
Method Summary
Modifier and TypeMethodDescriptionAllows the caller to configure what level of consistency is required when retrieving data.Allows the caller to configure what level of consistency is required when retrieving data.batchSize(int batchSize) Configures publisher methods chunk size when retrieving remote values.<R> SegmentPublisherSupplier<R> entryPublisher(Function<? super org.reactivestreams.Publisher<CacheEntry<K, V>>, ? extends org.reactivestreams.Publisher<R>> transformer) Performs the given transformer on data in the cache, resulting in multiple values.<R> SegmentPublisherSupplier<R> entryPublisher(SerializableFunction<? super org.reactivestreams.Publisher<CacheEntry<K, V>>, ? extends org.reactivestreams.Publisher<R>> transformer) Same asCachePublisher.entryPublisher(Function)except that the Function must also implementSerializable.<R> CompletionStage<R> entryReduction(Function<? super org.reactivestreams.Publisher<CacheEntry<K, V>>, ? extends CompletionStage<R>> transformer, Function<? super org.reactivestreams.Publisher<R>, ? extends CompletionStage<R>> finalizer) Performs the given transformer and finalizer on data in the cache, resulting in a single value.<R> CompletionStage<R> entryReduction(SerializableFunction<? super org.reactivestreams.Publisher<CacheEntry<K, V>>, ? extends CompletionStage<R>> transformer, SerializableFunction<? super org.reactivestreams.Publisher<R>, ? extends CompletionStage<R>> finalizer) Same asCachePublisher.entryReduction(Function, Function)except that the Functions must also implementSerializable.Allows the caller to configure what level of consistency is required when retrieving data.<R> SegmentPublisherSupplier<R> keyPublisher(Function<? super org.reactivestreams.Publisher<K>, ? extends org.reactivestreams.Publisher<R>> transformer) Same asCachePublisher.entryPublisher(Function)except that the source publisher provided to the transformer is made up of keys only.<R> SegmentPublisherSupplier<R> keyPublisher(SerializableFunction<? super org.reactivestreams.Publisher<K>, ? extends org.reactivestreams.Publisher<R>> transformer) Same asCachePublisher.keyPublisher(Function)except that the Function must also implementSerializable.<R> CompletionStage<R> keyReduction(Function<? super org.reactivestreams.Publisher<K>, ? extends CompletionStage<R>> transformer, Function<? super org.reactivestreams.Publisher<R>, ? extends CompletionStage<R>> finalizer) Same asCachePublisher.entryReduction(Function, Function)except that the source publisher provided to the transformer is made up of keys only.<R> CompletionStage<R> keyReduction(SerializableFunction<? super org.reactivestreams.Publisher<K>, ? extends CompletionStage<R>> transformer, SerializableFunction<? super org.reactivestreams.Publisher<R>, ? extends CompletionStage<R>> finalizer) Same asCachePublisher.keyReduction(Function, Function)except that the Functions must also implementSerializable.Configures reduction methods to operate in parallel across nodes.Configures reduction methods to operate in sequential across nodes.Configures a publisher to publish all keys or values, overriding ifCachePublisher.withKeys(Set)was invoked.Configures the publisher to publish value(s) irrespective of their mapped segment.Configures the publisher to only publish keys or values that map to the given keys in the provided Set.withSegments(IntSet segments) Configures the publisher to only publish keys or values that map to a given segment in the provided IntSet.
-
Constructor Details
-
CachePublisherImpl
-
CachePublisherImpl
-
-
Method Details
-
parallelReduction
Description copied from interface:CachePublisherConfigures reduction methods to operate in parallel across nodes. This only affects methods likeCachePublisher.entryReduction(Function, Function)andCachePublisher.keyReduction(Function, Function). TheCachePublisher.entryPublisher(Function)andCachePublisher.keyPublisher(SerializableFunction)are not affected by this setting. Defaults to sequential.Care should be taken when setting this as it may cause adverse performance in some use cases.
- Specified by:
parallelReductionin interfaceCachePublisher<K,V> - Returns:
- a publisher that will perform reduction methods in parallel
-
sequentialReduction
Description copied from interface:CachePublisherConfigures reduction methods to operate in sequential across nodes. This only affects methods likeCachePublisher.entryReduction(Function, Function)andCachePublisher.keyReduction(Function, Function). TheCachePublisher.entryPublisher(Function)andCachePublisher.keyPublisher(SerializableFunction)are not affected by this setting. Defaults to sequential.- Specified by:
sequentialReductionin interfaceCachePublisher<K,V> - Returns:
- a publisher that will perform reduction methods in sequential
-
batchSize
Description copied from interface:CachePublisherConfigures publisher methods chunk size when retrieving remote values. This only affects methods likeCachePublisher.entryPublisher(Function)andCachePublisher.keyPublisher(Function). TheCachePublisher.entryReduction(Function, Function)andCachePublisher.keyReduction(Function, Function)methods are unaffected. Defaults to the cache's configuredStateTransferConfiguration.chunkSize().- Specified by:
batchSizein interfaceCachePublisher<K,V> - Parameters:
batchSize- the size of the batch to use when retrieving remote entries- Returns:
- a publisher that will perform publish methods with the given batch size
-
withKeys
Description copied from interface:CachePublisherConfigures the publisher to only publish keys or values that map to the given keys in the provided Set. Defaults to "all" keys, which can be done by invokingCachePublisher.withAllKeys().Note that if this and
CachePublisher.withSegments(IntSet)are both used, then a key is only returned if it is also maps to a provided segment.- Specified by:
withKeysin interfaceCachePublisher<K,V> - Parameters:
keys- set of keys that should only be used- Returns:
- a publisher that will filter published values based on the given keys
-
withAllKeys
Description copied from interface:CachePublisherConfigures a publisher to publish all keys or values, overriding ifCachePublisher.withKeys(Set)was invoked.- Specified by:
withAllKeysin interfaceCachePublisher<K,V> - Returns:
- a publisher that will return all keys or values.
-
withSegments
Description copied from interface:CachePublisherConfigures the publisher to only publish keys or values that map to a given segment in the provided IntSet. TheIntSetsis recommended to be used. Defaults to "all" segments.Note that if this and
CachePublisher.withKeys(Set)are both used, then a key is only returned if it is also maps to a provided segment.- Specified by:
withSegmentsin interfaceCachePublisher<K,V> - Parameters:
segments- determines what entries should be evaluated by only using ones that map to the given segments- Returns:
- a publisher that will filter published values based on the given segments
-
withAllSegments
Description copied from interface:CachePublisherConfigures the publisher to publish value(s) irrespective of their mapped segment. Defaults to "all" segments.- Specified by:
withAllSegmentsin interfaceCachePublisher<K,V> - Returns:
- a publisher that will publish all items irrespective of its segment
-
atMostOnce
Description copied from interface:CachePublisherAllows the caller to configure what level of consistency is required when retrieving data. At most is the weakest guarantee which ensures that data in a segment will be read once in a stable topology, but if there is a concurrent topology update a given segment or a portion of its data may not be returned.The default data consistency is
CachePublisher.exactlyOnce().- Specified by:
atMostOncein interfaceCachePublisher<K,V>
-
atLeastOnce
Description copied from interface:CachePublisherAllows the caller to configure what level of consistency is required when retrieving data. At least ensures that data in a segment will be read once in a stable topology, but if there is a concurrent topology update a given segment or a portion of its data may be returned multiple times.The default data consistency is
CachePublisher.exactlyOnce().- Specified by:
atLeastOncein interfaceCachePublisher<K,V> - Returns:
- a publisher that will provide at least once data semantics
-
exactlyOnce
Description copied from interface:CachePublisherAllows the caller to configure what level of consistency is required when retrieving data. Exactly once ensures the highest level of guarantee so that even under a topology all data is returned once.Exactly once is the default data consistency level.
- Specified by:
exactlyOncein interfaceCachePublisher<K,V> - Returns:
- a publisher that will provide exactly once data semantics
-
keyReduction
public <R> CompletionStage<R> keyReduction(Function<? super org.reactivestreams.Publisher<K>, ? extends CompletionStage<R>> transformer, Function<? super org.reactivestreams.Publisher<R>, ? extends CompletionStage<R>> finalizer) Description copied from interface:CachePublisherSame asCachePublisher.entryReduction(Function, Function)except that the source publisher provided to the transformer is made up of keys only.- Specified by:
keyReductionin interfaceCachePublisher<K,V> - Type Parameters:
R- return value type- Returns:
- CompletionStage that contains the resulting value when complete
-
keyReduction
public <R> CompletionStage<R> keyReduction(SerializableFunction<? super org.reactivestreams.Publisher<K>, ? extends CompletionStage<R>> transformer, SerializableFunction<? super org.reactivestreams.Publisher<R>, ? extends CompletionStage<R>> finalizer) Description copied from interface:CachePublisherSame asCachePublisher.keyReduction(Function, Function)except that the Functions must also implementSerializable.The compiler will pick this overload for lambda parameters, making them
Serializable.- Specified by:
keyReductionin interfaceCachePublisher<K,V> - Type Parameters:
R- return value type- Returns:
- CompletionStage that contains the resulting value when complete
-
entryReduction
public <R> CompletionStage<R> entryReduction(Function<? super org.reactivestreams.Publisher<CacheEntry<K, V>>, ? extends CompletionStage<R>> transformer, Function<? super org.reactivestreams.Publisher<R>, ? extends CompletionStage<R>> finalizer) Description copied from interface:CachePublisherPerforms the given transformer and finalizer on data in the cache, resulting in a single value. Depending on the deliveryGuarantee the transformer may be invoked 1..numSegments times. It could be that the transformer is invoked for every segment and produces a result. All of these results are then fed into the finalizer to produce a final result. If publisher is parallel the finalizer will be invoked on each node to ensure there is only a single result per node.If the provided transformer internally uses a reduction with a default value, that value must be its identity value. This is the same as can be seen at
Stream.reduce(Object, BinaryOperator). Then as long as the finalizer can handle the identity value it will be properly reduced.- Specified by:
entryReductionin interfaceCachePublisher<K,V> - Type Parameters:
R- return value type- Parameters:
transformer- reduces the given publisher of data eventually into a single value.finalizer- reduces all the single values produced by the transformer or this finalizer into one final value.- Returns:
- CompletionStage that contains the resulting value when complete
-
entryReduction
public <R> CompletionStage<R> entryReduction(SerializableFunction<? super org.reactivestreams.Publisher<CacheEntry<K, V>>, ? extends CompletionStage<R>> transformer, SerializableFunction<? super org.reactivestreams.Publisher<R>, ? extends CompletionStage<R>> finalizer) Description copied from interface:CachePublisherSame asCachePublisher.entryReduction(Function, Function)except that the Functions must also implementSerializable.The compiler will pick this overload for lambda parameters, making them
Serializable.- Specified by:
entryReductionin interfaceCachePublisher<K,V> - Type Parameters:
R- return value type- Parameters:
transformer- reduces the given publisher of data eventually into a single value.finalizer- reduces all the single values produced by the transformer or this finalizer into one final value.- Returns:
- CompletionStage that contains the resulting value when complete
-
keyPublisher
public <R> SegmentPublisherSupplier<R> keyPublisher(Function<? super org.reactivestreams.Publisher<K>, ? extends org.reactivestreams.Publisher<R>> transformer) Description copied from interface:CachePublisherSame asCachePublisher.entryPublisher(Function)except that the source publisher provided to the transformer is made up of keys only.- Specified by:
keyPublisherin interfaceCachePublisher<K,V> - Type Parameters:
R- return value type- Returns:
- Publisher that when subscribed to will return the results and notify of segment completion if necessary
-
keyPublisher
public <R> SegmentPublisherSupplier<R> keyPublisher(SerializableFunction<? super org.reactivestreams.Publisher<K>, ? extends org.reactivestreams.Publisher<R>> transformer) Description copied from interface:CachePublisherSame asCachePublisher.keyPublisher(Function)except that the Function must also implementSerializable.The compiler will pick this overload for lambda parameters, making them
Serializable.- Specified by:
keyPublisherin interfaceCachePublisher<K,V> - Type Parameters:
R- return value type- Returns:
- Publisher that when subscribed to will return the results and notify of segment completion if necessary
-
entryPublisher
public <R> SegmentPublisherSupplier<R> entryPublisher(Function<? super org.reactivestreams.Publisher<CacheEntry<K, V>>, ? extends org.reactivestreams.Publisher<R>> transformer) Description copied from interface:CachePublisherPerforms the given transformer on data in the cache, resulting in multiple values. If a single value is desired, the user should useCachePublisher.entryReduction(Function, Function)instead as it can optimize some things. Depending on the deliveryGuarantee the transformer may be invoked 1..numSegments times per node. Results from a given node will retrieve values up tobatchSizevalues until some are consumed.For example when using RxJava and using an intermediate operation such as
Flowable.switchIfEmpty(Publisher)this can add elements if the given Publisher is empty, and it is very possible that a segment may not have entries and therefore may add the elements the switched Publisher returns multiple times.Methods that add elements to the returned Publisher are fine as long as they are tied to a specific entry, for example
Flowable.flatMap(io.reactivex.rxjava3.functions.Function)which can reproduce the same elements when provided the same input entry from the cache.- Specified by:
entryPublisherin interfaceCachePublisher<K,V> - Type Parameters:
R- return value type- Parameters:
transformer- transform the given stream of data into something else (requires non null)- Returns:
- Publisher that when subscribed to will return the results and notify of segment completion if necessary
-
entryPublisher
public <R> SegmentPublisherSupplier<R> entryPublisher(SerializableFunction<? super org.reactivestreams.Publisher<CacheEntry<K, V>>, ? extends org.reactivestreams.Publisher<R>> transformer) Description copied from interface:CachePublisherSame asCachePublisher.entryPublisher(Function)except that the Function must also implementSerializable.The compiler will pick this overload for lambda parameters, making them
Serializable.- Specified by:
entryPublisherin interfaceCachePublisher<K,V> - Type Parameters:
R- return value type- Parameters:
transformer- transform the given stream of data into something else (requires non null)- Returns:
- Publisher that when subscribed to will return the results and notify of segment completion if necessary
-