Search in sources :

Example 6 with BaseMarshaller

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

the class MetadataCacheProducer method mavenMetadataCacheCfg.

@MavenMetadataCache
@Produces
@ApplicationScoped
public BasicCacheHandle<MetadataKey, MetadataInfo> mavenMetadataCacheCfg() {
    if (remoteConfiguration.isEnabled()) {
        List<BaseMarshaller> infoMarshallers = new ArrayList<>();
        infoMarshallers.add(new MetadataInfoMarshaller());
        infoMarshallers.add(new MetadataMarshaller());
        infoMarshallers.add(new VersioningMarshaller());
        infoMarshallers.add(new SnapshotMarshaller());
        infoMarshallers.add(new SnapshotVersionMarshaller());
        infoMarshallers.add(new VersioningMarshaller());
        cacheProducer.registerProtoAndMarshallers("metadata_info.proto", infoMarshallers);
        List<BaseMarshaller> keyMarshallers = new ArrayList<>();
        keyMarshallers.add(new MetadataKeyMarshaller());
        keyMarshallers.add(new StoreKeyMarshaller());
        keyMarshallers.add(new StoreTypeMarshaller());
        cacheProducer.registerProtoAndMarshallers("metadata_key.proto", keyMarshallers);
    }
    return cacheProducer.getBasicCache(METADATA_CACHE);
}
Also used : MetadataMarshaller(org.commonjava.indy.pkg.maven.content.marshaller.MetadataMarshaller) StoreTypeMarshaller(org.commonjava.indy.pkg.maven.content.marshaller.StoreTypeMarshaller) SnapshotMarshaller(org.commonjava.indy.pkg.maven.content.marshaller.SnapshotMarshaller) BaseMarshaller(org.infinispan.protostream.BaseMarshaller) ArrayList(java.util.ArrayList) SnapshotVersionMarshaller(org.commonjava.indy.pkg.maven.content.marshaller.SnapshotVersionMarshaller) MetadataInfoMarshaller(org.commonjava.indy.pkg.maven.content.marshaller.MetadataInfoMarshaller) VersioningMarshaller(org.commonjava.indy.pkg.maven.content.marshaller.VersioningMarshaller) MetadataKeyMarshaller(org.commonjava.indy.pkg.maven.content.marshaller.MetadataKeyMarshaller) StoreKeyMarshaller(org.commonjava.indy.pkg.maven.content.marshaller.StoreKeyMarshaller) Produces(javax.enterprise.inject.Produces) ApplicationScoped(javax.enterprise.context.ApplicationScoped)

Example 7 with BaseMarshaller

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

the class MetadataCacheProducer method mavenMetadataKeyCacheCfg.

@MavenMetadataKeyCache
@Produces
@ApplicationScoped
public BasicCacheHandle<MetadataKey, MetadataKey> mavenMetadataKeyCacheCfg() {
    if (remoteConfiguration.isEnabled()) {
        List<BaseMarshaller> keyMarshallers = new ArrayList<>();
        keyMarshallers.add(new MetadataKeyMarshaller());
        keyMarshallers.add(new StoreKeyMarshaller());
        keyMarshallers.add(new StoreTypeMarshaller());
        cacheProducer.registerProtoAndMarshallers("metadata_key.proto", keyMarshallers);
    }
    BasicCacheHandle<MetadataKey, MetadataKey> handler = cacheProducer.getBasicCache(METADATA_KEY_CACHE);
    registerTransformer(handler);
    return handler;
}
Also used : StoreTypeMarshaller(org.commonjava.indy.pkg.maven.content.marshaller.StoreTypeMarshaller) BaseMarshaller(org.infinispan.protostream.BaseMarshaller) ArrayList(java.util.ArrayList) MetadataKey(org.commonjava.indy.pkg.maven.content.MetadataKey) MetadataKeyMarshaller(org.commonjava.indy.pkg.maven.content.marshaller.MetadataKeyMarshaller) StoreKeyMarshaller(org.commonjava.indy.pkg.maven.content.marshaller.StoreKeyMarshaller) Produces(javax.enterprise.inject.Produces) ApplicationScoped(javax.enterprise.context.ApplicationScoped)

Example 8 with BaseMarshaller

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

the class CacheProducer method registerProtoAndMarshallers.

