Search in sources :

Example 1 with SerializationContextRegistry

use of org.infinispan.marshall.protostream.impl.SerializationContextRegistry in project infinispan by infinispan.

the class ServiceLoadSerializationContextInitializerTest method testSCILoaded.

public void testSCILoaded() throws Exception {
    try (EmbeddedCacheManager cm = TestCacheManagerFactory.createCacheManager(true)) {
        SerializationContextRegistry registry = TestingUtil.extractGlobalComponent(cm, SerializationContextRegistry.class);
        assertTrue(registry.getUserCtx().canMarshall(ServiceLoadedClass.class));
        assertFalse(registry.getGlobalCtx().canMarshall(ServiceLoadedClass.class));
        assertFalse(registry.getPersistenceCtx().canMarshall(ServiceLoadedClass.class));
    }
}
Also used : SerializationContextRegistry(org.infinispan.marshall.protostream.impl.SerializationContextRegistry) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager)

Example 2 with SerializationContextRegistry

use of org.infinispan.marshall.protostream.impl.SerializationContextRegistry in project infinispan by infinispan.

the class CounterModuleLifecycle method cacheManagerStarting.

@Override
public void cacheManagerStarting(GlobalComponentRegistry gcr, GlobalConfiguration globalConfiguration) {
    final Map<Integer, AdvancedExternalizer<?>> externalizerMap = globalConfiguration.serialization().advancedExternalizers();
    // Only required by GlobalMarshaller
    addAdvancedExternalizer(externalizerMap, ResetFunction.EXTERNALIZER);
    addAdvancedExternalizer(externalizerMap, ReadFunction.EXTERNALIZER);
    addAdvancedExternalizer(externalizerMap, InitializeCounterFunction.EXTERNALIZER);
    addAdvancedExternalizer(externalizerMap, AddFunction.EXTERNALIZER);
    addAdvancedExternalizer(externalizerMap, CompareAndSwapFunction.EXTERNALIZER);
    addAdvancedExternalizer(externalizerMap, CreateAndCASFunction.EXTERNALIZER);
    addAdvancedExternalizer(externalizerMap, CreateAndAddFunction.EXTERNALIZER);
    addAdvancedExternalizer(externalizerMap, RemoveFunction.EXTERNALIZER);
    BasicComponentRegistry bcr = gcr.getComponent(BasicComponentRegistry.class);
    EmbeddedCacheManager cacheManager = bcr.getComponent(EmbeddedCacheManager.class).wired();
    InternalCacheRegistry internalCacheRegistry = bcr.getComponent(InternalCacheRegistry.class).running();
    SerializationContextRegistry ctxRegistry = gcr.getComponent(SerializationContextRegistry.class);
    ctxRegistry.addContextInitializer(SerializationContextRegistry.MarshallerType.PERSISTENCE, new PersistenceContextInitializerImpl());
    CounterManagerConfiguration counterManagerConfiguration = extractConfiguration(globalConfiguration);
    if (gcr.getGlobalConfiguration().isClustered()) {
        // only attempts to create the caches if the cache manager is clustered.
        registerCounterCache(internalCacheRegistry, counterManagerConfiguration);
    } else {
        // local only cache manager.
        registerLocalCounterCache(internalCacheRegistry);
    }
    registerCounterNotificationManager(bcr);
    registerCounterManager(cacheManager, bcr, globalConfiguration);
}
Also used : BasicComponentRegistry(org.infinispan.factories.impl.BasicComponentRegistry) SerializationContextRegistry(org.infinispan.marshall.protostream.impl.SerializationContextRegistry) PersistenceContextInitializerImpl(org.infinispan.counter.impl.persistence.PersistenceContextInitializerImpl) InternalCacheRegistry(org.infinispan.registry.InternalCacheRegistry) AdvancedExternalizer(org.infinispan.commons.marshall.AdvancedExternalizer) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) CounterManagerConfiguration(org.infinispan.counter.configuration.CounterManagerConfiguration)

