Search in sources :

Example 1 with TranscoderMarshallerAdapter

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

the class EndpointsCacheFactory method createEmbeddedCache.

private void createEmbeddedCache() {
    GlobalConfigurationBuilder globalBuilder;
    if (cacheMode.isClustered()) {
        globalBuilder = new GlobalConfigurationBuilder();
        globalBuilder.transport().defaultTransport();
    } else {
        globalBuilder = new GlobalConfigurationBuilder().nonClusteredDefault();
    }
    globalBuilder.addModule(PrivateGlobalConfigurationBuilder.class).serverMode(true);
    globalBuilder.defaultCacheName(cacheName);
    if (contextInitializer != null)
        globalBuilder.serialization().addContextInitializer(contextInitializer);
    org.infinispan.configuration.cache.ConfigurationBuilder builder = new org.infinispan.configuration.cache.ConfigurationBuilder();
    builder.clustering().cacheMode(cacheMode).encoding().key().mediaType(MediaType.APPLICATION_OBJECT_TYPE).encoding().value().mediaType(MediaType.APPLICATION_OBJECT_TYPE);
    if (cacheMode.isDistributed() && numOwners != DEFAULT_NUM_OWNERS) {
        builder.clustering().hash().numOwners(numOwners);
    }
    if (cacheMode.isDistributed() && l1Enable) {
        builder.clustering().l1().enable();
    }
    cacheManager = cacheMode.isClustered() ? TestCacheManagerFactory.createClusteredCacheManager(globalBuilder, builder) : TestCacheManagerFactory.createCacheManager(globalBuilder, builder);
    embeddedCache = cacheManager.getCache(cacheName);
    EncoderRegistry encoderRegistry = embeddedCache.getAdvancedCache().getComponentRegistry().getGlobalComponentRegistry().getComponent(EncoderRegistry.class);
    if (marshaller != null) {
        boolean isConversionSupported = encoderRegistry.isConversionSupported(marshaller.mediaType(), APPLICATION_OBJECT);
        if (!isConversionSupported) {
            encoderRegistry.registerTranscoder(new TranscoderMarshallerAdapter(marshaller));
        }
    }
}
Also used : PrivateGlobalConfigurationBuilder(org.infinispan.configuration.internal.PrivateGlobalConfigurationBuilder) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) PrivateGlobalConfigurationBuilder(org.infinispan.configuration.internal.PrivateGlobalConfigurationBuilder) RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) ConfigurationBuilder(org.infinispan.client.hotrod.configuration.ConfigurationBuilder) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) RestServerConfigurationBuilder(org.infinispan.rest.configuration.RestServerConfigurationBuilder) PrivateGlobalConfigurationBuilder(org.infinispan.configuration.internal.PrivateGlobalConfigurationBuilder) TranscoderMarshallerAdapter(org.infinispan.commons.dataconversion.TranscoderMarshallerAdapter) EncoderRegistry(org.infinispan.marshall.core.EncoderRegistry)

Example 2 with TranscoderMarshallerAdapter

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

the class EncoderRegistryFactory method construct.

@Override
public Object construct(String componentName) {
    ClassLoader classLoader = globalConfiguration.classLoader();
    EncoderRegistryImpl encoderRegistry = new EncoderRegistryImpl();
    ClassAllowList classAllowList = embeddedCacheManager.getClassAllowList();
    encoderRegistry.registerEncoder(IdentityEncoder.INSTANCE);
    encoderRegistry.registerEncoder(UTF8Encoder.INSTANCE);
    encoderRegistry.registerEncoder(new JavaSerializationEncoder(classAllowList));
    encoderRegistry.registerEncoder(new GlobalMarshallerEncoder(globalMarshaller.wired()));
    // Default and binary transcoder use the user marshaller to convert data to/from a byte array
    encoderRegistry.registerTranscoder(new DefaultTranscoder(userMarshaller));
    encoderRegistry.registerTranscoder(new BinaryTranscoder(userMarshaller));
    // Core transcoders are always available
    encoderRegistry.registerTranscoder(new ProtostreamTranscoder(ctxRegistry, classLoader));
    encoderRegistry.registerTranscoder(new JavaSerializationTranscoder(classAllowList));
    // Wraps the GlobalMarshaller so that it can be used as a transcoder
    // Keeps application/x-infinispan-marshalling available for backwards compatibility
    encoderRegistry.registerTranscoder(new TranscoderMarshallerAdapter(globalMarshaller.wired()));
    // Make the user marshaller's media type available as well
    // As custom marshaller modules like Kryo and Protostuff do not define their own transcoder
    encoderRegistry.registerTranscoder(new TranscoderMarshallerAdapter(userMarshaller));
    encoderRegistry.registerWrapper(ByteArrayWrapper.INSTANCE);
    encoderRegistry.registerWrapper(IdentityWrapper.INSTANCE);
    return encoderRegistry;
}
Also used : EncoderRegistryImpl(org.infinispan.marshall.core.EncoderRegistryImpl) DefaultTranscoder(org.infinispan.commons.dataconversion.DefaultTranscoder) TranscoderMarshallerAdapter(org.infinispan.commons.dataconversion.TranscoderMarshallerAdapter) ClassAllowList(org.infinispan.commons.configuration.ClassAllowList) BinaryTranscoder(org.infinispan.commons.dataconversion.BinaryTranscoder) JavaSerializationTranscoder(org.infinispan.encoding.impl.JavaSerializationTranscoder) ProtostreamTranscoder(org.infinispan.encoding.ProtostreamTranscoder) GlobalMarshallerEncoder(org.infinispan.commons.dataconversion.GlobalMarshallerEncoder) JavaSerializationEncoder(org.infinispan.commons.dataconversion.JavaSerializationEncoder)

Aggregations

TranscoderMarshallerAdapter (org.infinispan.commons.dataconversion.TranscoderMarshallerAdapter)2 ConfigurationBuilder (org.infinispan.client.hotrod.configuration.ConfigurationBuilder)1 RestClientConfigurationBuilder (org.infinispan.client.rest.configuration.RestClientConfigurationBuilder)1 ClassAllowList (org.infinispan.commons.configuration.ClassAllowList)1 BinaryTranscoder (org.infinispan.commons.dataconversion.BinaryTranscoder)1 DefaultTranscoder (org.infinispan.commons.dataconversion.DefaultTranscoder)1 GlobalMarshallerEncoder (org.infinispan.commons.dataconversion.GlobalMarshallerEncoder)1 JavaSerializationEncoder (org.infinispan.commons.dataconversion.JavaSerializationEncoder)1 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)1 PrivateGlobalConfigurationBuilder (org.infinispan.configuration.internal.PrivateGlobalConfigurationBuilder)1 ProtostreamTranscoder (org.infinispan.encoding.ProtostreamTranscoder)1 JavaSerializationTranscoder (org.infinispan.encoding.impl.JavaSerializationTranscoder)1 EncoderRegistry (org.infinispan.marshall.core.EncoderRegistry)1 EncoderRegistryImpl (org.infinispan.marshall.core.EncoderRegistryImpl)1 RestServerConfigurationBuilder (org.infinispan.rest.configuration.RestServerConfigurationBuilder)1