Search in sources :

Example 21 with MediaType

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

the class ObjectRemoteQueryManager method createEntityNamesResolver.

private EntityNameResolver<Class<?>> createEntityNamesResolver(MediaType mediaType) {
    if (mediaType.match(APPLICATION_PROTOSTREAM)) {
        return new ProtobufEntityNameResolver(serCtx);
    } else {
        ClassLoader classLoader = cr.getGlobalComponentRegistry().getComponent(ClassLoader.class);
        ReflectionEntityNamesResolver reflectionEntityNamesResolver = new ReflectionEntityNamesResolver(classLoader);
        if (searchMapping != null) {
            // If indexing is enabled then use the declared set of indexed classes for lookup but fallback to global classloader.
            QueryInterceptor queryInterceptor = cr.getComponent(QueryInterceptor.class);
            Map<String, Class<?>> indexedEntities = queryInterceptor.indexedEntities();
            return name -> {
                Class<?> c = indexedEntities.get(name);
                if (c == null) {
                    c = reflectionEntityNamesResolver.resolve(name);
                }
                return c;
            };
        }
        return reflectionEntityNamesResolver;
    }
}
Also used : ReflectionEntityNamesResolver(org.infinispan.objectfilter.impl.syntax.parser.ReflectionEntityNamesResolver) QueryInterceptor(org.infinispan.query.backend.QueryInterceptor) SearchMapping(org.infinispan.search.mapper.mapping.SearchMapping) APPLICATION_PROTOSTREAM(org.infinispan.commons.dataconversion.MediaType.APPLICATION_PROTOSTREAM) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ReflectionMatcher(org.infinispan.objectfilter.impl.ReflectionMatcher) ComponentRegistry(org.infinispan.factories.ComponentRegistry) EntityNameResolver(org.infinispan.objectfilter.impl.syntax.parser.EntityNameResolver) BasicComponentRegistry(org.infinispan.factories.impl.BasicComponentRegistry) MediaType(org.infinispan.commons.dataconversion.MediaType) AdvancedCache(org.infinispan.AdvancedCache) Matcher(org.infinispan.objectfilter.Matcher) APPLICATION_OBJECT(org.infinispan.commons.dataconversion.MediaType.APPLICATION_OBJECT) Map(java.util.Map) ReflectionEntityNamesResolver(org.infinispan.objectfilter.impl.syntax.parser.ReflectionEntityNamesResolver) ObjectReflectionMatcher(org.infinispan.query.dsl.embedded.impl.ObjectReflectionMatcher) SerializationContext(org.infinispan.protostream.SerializationContext) QueryInterceptor(org.infinispan.query.backend.QueryInterceptor)

Example 22 with MediaType

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

the class LifecycleManager method buildQueryManager.

private RemoteQueryManager buildQueryManager(Configuration cfg, SerializationContext ctx, ComponentRegistry cr) {
    ContentTypeConfiguration valueEncoding = cfg.encoding().valueDataType();
    MediaType valueStorageMediaType = valueEncoding.mediaType();
    AdvancedCache<?, ?> cache = cr.getComponent(Cache.class).getAdvancedCache();
    MediaType storageMediaType = cache.getValueDataConversion().getStorageMediaType();
    QuerySerializers querySerializers = buildQuerySerializers(cr, storageMediaType);
    boolean isObjectStorage = valueStorageMediaType != null && valueStorageMediaType.match(APPLICATION_OBJECT);
    if (isObjectStorage)
        return new ObjectRemoteQueryManager(cache, cr, querySerializers);
    return new ProtobufRemoteQueryManager(cache, cr, ctx, querySerializers);
}
Also used : MediaType(org.infinispan.commons.dataconversion.MediaType) ContentTypeConfiguration(org.infinispan.configuration.cache.ContentTypeConfiguration) Cache(org.infinispan.Cache) AdvancedCache(org.infinispan.AdvancedCache)

Example 23 with MediaType

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

the class CacheResourceV2 method getCacheConfig.