Example 3 with SerializationContextRegistry

use of org.infinispan.marshall.protostream.impl.SerializationContextRegistry in project infinispan by infinispan.

the class LifecycleCallbacks method cacheManagerStarting.

@Override
public void cacheManagerStarting(GlobalComponentRegistry gcr, GlobalConfiguration globalConfiguration) {
    SerializationContextRegistry ctxRegistry = gcr.getComponent(SerializationContextRegistry.class);
    PersistenceContextInitializerImpl sci = new PersistenceContextInitializerImpl();
    ctxRegistry.addContextInitializer(SerializationContextRegistry.MarshallerType.PERSISTENCE, sci);
    ctxRegistry.addContextInitializer(SerializationContextRegistry.MarshallerType.GLOBAL, sci);
    Map<Integer, AdvancedExternalizer<?>> map = globalConfiguration.serialization().advancedExternalizers();
    add(map, new SuppliedExternalizer<>(ExternalizerIds.READ_WITH_EXPIRY, ReadWithExpiry.class, ReadWithExpiry::new));
    add(map, new SuppliedExternalizer<>(ExternalizerIds.GET_AND_PUT, GetAndPut.class, GetAndPut::new));
    add(map, new SuppliedExternalizer<>(ExternalizerIds.GET_AND_REPLACE, GetAndReplace.class, GetAndReplace::new));
    add(map, new Invoke.Externalizer());
    add(map, new SuppliedExternalizer<>(ExternalizerIds.PUT, Put.class, Put::new));
    add(map, new SuppliedExternalizer<>(ExternalizerIds.PUT_IF_ABSENT, PutIfAbsent.class, PutIfAbsent::new));
    add(map, new SingletonExternalizer<>(ExternalizerIds.REMOVE, Remove.getInstance()));
    add(map, new SuppliedExternalizer<>(ExternalizerIds.REMOVE_CONDITIONALLY, RemoveConditionally.class, RemoveConditionally::new));
    add(map, new SuppliedExternalizer<>(ExternalizerIds.REPLACE, Replace.class, Replace::new));
    add(map, new SingletonExternalizer<>(ExternalizerIds.GET_AND_REMOVE, GetAndRemove.getInstance()));
    add(map, new ReplaceConditionally.Externalizer());
    // that cannot be classloaded.
    if (canLoad("javax.cache.processor.MutableEntry", MutableEntrySnapshot.Externalizer.class.getClassLoader())) {
        add(map, new MutableEntrySnapshot.Externalizer());
    }
    gcr.getCacheManager().getClassAllowList().addClasses(DefaultCacheKey.class);
}
Also used : ReplaceConditionally(org.infinispan.jcache.embedded.functions.ReplaceConditionally) Replace(org.infinispan.jcache.embedded.functions.Replace) GetAndReplace(org.infinispan.jcache.embedded.functions.GetAndReplace) GetAndPut(org.infinispan.jcache.embedded.functions.GetAndPut) RemoveConditionally(org.infinispan.jcache.embedded.functions.RemoveConditionally) MutableEntrySnapshot(org.infinispan.jcache.embedded.functions.MutableEntrySnapshot) PutIfAbsent(org.infinispan.jcache.embedded.functions.PutIfAbsent) ReadWithExpiry(org.infinispan.jcache.embedded.functions.ReadWithExpiry) Put(org.infinispan.jcache.embedded.functions.Put) GetAndPut(org.infinispan.jcache.embedded.functions.GetAndPut) Invoke(org.infinispan.jcache.embedded.functions.Invoke) SingletonExternalizer(org.infinispan.commons.marshall.SingletonExternalizer) AdvancedExternalizer(org.infinispan.commons.marshall.AdvancedExternalizer) SuppliedExternalizer(org.infinispan.commons.marshall.SuppliedExternalizer) SerializationContextRegistry(org.infinispan.marshall.protostream.impl.SerializationContextRegistry) GetAndReplace(org.infinispan.jcache.embedded.functions.GetAndReplace) AdvancedExternalizer(org.infinispan.commons.marshall.AdvancedExternalizer)

