Search in sources :

Example 1 with APPLICATION_OBJECT

use of org.infinispan.commons.dataconversion.MediaType.APPLICATION_OBJECT 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;
}
Also used : WithinThreadExecutor(org.infinispan.util.concurrent.WithinThreadExecutor) Arrays(java.util.Arrays) CacheStream(org.infinispan.CacheStream) TimeServiceTicker(org.infinispan.commons.time.TimeServiceTicker) IntSets(org.infinispan.commons.util.IntSets) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) MediaType(org.infinispan.commons.dataconversion.MediaType) AdvancedCache(org.infinispan.AdvancedCache) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) APPLICATION_OBJECT(org.infinispan.commons.dataconversion.MediaType.APPLICATION_OBJECT) Map(java.util.Map) KeyValueFilterConverterFactory(org.infinispan.filter.KeyValueFilterConverterFactory) ParamKeyValueFilterConverterFactory(org.infinispan.filter.ParamKeyValueFilterConverterFactory) EncoderRegistry(org.infinispan.marshall.core.EncoderRegistry) RemovalListener(com.github.benmanes.caffeine.cache.RemovalListener) KeyValuePair(org.infinispan.util.KeyValuePair) KeyValueFilterConverter(org.infinispan.filter.KeyValueFilterConverter) Caffeine(com.github.benmanes.caffeine.cache.Caffeine) CacheFilters.filterAndConvert(org.infinispan.filter.CacheFilters.filterAndConvert) Iterator(java.util.Iterator) CacheEntry(org.infinispan.container.entries.CacheEntry) BaseCacheStream(org.infinispan.BaseCacheStream) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Util(org.infinispan.commons.util.Util) Log(org.infinispan.server.hotrod.logging.Log) Set(java.util.Set) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Stream(java.util.stream.Stream) OperationStatus(org.infinispan.server.hotrod.OperationStatus) Closeable(java.io.Closeable) Optional(java.util.Optional) LogFactory(org.infinispan.commons.logging.LogFactory) DataConversion(org.infinispan.encoding.DataConversion) BitSet(java.util.BitSet) Collections(java.util.Collections) TimeService(org.infinispan.commons.time.TimeService) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) CacheEntry(org.infinispan.container.entries.CacheEntry) DataConversion(org.infinispan.encoding.DataConversion) KeyValueFilterConverterFactory(org.infinispan.filter.KeyValueFilterConverterFactory) ParamKeyValueFilterConverterFactory(org.infinispan.filter.ParamKeyValueFilterConverterFactory) KeyValueFilterConverter(org.infinispan.filter.KeyValueFilterConverter) EncoderRegistry(org.infinispan.marshall.core.EncoderRegistry) MediaType(org.infinispan.commons.dataconversion.MediaType) AdvancedCache(org.infinispan.AdvancedCache)

Example 2 with APPLICATION_OBJECT

use of org.infinispan.commons.dataconversion.MediaType.APPLICATION_OBJECT in project infinispan by infinispan.

the class ServerTaskEngine method invokeTask.

private <T> CompletableFuture<T> invokeTask(TaskContext context, ServerTaskWrapper<T> task) {
    ServerTaskRunner runner;
    switch(task.getExecutionMode()) {
        case ONE_NODE:
            runner = localRunner;
            break;
        default:
            runner = distributedRunner;
            break;
    }
    launderParameters(context);
    MediaType requestMediaType = context.getCache().map(c -> c.getAdvancedCache().getValueDataConversion().getRequestMediaType()).orElse(MediaType.MATCH_ALL);
    context.getCache().ifPresent(c -> context.cache(c.getAdvancedCache().withMediaType(APPLICATION_OBJECT, APPLICATION_OBJECT)));
    return runner.execute(task.getName(), context).thenApply(r -> (T) scriptConversions.convertToRequestType(r, APPLICATION_OBJECT, requestMediaType));
}
Also used : AuthorizationPermission(org.infinispan.security.AuthorizationPermission) GlobalComponentRegistry(org.infinispan.factories.GlobalComponentRegistry) AuthorizationManager(org.infinispan.security.AuthorizationManager) TaskContext(org.infinispan.tasks.TaskContext) CompletableFuture(java.util.concurrent.CompletableFuture) ScriptConversions(org.infinispan.scripting.utils.ScriptConversions) ArrayList(java.util.ArrayList) List(java.util.List) MediaType(org.infinispan.commons.dataconversion.MediaType) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) Authorizer(org.infinispan.security.impl.Authorizer) APPLICATION_OBJECT(org.infinispan.commons.dataconversion.MediaType.APPLICATION_OBJECT) Map(java.util.Map) EncoderRegistry(org.infinispan.marshall.core.EncoderRegistry) TaskEngine(org.infinispan.tasks.spi.TaskEngine) SerializationContextRegistry(org.infinispan.marshall.protostream.impl.SerializationContextRegistry) Task(org.infinispan.tasks.Task) BlockingManager(org.infinispan.util.concurrent.BlockingManager) MediaType(org.infinispan.commons.dataconversion.MediaType)

Aggregations

ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 MediaType (org.infinispan.commons.dataconversion.MediaType)2 APPLICATION_OBJECT (org.infinispan.commons.dataconversion.MediaType.APPLICATION_OBJECT)2 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)2 EncoderRegistry (org.infinispan.marshall.core.EncoderRegistry)2 Caffeine (com.github.benmanes.caffeine.cache.Caffeine)1 RemovalListener (com.github.benmanes.caffeine.cache.RemovalListener)1 Closeable (java.io.Closeable)1 Arrays (java.util.Arrays)1 BitSet (java.util.BitSet)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 Optional (java.util.Optional)1 Set (java.util.Set)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 TimeUnit (java.util.concurrent.TimeUnit)1