private CompletionStage<RestResponse> getCacheConfig(RestRequest request) {
    NettyRestResponse.Builder responseBuilder = new NettyRestResponse.Builder();
    String cacheName = request.variables().get("cacheName");
    MediaType accept = negotiateMediaType(request, APPLICATION_JSON, APPLICATION_XML, APPLICATION_YAML);
    responseBuilder.contentType(accept);
    if (!invocationHelper.getRestCacheManager().getInstance().getCacheConfigurationNames().contains(cacheName)) {
        responseBuilder.status(NOT_FOUND).build();
    }
    Cache<?, ?> cache = invocationHelper.getRestCacheManager().getCache(cacheName, request);
    if (cache == null)
        return notFoundResponseFuture();
    Configuration cacheConfiguration = SecurityActions.getCacheConfiguration(cache.getAdvancedCache());
    ByteArrayOutputStream entity = new ByteArrayOutputStream();
    try (ConfigurationWriter writer = ConfigurationWriter.to(entity).withType(accept).prettyPrint(false).build()) {
        parserRegistry.serialize(writer, cacheName, cacheConfiguration);
    } catch (Exception e) {
        return CompletableFuture.completedFuture(responseBuilder.status(INTERNAL_SERVER_ERROR).entity(Util.getRootCause(e)).build());
    }
    responseBuilder.entity(entity);
    return CompletableFuture.completedFuture(responseBuilder.status(OK).build());
}
Also used : ConfigurationWriter(org.infinispan.commons.configuration.io.ConfigurationWriter) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) RemoteStoreConfiguration(org.infinispan.persistence.remote.configuration.RemoteStoreConfiguration) Configuration(org.infinispan.configuration.cache.Configuration) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) MediaType(org.infinispan.commons.dataconversion.MediaType) MediaTypeUtils.negotiateMediaType(org.infinispan.rest.resources.MediaTypeUtils.negotiateMediaType) ByteArrayOutputStream(java.io.ByteArrayOutputStream) NettyRestResponse(org.infinispan.rest.NettyRestResponse) RestResponseException(org.infinispan.rest.RestResponseException)

Example 24 with MediaType

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

the class CacheResourceV2 method cacheListen.

private CompletionStage<RestResponse> cacheListen(RestRequest request) {
    MediaType accept = negotiateMediaType(request, APPLICATION_JSON, TEXT_PLAIN);
    String cacheName = request.variables().get("cacheName");
    boolean includeCurrentState = Boolean.parseBoolean(request.getParameter("includeCurrentState"));
    RestCacheManager<Object> restCacheManager = invocationHelper.getRestCacheManager();
    if (!restCacheManager.cacheExists(cacheName))
        return notFoundResponseFuture();
    Cache<?, ?> cache = restCacheManager.getCache(cacheName, accept, accept, request);
    BaseCacheListener listener = includeCurrentState ? new StatefulCacheListener(cache) : new StatelessCacheListener(cache);
    NettyRestResponse.Builder responseBuilder = new NettyRestResponse.Builder();
    responseBuilder.contentType(TEXT_EVENT_STREAM).entity(listener.getEventStream());
    return cache.addListenerAsync(listener).thenApply(v -> responseBuilder.build());
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) MediaType(org.infinispan.commons.dataconversion.MediaType) MediaTypeUtils.negotiateMediaType(org.infinispan.rest.resources.MediaTypeUtils.negotiateMediaType) NettyRestResponse(org.infinispan.rest.NettyRestResponse)

Example 25 with MediaType

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

the class ContainerResource method listenConfig.

private CompletionStage<RestResponse> listenConfig(RestRequest request) {
    MediaType mediaType = negotiateMediaType(request, APPLICATION_YAML, APPLICATION_JSON, APPLICATION_XML);
    boolean includeCurrentState = Boolean.parseBoolean(request.getParameter("includeCurrentState"));
    EmbeddedCacheManager cacheManager = invocationHelper.getRestCacheManager().getInstance();
    NettyRestResponse.Builder responseBuilder = new NettyRestResponse.Builder();
    ConfigurationListener listener = new ConfigurationListener(cacheManager, mediaType, includeCurrentState);
    responseBuilder.contentType(TEXT_EVENT_STREAM).entity(listener.getEventStream());
    return cacheManager.addListenerAsync(listener).thenApply(v -> responseBuilder.build());
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) MediaType(org.infinispan.commons.dataconversion.MediaType) MediaTypeUtils.negotiateMediaType(org.infinispan.rest.resources.MediaTypeUtils.negotiateMediaType) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) NettyRestResponse(org.infinispan.rest.NettyRestResponse)

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