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();
}
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;
}
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);
}
});
}
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;
}
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);
}
Aggregations