Search in sources :

Example 1 with CommonTypesSchema

use of org.infinispan.protostream.types.java.CommonTypesSchema in project infinispan by infinispan.

the class SerializationContextRegistryImpl method start.

@Start
public void start() {
    user.addContextInitializer(new CommonTypesSchema());
    user.addContextInitializer(new CommonContainerTypesSchema());
    user.addContextInitializer(new UserContextInitializerImpl());
    // Add user configured SCIs
    Collection<SerializationContextInitializer> initializers = globalConfig.serialization().contextInitializers();
    if (initializers == null || initializers.isEmpty()) {
        // If no SCIs have been explicitly configured, then load all available SCI services
        initializers = ServiceFinder.load(SerializationContextInitializer.class, globalConfig.classLoader());
    }
    initializers.forEach(user::addContextInitializer);
    String messageName = PersistenceContextInitializer.getFqTypeName(MarshallableUserObject.class);
    BaseMarshaller userObjectMarshaller = new MarshallableUserObject.Marshaller(messageName, userMarshaller.wired());
    update(GLOBAL, ctx -> ctx.addContextInitializer(new PersistenceContextInitializerImpl()).addContextInitializer(new org.infinispan.commons.GlobalContextInitializerImpl()).addMarshaller(userObjectMarshaller));
    update(PERSISTENCE, ctx -> ctx.addContextInitializer(new PersistenceContextInitializerImpl()).addMarshaller(userObjectMarshaller));
}
Also used : CommonTypesSchema(org.infinispan.protostream.types.java.CommonTypesSchema) BaseMarshaller(org.infinispan.protostream.BaseMarshaller) Marshaller(org.infinispan.commons.marshall.Marshaller) UserContextInitializerImpl(org.infinispan.commons.marshall.UserContextInitializerImpl) SerializationContextInitializer(org.infinispan.protostream.SerializationContextInitializer) CommonContainerTypesSchema(org.infinispan.protostream.types.java.CommonContainerTypesSchema) PersistenceContextInitializerImpl(org.infinispan.marshall.persistence.impl.PersistenceContextInitializerImpl) BaseMarshaller(org.infinispan.protostream.BaseMarshaller) Start(org.infinispan.factories.annotations.Start)

Example 2 with CommonTypesSchema

use of org.infinispan.protostream.types.java.CommonTypesSchema in project infinispan by infinispan.

the class ProtoStreamBackwardsCompatibilityTest method testOldEventLoggerUUIDBytesAreReadable.

public void testOldEventLoggerUUIDBytesAreReadable() throws IOException {
    // Initialize SerializationContext like it used to be in the server
    SerializationContext oldServerCtx = ProtobufUtil.newSerializationContext();
    PersistenceContextManualInitializer serverInitializer = new PersistenceContextManualInitializer();
    serverInitializer.registerSchema(oldServerCtx);
    serverInitializer.registerMarshallers(oldServerCtx);
    // Initialise SerializationContext using the new core initializer
    SerializationContext coreCtx = ProtobufUtil.newSerializationContext();
    CommonTypesSchema sci = new CommonTypesSchema();
    sci.registerSchema(coreCtx);
    sci.registerMarshallers(coreCtx);
    UUID uuid = Util.threadLocalRandomUUID();
    byte[] oldBytes = ProtobufUtil.toWrappedByteArray(oldServerCtx, uuid);
    UUID unmarshalled = ProtobufUtil.fromWrappedByteArray(coreCtx, oldBytes);
    assertEquals(uuid, unmarshalled);
    byte[] newBytes = ProtobufUtil.toWrappedByteArray(coreCtx, uuid);
    unmarshalled = ProtobufUtil.fromWrappedByteArray(coreCtx, newBytes);
    assertEquals(uuid, unmarshalled);
}
Also used : SerializationContext(org.infinispan.protostream.SerializationContext) CommonTypesSchema(org.infinispan.protostream.types.java.CommonTypesSchema) UUID(java.util.UUID)

Aggregations

CommonTypesSchema (org.infinispan.protostream.types.java.CommonTypesSchema)2 UUID (java.util.UUID)1 Marshaller (org.infinispan.commons.marshall.Marshaller)1 UserContextInitializerImpl (org.infinispan.commons.marshall.UserContextInitializerImpl)1 Start (org.infinispan.factories.annotations.Start)1 PersistenceContextInitializerImpl (org.infinispan.marshall.persistence.impl.PersistenceContextInitializerImpl)1 BaseMarshaller (org.infinispan.protostream.BaseMarshaller)1 SerializationContext (org.infinispan.protostream.SerializationContext)1 SerializationContextInitializer (org.infinispan.protostream.SerializationContextInitializer)1 CommonContainerTypesSchema (org.infinispan.protostream.types.java.CommonContainerTypesSchema)1