Example 4 with SerializationContextRegistry

use of org.infinispan.marshall.protostream.impl.SerializationContextRegistry in project infinispan by infinispan.

the class LifecycleCallbacks method cacheManagerStarting.

@Override
public void cacheManagerStarting(GlobalComponentRegistry gcr, GlobalConfiguration globalConfiguration) {
    SerializationContextRegistry ctxRegistry = gcr.getComponent(SerializationContextRegistry.class);
    PersistenceContextInitializerImpl sci = new PersistenceContextInitializerImpl();
    ctxRegistry.addContextInitializer(SerializationContextRegistry.MarshallerType.PERSISTENCE, sci);
    ctxRegistry.addContextInitializer(SerializationContextRegistry.MarshallerType.GLOBAL, sci);
}
Also used : SerializationContextRegistry(org.infinispan.marshall.protostream.impl.SerializationContextRegistry)

Example 5 with SerializationContextRegistry

use of org.infinispan.marshall.protostream.impl.SerializationContextRegistry in project infinispan by infinispan.

the class ProtobufMetadataCachePreserveStateAcrossRestartsTest method verifySchemas.

private void verifySchemas(CacheContainer manager) {
    assertFiles(manager, "A.proto", "B.proto", "C.proto", "D.proto", "E.proto", "F.proto");
    assertFilesWithErrors(manager, "E.proto", "F.proto");
    SerializationContextRegistry scr = extractGlobalComponent(manager, SerializationContextRegistry.class);
    ImmutableSerializationContext serializationContext = scr.getUserCtx();
    Descriptor mDescriptor = serializationContext.getMessageDescriptor("D.M");
    assertNotNull(mDescriptor);
    List<String> fields = mDescriptor.getFields().stream().map(AnnotatedDescriptorImpl::getName).collect(Collectors.toList());
    assertEquals(singletonList("s"), fields);
}
Also used : SerializationContextRegistry(org.infinispan.marshall.protostream.impl.SerializationContextRegistry) ImmutableSerializationContext(org.infinispan.protostream.ImmutableSerializationContext) Descriptor(org.infinispan.protostream.descriptors.Descriptor)

Aggregations

SerializationContextRegistry (org.infinispan.marshall.protostream.impl.SerializationContextRegistry)15 AdvancedExternalizer (org.infinispan.commons.marshall.AdvancedExternalizer)6 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)5 BasicComponentRegistry (org.infinispan.factories.impl.BasicComponentRegistry)3 InternalCacheRegistry (org.infinispan.registry.InternalCacheRegistry)3 ClassAllowList (org.infinispan.commons.configuration.ClassAllowList)2 ProtostreamTranscoder (org.infinispan.encoding.ProtostreamTranscoder)2 BeforeClass (org.testng.annotations.BeforeClass)2 Transcoder (org.infinispan.commons.dataconversion.Transcoder)1 JavaSerializationMarshaller (org.infinispan.commons.marshall.JavaSerializationMarshaller)1 SingletonExternalizer (org.infinispan.commons.marshall.SingletonExternalizer)1 SuppliedExternalizer (org.infinispan.commons.marshall.SuppliedExternalizer)1 CounterManagerConfiguration (org.infinispan.counter.configuration.CounterManagerConfiguration)1 PersistenceContextInitializerImpl (org.infinispan.counter.impl.persistence.PersistenceContextInitializerImpl)1 TwoStepTranscoder (org.infinispan.encoding.impl.TwoStepTranscoder)1 GetAndPut (org.infinispan.jcache.embedded.functions.GetAndPut)1 GetAndReplace (org.infinispan.jcache.embedded.functions.GetAndReplace)1 Invoke (org.infinispan.jcache.embedded.functions.Invoke)1 MutableEntrySnapshot (org.infinispan.jcache.embedded.functions.MutableEntrySnapshot)1 Put (org.infinispan.jcache.embedded.functions.Put)1