Search in sources :

Example 11 with MediaType

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

the class EntryEventListener method inject.

@Inject
void inject(EncoderRegistry encoderRegistry, GlobalConfiguration globalConfiguration) {
    MediaType keyBytesMediaType = bytesMediaType(storageConfigurationManager.getKeyStorageMediaType(), persistenceMarshaller.mediaType());
    if (encoderRegistry.isConversionSupported(keyBytesMediaType, MediaType.APPLICATION_JSON)) {
        keyJsonTranscoder = encoderRegistry.getTranscoder(keyBytesMediaType, MediaType.APPLICATION_JSON);
    }
    MediaType valueBytesMediaType = bytesMediaType(storageConfigurationManager.getKeyStorageMediaType(), persistenceMarshaller.mediaType());
    if (encoderRegistry.isConversionSupported(keyBytesMediaType, MediaType.APPLICATION_JSON)) {
        valueJsonTranscoder = encoderRegistry.getTranscoder(valueBytesMediaType, MediaType.APPLICATION_JSON);
    }
    clusterName = globalConfiguration.transport().clusterName();
    CloudEventsGlobalConfiguration cloudEventsGlobalConfiguration = globalConfiguration.module(CloudEventsGlobalConfiguration.class);
    cacheEntriesTopic = cloudEventsGlobalConfiguration.cacheEntriesTopic();
}
Also used : CloudEventsGlobalConfiguration(org.infinispan.cloudevents.configuration.CloudEventsGlobalConfiguration) MediaType(org.infinispan.commons.dataconversion.MediaType) Inject(org.infinispan.factories.annotations.Inject)

Example 12 with MediaType

use of org.infinispan.commons.dataconversion.MediaType 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 13 with MediaType

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

the class IterationFilter method injectDependencies.

@Inject
public void injectDependencies(Cache cache, EncoderRegistry encoderRegistry) {
    providedFilter.ifPresent(kvfc -> {
        cache.getAdvancedCache().getComponentRegistry().wireDependencies(kvfc);
        MediaType filterFormat = kvfc.format();
        if (filterFormat != null && !filterFormat.equals(storageMediaType)) {
            applyBefore = encoderRegistry.getTranscoder(filterFormat, storageMediaType);
        }
        if (filterFormat != null && !filterFormat.equals(requestType)) {
            applyAfter = encoderRegistry.getTranscoder(filterFormat, requestType);
        }
    });
}
Also used : MediaType(org.infinispan.commons.dataconversion.MediaType) Inject(org.infinispan.factories.annotations.Inject)

Example 14 with MediaType

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

the class DistributedServerTask method prepareContext.

private TaskContext prepareContext(EmbeddedCacheManager embeddedCacheManager, Cache<Object, Object> cache, Marshaller marshaller) {
    TaskContext context = new TaskContext();
    context.cacheManager(embeddedCacheManager);
    Map<String, String> params = parameters.stream().collect(Collectors.toMap(p -> p.key, p -> p.value));
    context.parameters(params);
    MediaType type = MediaType.APPLICATION_OBJECT;
    if (cache != null)
        context.cache(cache.getAdvancedCache().withMediaType(type, type));
    if (marshaller != null)
        context.marshaller(marshaller);
    return context;
}
Also used : CacheException(org.infinispan.commons.CacheException) GlobalComponentRegistry(org.infinispan.factories.GlobalComponentRegistry) TaskContext(org.infinispan.tasks.TaskContext) StreamingMarshaller(org.infinispan.commons.marshall.StreamingMarshaller) Cache(org.infinispan.Cache) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) ProtoStreamTypeIds(org.infinispan.commons.marshall.ProtoStreamTypeIds) ArrayList(java.util.ArrayList) ProtoFactory(org.infinispan.protostream.annotations.ProtoFactory) List(java.util.List) MediaType(org.infinispan.commons.dataconversion.MediaType) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) Map(java.util.Map) ProtoTypeId(org.infinispan.protostream.annotations.ProtoTypeId) ProtoField(org.infinispan.protostream.annotations.ProtoField) Marshaller(org.infinispan.commons.marshall.Marshaller) TaskContext(org.infinispan.tasks.TaskContext) MediaType(org.infinispan.commons.dataconversion.MediaType)

Example 15 with MediaType

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

the class CheckAddressTask method getRequestMediaTypes.

private static KeyValuePair<MediaType, MediaType> getRequestMediaTypes(HotRodHeader header, Configuration configuration) {
    MediaType keyRequestType = header == null ? APPLICATION_UNKNOWN : header.getKeyMediaType();
    MediaType valueRequestType = header == null ? APPLICATION_UNKNOWN : header.getValueMediaType();
    if (header != null && HotRodVersion.HOTROD_28.isOlder(header.version)) {
        // Pre-2.8 clients always send protobuf payload to the metadata cache
        if (header.cacheName.equals(PROTOBUF_METADATA_CACHE_NAME)) {
            keyRequestType = APPLICATION_PROTOSTREAM;
            valueRequestType = APPLICATION_PROTOSTREAM;
        } else {
            // Pre-2.8 clients always sent query encoded as protobuf unless object store is used.
            if (header.op == HotRodOperation.QUERY) {
                boolean objectStorage = APPLICATION_OBJECT.match(configuration.encoding().valueDataType().mediaType());
                keyRequestType = objectStorage ? APPLICATION_JBOSS_MARSHALLING : APPLICATION_PROTOSTREAM;
                valueRequestType = objectStorage ? APPLICATION_JBOSS_MARSHALLING : APPLICATION_PROTOSTREAM;
            }
        }
    }
    return new KeyValuePair<>(keyRequestType, valueRequestType);
}
Also used : KeyValuePair(org.infinispan.util.KeyValuePair) MediaType(org.infinispan.commons.dataconversion.MediaType)

Aggregations

MediaType (org.infinispan.commons.dataconversion.MediaType)54 NettyRestResponse (org.infinispan.rest.NettyRestResponse)13 MediaTypeUtils.negotiateMediaType (org.infinispan.rest.resources.MediaTypeUtils.negotiateMediaType)12 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)9 Map (java.util.Map)8 EncoderRegistry (org.infinispan.marshall.core.EncoderRegistry)7 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)6 List (java.util.List)5 Function (java.util.function.Function)5 AdvancedCache (org.infinispan.AdvancedCache)5 Cache (org.infinispan.Cache)5 DataConversion (org.infinispan.encoding.DataConversion)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 CacheException (org.infinispan.commons.CacheException)4 Configuration (org.infinispan.configuration.cache.Configuration)4 IOException (java.io.IOException)3 Collections (java.util.Collections)3 Optional (java.util.Optional)3