public synchronized void registerProtoAndMarshallers(String protofile, List<BaseMarshaller> marshallers) {
    SerializationContext ctx = ProtoStreamMarshaller.getSerializationContext(remoteCacheManager);
    try {
        ctx.registerProtoFiles(FileDescriptorSource.fromResources(protofile));
    } catch (IOException e) {
        throw new RuntimeException("Register proto files error, protofile: " + protofile, e);
    }
    for (BaseMarshaller marshaller : marshallers) {
        try {
            ctx.registerMarshaller(marshaller);
        } catch (Exception e) {
            throw new RuntimeException("Register the marshallers error.", e);
        }
    }
    // Retrieve metadata cache and register the new schema on the infinispan server too
    RemoteCache<String, String> metadataCache = remoteCacheManager.getCache(PROTOBUF_METADATA_CACHE_NAME);
    metadataCache.put(protofile, FileDescriptorSource.getResourceAsString(getClass(), "/" + protofile));
}
Also used : SerializationContext(org.infinispan.protostream.SerializationContext) BaseMarshaller(org.infinispan.protostream.BaseMarshaller) IOException(java.io.IOException) IndyLifecycleException(org.commonjava.indy.action.IndyLifecycleException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) InterpolationException(org.codehaus.plexus.interpolation.InterpolationException)

Example 9 with BaseMarshaller

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

the class InfinispanClientProducer method handleProtoStreamMarshaller.

private static void handleProtoStreamMarshaller(ProtoStreamMarshaller marshaller, Properties properties, BeanManager beanManager) {
    SerializationContext serializationContext = marshaller.getSerializationContext();
    Set<SerializationContextInitializer> initializers = (Set) properties.get(InfinispanClientProducer.PROTOBUF_INITIALIZERS);
    if (initializers != null) {
        for (SerializationContextInitializer initializer : initializers) {
            initializer.registerSchema(serializationContext);
            initializer.registerMarshallers(serializationContext);
        }
    }
    FileDescriptorSource fileDescriptorSource = null;
    for (Map.Entry<Object, Object> property : properties.entrySet()) {
        Object key = property.getKey();
        if (key instanceof String) {
            String keyString = (String) key;
            if (keyString.startsWith(InfinispanClientProducer.PROTOBUF_FILE_PREFIX)) {
                String fileName = keyString.substring(InfinispanClientProducer.PROTOBUF_FILE_PREFIX.length());
                String fileContents = (String) property.getValue();
                if (fileDescriptorSource == null) {
                    fileDescriptorSource = new FileDescriptorSource();
                }
                fileDescriptorSource.addProtoFile(fileName, fileContents);
            }
        }
    }
    if (fileDescriptorSource != null) {
        serializationContext.registerProtoFiles(fileDescriptorSource);
    }
    Set<Bean<FileDescriptorSource>> protoFileBeans = (Set) beanManager.getBeans(FileDescriptorSource.class);
    for (Bean<FileDescriptorSource> bean : protoFileBeans) {
        CreationalContext<FileDescriptorSource> ctx = beanManager.createCreationalContext(bean);
        FileDescriptorSource fds = (FileDescriptorSource) beanManager.getReference(bean, FileDescriptorSource.class, ctx);
        serializationContext.registerProtoFiles(fds);
        // Register all of the fds so they can be queried
        for (Map.Entry<String, char[]> fdEntry : fds.getFileDescriptors().entrySet()) {
            properties.put(PROTOBUF_FILE_PREFIX + fdEntry.getKey(), new String(fdEntry.getValue()));
        }
    }
    Set<Bean<BaseMarshaller>> beans = (Set) beanManager.getBeans(BaseMarshaller.class);
    for (Bean<BaseMarshaller> bean : beans) {
        CreationalContext<BaseMarshaller> ctx = beanManager.createCreationalContext(bean);
        BaseMarshaller messageMarshaller = (BaseMarshaller) beanManager.getReference(bean, BaseMarshaller.class, ctx);
        serializationContext.registerMarshaller(messageMarshaller);
    }
}
Also used : SerializationContext(org.infinispan.protostream.SerializationContext) Set(java.util.Set) SerializationContextInitializer(org.infinispan.protostream.SerializationContextInitializer) Bean(javax.enterprise.inject.spi.Bean) BaseMarshaller(org.infinispan.protostream.BaseMarshaller) FileDescriptorSource(org.infinispan.protostream.FileDescriptorSource) Map(java.util.Map)

Example 10 with BaseMarshaller

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

the class SpringRemoteCacheManager method addSessionContextInitializerAndMarshaller.

private void addSessionContextInitializerAndMarshaller(SerializationContext ctx, 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();
    sessionSci.registerMarshallers(ctx);
    sessionSci.registerSchema(ctx);
    BaseMarshaller sessionAttributeMarshaller = new MapSessionProtoAdapter.SessionAttributeRawMarshaller(serializationMarshaller);
    ctx.registerMarshaller(sessionAttributeMarshaller);
}
Also used : BaseMarshaller(org.infinispan.protostream.BaseMarshaller) MapSession(org.springframework.session.MapSession)

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