use of org.infinispan.encoding.DataConversion in project infinispan by infinispan.
the class MigrationTask method migrateEntriesWithMetadata.
private void migrateEntriesWithMetadata(RemoteCache<Object, Object> sourceCache, AtomicInteger counter, ExecutorService executorService, Cache<Object, Object> cache) {
AdvancedCache<Object, Object> destinationCache = cache.getAdvancedCache();
DataConversion keyDataConversion = destinationCache.getKeyDataConversion();
DataConversion valueDataConversion = destinationCache.getValueDataConversion();
try (CloseableIterator<Entry<Object, MetadataValue<Object>>> iterator = sourceCache.retrieveEntriesWithMetadata(segments, readBatch)) {
CompletableFuture<?>[] completableFutures = StreamSupport.stream(spliteratorUnknownSize(iterator, 0), false).map(entry -> {
Object key = entry.getKey();
MetadataValue<Object> metadataValue = entry.getValue();
int lifespan = metadataValue.getLifespan();
int maxIdle = metadataValue.getMaxIdle();
long version = metadataValue.getVersion();
Metadata metadata = new EmbeddedMetadata.Builder().version(new NumericVersion(version)).lifespan(lifespan, TimeUnit.SECONDS).maxIdle(maxIdle, TimeUnit.SECONDS).build();
if (!deletedKeys.contains(ByteArrayWrapper.INSTANCE.wrap(key))) {
return CompletableFuture.supplyAsync(() -> {
int currentCount = counter.incrementAndGet();
if (log.isDebugEnabled() && currentCount % 100 == 0)
log.debugf(">> Migrated %s entries\n", currentCount);
return writeToDestinationCache(entry, metadata, keyDataConversion, valueDataConversion);
}, executorService);
}
return CompletableFuture.completedFuture(null);
}).toArray(CompletableFuture[]::new);
CompletableFuture.allOf(completableFutures).join();
}
}
Aggregations