Class BulkOperations<K,V>
java.lang.Object
cloud.opencode.base.cache.bulk.BulkOperations<K,V>
- Type Parameters:
K- key type | 键类型V- value type | 值类型Security | 安全性:
- Thread-safe: Yes (delegates to thread-safe cache) - 线程安全: 是(委托给线程安全的缓存)
- Null-safe: Yes - 空值安全: 是
Bulk Operations - Enhanced bulk operations for cache
批量操作 - 缓存的增强批量操作
Provides advanced bulk operations with atomic semantics, conditional updates, and batch processing.
提供具有原子语义、条件更新和批处理的高级批量操作。
Features | 主要功能:
- Atomic compare-and-swap-all - 原子比较并交换全部
- Conditional bulk put - 条件批量放置
- Batch processing with callback - 带回调的批处理
- Parallel batch operations - 并行批量操作
- Bulk compute operations - 批量计算操作
Usage Examples | 使用示例:
BulkOperations<String, User> bulk = BulkOperations.on(cache);
// Bulk put all - best-effort rollback on failure
boolean success = bulk.bulkPutAll(users);
// Conditional put - only if all keys present
boolean success = bulk.putAllIfAllPresent(updates);
// Batch process with callback
bulk.batchProcess(keys, 100, batch -> {
// Process each batch of 100
});
// Compute all values
bulk.computeAll(keys, (key, oldValue) -> newValue);
- Since:
- JDK 25, opencode-base-cache V2.0.5
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceBatch processor functional interface 批处理器函数式接口static final recordResult of batch processing 批处理的结果static final recordResult of bulk put operation 批量放置操作的结果static final recordValue with TTL for bulk put 用于批量放置的带 TTL 的值 -
Method Summary
Modifier and TypeMethodDescriptionatomicInvalidateAll(Iterable<? extends K> keys) Atomic invalidate all - either all succeed or none 原子使全部无效 - 要么全部成功,要么都不intbatchProcess(Iterable<? extends K> keys, int batchSize, BulkOperations.BatchProcessor<K, V> processor) Process keys in batches 分批处理键batchProcessParallel(List<? extends K> keys, int batchSize, int parallelism, BulkOperations.BatchProcessor<K, V> processor) Process keys in parallel batches 并行分批处理键booleanbulkPutAll(Map<? extends K, ? extends V> entries) Bulk put all entries with best-effort rollback on failure.computeAll(Iterable<? extends K> keys, BiFunction<? super K, ? super V, ? extends V> remappingFunction) Compute values for all specified keys 为所有指定的键计算值Compute values for all absent keys 为所有不存在的键计算值booleaninvalidateAllIfMatch(Map<? extends K, ? extends V> expected) Invalidate all only if all values match expected 仅当所有值与预期匹配时才使全部无效static <K,V> BulkOperations <K, V> Create bulk operations for a cache 为缓存创建批量操作putAllIfAbsent(Map<? extends K, ? extends V> entries) Put entries that are absent, skip existing 放置不存在的条目,跳过已存在的booleanputAllIfAllAbsent(Map<? extends K, ? extends V> entries) Put all only if all keys are absent 仅当所有键都不存在时才放置全部booleanputAllIfAllPresent(Map<? extends K, ? extends V> entries) Put all only if all keys are already present 仅当所有键都已存在时才放置全部voidputAllWithTtl(Map<? extends K, ? extends BulkOperations.TtlValue<V>> entries) Put all with individual TTLs 放置全部并带有各自的 TTLintreplaceAllMatching(BiPredicate<K, V> predicate, BiFunction<? super K, ? super V, ? extends V> remappingFunction) Replace all values matching predicate 替换所有匹配谓词的值
-
Method Details
-
on
Create bulk operations for a cache 为缓存创建批量操作- Type Parameters:
K- key type | 键类型V- value type | 值类型- Parameters:
cache- the cache | 缓存- Returns:
- bulk operations | 批量操作
-
bulkPutAll
Bulk put all entries with best-effort rollback on failure. 批量放置所有条目,失败时尽最大努力回滚。Note: This is NOT truly atomic. Entries are put one by one and concurrent readers may see partial updates. If an exception occurs mid-way, previously inserted entries are rolled back on a best-effort basis.
- Parameters:
entries- entries to put | 要放置的条目- Returns:
- true if all succeeded | 如果全部成功返回 true
-
atomicInvalidateAll
-
putAllIfAllPresent
-
putAllIfAllAbsent
-
putAllIfAbsent
Put entries that are absent, skip existing 放置不存在的条目,跳过已存在的- Parameters:
entries- entries to put | 要放置的条目- Returns:
- result with counts of inserted and skipped | 带有插入和跳过计数的结果
-
invalidateAllIfMatch
-
batchProcess
public int batchProcess(Iterable<? extends K> keys, int batchSize, BulkOperations.BatchProcessor<K, V> processor) Process keys in batches 分批处理键- Parameters:
keys- keys to process | 要处理的键batchSize- batch size | 批次大小processor- batch processor | 批处理器- Returns:
- total processed count | 处理的总数
-
batchProcessParallel
public CompletableFuture<BulkOperations.BatchResult> batchProcessParallel(List<? extends K> keys, int batchSize, int parallelism, BulkOperations.BatchProcessor<K, V> processor) Process keys in parallel batches 并行分批处理键- Parameters:
keys- keys to process | 要处理的键batchSize- batch size | 批次大小parallelism- number of parallel threads | 并行线程数processor- batch processor | 批处理器- Returns:
- future completing when all batches done | 所有批次完成时完成的 Future
-
computeAll
public Map<K,V> computeAll(Iterable<? extends K> keys, BiFunction<? super K, ? super V, ? extends V> remappingFunction) Compute values for all specified keys 为所有指定的键计算值- Parameters:
keys- keys to compute | 要计算的键remappingFunction- function to compute new value | 计算新值的函数- Returns:
- map of new values | 新值的映射
-
computeAllIfAbsent
-
replaceAllMatching
public int replaceAllMatching(BiPredicate<K, V> predicate, BiFunction<? super K, ? super V, ? extends V> remappingFunction) Replace all values matching predicate 替换所有匹配谓词的值- Parameters:
predicate- filter for entries to replace | 要替换的条目过滤器remappingFunction- function to compute new value | 计算新值的函数- Returns:
- count of replaced entries | 替换的条目数
-
putAllWithTtl
Put all with individual TTLs 放置全部并带有各自的 TTL- Parameters:
entries- entries with their TTLs | 带有 TTL 的条目
-