Search in sources :

Example 1 with BaseMarshaller

use of org.infinispan.protostream.BaseMarshaller 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 BaseMarshaller

use of org.infinispan.protostream.BaseMarshaller in project infinispan by infinispan.

the class SpringEmbeddedModule method addSessionContextInitializerAndMarshaller.

private void addSessionContextInitializerAndMarshaller(SerializationContextRegistry ctxRegistry, JavaSerializationMarshaller serializationMarshaller) {
    // Skip registering the marshallers if the MapSession class is not available
    try {
        new MapSession();
    } catch (NoClassDefFoundError e) {
        Log.CONFIG.debug("spring-session classes not found, skipping the session context initializer registration");
        return;
    }
    org.infinispan.spring.common.session.PersistenceContextInitializerImpl sessionSci = new org.infinispan.spring.common.session.PersistenceContextInitializerImpl();
    ctxRegistry.addContextInitializer(SerializationContextRegistry.MarshallerType.PERSISTENCE, sessionSci);
    ctxRegistry.addContextInitializer(SerializationContextRegistry.MarshallerType.GLOBAL, sessionSci);
    BaseMarshaller sessionAttributeMarshaller = new MapSessionProtoAdapter.SessionAttributeRawMarshaller(serializationMarshaller);
    ctxRegistry.addMarshaller(PERSISTENCE, sessionAttributeMarshaller);
    ctxRegistry.addMarshaller(GLOBAL, sessionAttributeMarshaller);
}
Also used : BaseMarshaller(org.infinispan.protostream.BaseMarshaller) MapSession(org.springframework.session.MapSession)

Example 3 with BaseMarshaller

use of org.infinispan.protostream.BaseMarshaller in project protostream by infinispan.

the class ProtoSchemaBuilder method main.

public static void main(String[] args) throws Exception {
    CommandLine cmd = parseCommandLine(args);
    if (cmd == null) {
        return;
    }
    String packageName = cmd.getOptionValue(PACKAGE_LONG_OPT);
    Configuration config = Configuration.builder().build();
    SerializationContext ctx = ProtobufUtil.newSerializationContext(config);
    Properties schemas = cmd.getOptionProperties(SCHEMA_LONG_OPT);
    if (schemas != null) {
        for (String schema : schemas.stringPropertyNames()) {
            String file = schemas.getProperty(schema);
            try (FileInputStream in = new FileInputStream(file)) {
                ctx.registerProtoFiles(new FileDescriptorSource().addProtoFile(schema, in));
            }
        }
    }
    String[] marshallers = cmd.getOptionValues(MARSHALLER_LONG_OPT);
    if (marshallers != null) {
        for (String marshallerClass : marshallers) {
            BaseMarshaller<?> bm = (BaseMarshaller<?>) Class.forName(marshallerClass).newInstance();
            ctx.registerMarshaller(bm);
        }
    }
    File file = cmd.hasOption(FILE_LONG_OPT) ? new File(cmd.getOptionValue(FILE_LONG_OPT)) : null;
    String fileName = file == null ? DEFAULT_GENERATED_SCHEMA_NAME : file.getName();
    ProtoSchemaBuilder protoSchemaBuilder = new ProtoSchemaBuilder().fileName(fileName).packageName(packageName);
    for (String className : cmd.getArgs()) {
        protoSchemaBuilder.addClass(Class.forName(className));
    }
    String schemaFile = protoSchemaBuilder.build(ctx);
    if (file != null) {
        try (PrintStream out = new PrintStream(new FileOutputStream(file))) {
            out.print(schemaFile);
            out.flush();
        }
    } else {
        System.out.print(schemaFile);
    }
}
Also used : SerializationContext(org.infinispan.protostream.SerializationContext) PrintStream(java.io.PrintStream) Configuration(org.infinispan.protostream.config.Configuration) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream) CommandLine(org.apache.commons.cli.CommandLine) FileOutputStream(java.io.FileOutputStream) BaseMarshaller(org.infinispan.protostream.BaseMarshaller) FileDescriptorSource(org.infinispan.protostream.FileDescriptorSource) File(java.io.File)

Example 4 with BaseMarshaller

use of org.infinispan.protostream.BaseMarshaller in project protostream by infinispan.

the class MarshallerByteCodeGenerator method generateMarshaller.

@Override
public void generateMarshaller(SerializationContext serializationContext, ProtoTypeMetadata ptm) throws Exception {
    Class<? extends BaseMarshaller> marshallerClass = null;
    if (ptm instanceof ProtoMessageTypeMetadata) {
        marshallerClass = generateMessageMarshaller((ProtoMessageTypeMetadata) ptm);
    } else if (ptm instanceof ProtoEnumTypeMetadata) {
        marshallerClass = generateEnumMarshaller((ProtoEnumTypeMetadata) ptm);
    }
    if (marshallerClass != null) {
        BaseMarshaller marshaller = marshallerClass.newInstance();
        serializationContext.registerMarshaller(marshaller);
    }
}
Also used : BaseMarshaller(org.infinispan.protostream.BaseMarshaller)

Example 5 with BaseMarshaller

use of org.infinispan.protostream.BaseMarshaller in project indy by Commonjava.

the class KojiCacheProducer method versionMetadataCache.

@KojiMavenVersionMetadataCache
@Produces
@ApplicationScoped
public BasicCacheHandle<ProjectRef, Metadata> versionMetadataCache() {
    if (remoteConfiguration.isEnabled()) {
        List<BaseMarshaller> marshallers = new ArrayList<>();
        marshallers.add(new MetadataMarshaller());
        marshallers.add(new ProjectRefMarshaller());
        cacheProducer.registerProtoAndMarshallers("koji_metadata.proto", marshallers);
    }
    return cacheProducer.getBasicCache("koji-maven-version-metadata");
}
Also used : MetadataMarshaller(org.commonjava.indy.pkg.maven.content.marshaller.MetadataMarshaller) BaseMarshaller(org.infinispan.protostream.BaseMarshaller) ArrayList(java.util.ArrayList) Produces(javax.enterprise.inject.Produces) ApplicationScoped(javax.enterprise.context.ApplicationScoped)

Aggregations

BaseMarshaller (org.infinispan.protostream.BaseMarshaller)11 SerializationContext (org.infinispan.protostream.SerializationContext)4 ArrayList (java.util.ArrayList)3 ApplicationScoped (javax.enterprise.context.ApplicationScoped)3 Produces (javax.enterprise.inject.Produces)3 FileDescriptorSource (org.infinispan.protostream.FileDescriptorSource)3 IOException (java.io.IOException)2 MetadataKeyMarshaller (org.commonjava.indy.pkg.maven.content.marshaller.MetadataKeyMarshaller)2 MetadataMarshaller (org.commonjava.indy.pkg.maven.content.marshaller.MetadataMarshaller)2 StoreKeyMarshaller (org.commonjava.indy.pkg.maven.content.marshaller.StoreKeyMarshaller)2 StoreTypeMarshaller (org.commonjava.indy.pkg.maven.content.marshaller.StoreTypeMarshaller)2 SerializationContextInitializer (org.infinispan.protostream.SerializationContextInitializer)2 MapSession (org.springframework.session.MapSession)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 PrintStream (java.io.PrintStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Map (java.util.Map)1 Properties (java.util.Properties)1