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));
}
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);
}
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);
}
}
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);
}
}
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");
}
Aggregations