use of org.infinispan.filter.KeyValueFilterConverterFactory in project infinispan by infinispan.
the class DefaultIterationManager method start.
@Override
public IterationState start(AdvancedCache cache, BitSet segments, String filterConverterFactory, List<byte[]> filterConverterParams, MediaType requestValueType, int batch, boolean metadata) {
String iterationId = Util.threadLocalRandomUUID().toString();
EmbeddedCacheManager cacheManager = SecurityActions.getEmbeddedCacheManager(cache);
EncoderRegistry encoderRegistry = SecurityActions.getGlobalComponentRegistry(cacheManager).getComponent(EncoderRegistry.class);
DataConversion valueDataConversion = cache.getValueDataConversion();
Function<Object, Object> unmarshaller = p -> encoderRegistry.convert(p, requestValueType, APPLICATION_OBJECT);
MediaType storageMediaType = cache.getValueDataConversion().getStorageMediaType();
IterationSegmentsListener segmentListener = new IterationSegmentsListener();
CacheStream<CacheEntry<Object, Object>> stream;
Stream<CacheEntry<Object, Object>> filteredStream;
Function<Object, Object> resultTransformer = Function.identity();
AdvancedCache iterationCache = cache;
if (filterConverterFactory == null) {
stream = cache.cacheEntrySet().stream();
if (segments != null) {
stream.filterKeySegments(IntSets.from(segments.stream().iterator()));
}
filteredStream = stream.segmentCompletionListener(segmentListener);
} else {
KeyValueFilterConverterFactory factory = getFactory(filterConverterFactory);
KeyValuePair<KeyValueFilterConverter, Boolean> filter = buildFilter(factory, filterConverterParams.toArray(Util.EMPTY_BYTE_ARRAY_ARRAY), unmarshaller);
KeyValueFilterConverter customFilter = filter.getKey();
MediaType filterMediaType = customFilter.format();
if (filterMediaType != null && filterMediaType.equals(storageMediaType)) {
iterationCache = cache.withMediaType(filterMediaType, filterMediaType);
}
stream = iterationCache.cacheEntrySet().stream();
if (segments != null) {
stream.filterKeySegments(IntSets.from(segments.stream().iterator()));
}
IterationFilter iterationFilter = new IterationFilter(storageMediaType, requestValueType, Optional.of(filter.getKey()));
filteredStream = filterAndConvert(stream.segmentCompletionListener(segmentListener), iterationFilter);
if (filterMediaType != null && !storageMediaType.equals(requestValueType)) {
resultTransformer = valueDataConversion::fromStorage;
}
}
Iterator<CacheEntry<Object, Object>> iterator = filteredStream.iterator();
DefaultIterationState iterationState = new DefaultIterationState(iterationId, segmentListener, iterator, stream, batch, metadata, resultTransformer, new IterationReaper(this, iterationId));
iterationStateMap.put(iterationId, iterationState);
if (log.isTraceEnabled())
log.tracef("Started iteration %s", iterationId);
return iterationState;
}
Aggregations