Search in sources :

Example 1 with SerializationContextInitializer

use of org.infinispan.protostream.SerializationContextInitializer in project wildfly by wildfly.

the class GlobalConfigurationServiceConfigurator method get.

@Override
public GlobalConfiguration get() {
    org.infinispan.configuration.global.GlobalConfigurationBuilder builder = new org.infinispan.configuration.global.GlobalConfigurationBuilder();
    builder.cacheManagerName(this.name).defaultCacheName(this.defaultCache).cacheContainer().statistics(this.statisticsEnabled);
    builder.transport().read(this.transport.get());
    List<Module> modules = this.modules.get();
    Marshaller marshaller = this.marshallerFactory.apply(this.loader.get(), modules);
    InfinispanLogger.ROOT_LOGGER.debugf("%s cache-container will use %s", this.name, marshaller.getClass().getName());
    // Register dummy serialization context initializer, to bypass service loading in org.infinispan.marshall.protostream.impl.SerializationContextRegistryImpl
    // Otherwise marshaller auto-detection will not work
    builder.serialization().marshaller(marshaller).addContextInitializer(new SerializationContextInitializer() {

        @Deprecated
        @Override
        public String getProtoFile() throws UncheckedIOException {
            return null;
        }

        @Deprecated
        @Override
        public String getProtoFileName() {
            return null;
        }

        @Override
        public void registerMarshallers(SerializationContext context) {
        }

        @Override
        public void registerSchema(SerializationContext context) {
        }
    });
    builder.classLoader(modules.size() > 1 ? new AggregatedClassLoader(modules.stream().map(Module::getClassLoader).collect(Collectors.toList())) : modules.get(0).getClassLoader());
    builder.blockingThreadPool().read(this.pools.get(ThreadPoolResourceDefinition.BLOCKING).get());
    builder.listenerThreadPool().read(this.pools.get(ThreadPoolResourceDefinition.LISTENER).get());
    builder.nonBlockingThreadPool().read(this.pools.get(ThreadPoolResourceDefinition.NON_BLOCKING).get());
    builder.expirationThreadPool().read(this.scheduledPools.get(ScheduledThreadPoolResourceDefinition.EXPIRATION).get());
    builder.shutdown().hookBehavior(ShutdownHookBehavior.DONT_REGISTER);
    // Disable registration of MicroProfile Metrics
    builder.metrics().gauges(false).histograms(false).accurateSize(true);
    builder.jmx().domain("org.wildfly.clustering.infinispan").mBeanServerLookup((this.server != null) ? new MBeanServerProvider(this.server.get()) : null).enabled(this.server != null);
    // See ISPN-12252 for details
    if (modules.stream().map(Module::getName).noneMatch("org.infinispan.hibernate-cache"::equals)) {
        // Disable triangle algorithm - we optimize for originator as primary owner
        builder.addModule(PrivateGlobalConfigurationBuilder.class).serverMode(true);
    }
    builder.globalState().disable();
    return builder.build();
}
Also used : PrivateGlobalConfigurationBuilder(org.infinispan.configuration.internal.PrivateGlobalConfigurationBuilder) SerializationContext(org.infinispan.protostream.SerializationContext) Marshaller(org.infinispan.commons.marshall.Marshaller) UncheckedIOException(java.io.UncheckedIOException) SerializationContextInitializer(org.infinispan.protostream.SerializationContextInitializer) MBeanServerProvider(org.jboss.as.clustering.infinispan.MBeanServerProvider) AggregatedClassLoader(org.infinispan.commons.util.AggregatedClassLoader) PrivateGlobalConfigurationBuilder(org.infinispan.configuration.internal.PrivateGlobalConfigurationBuilder) Module(org.jboss.modules.Module)

Example 2 with SerializationContextInitializer

use of org.infinispan.protostream.SerializationContextInitializer in project wildfly by wildfly.

the class SerializationContextBuilder method tryLoad.

private boolean tryLoad(ClassLoader loader) {
    PrivilegedAction<Iterator<SerializationContextInitializer>> action = new PrivilegedAction<Iterator<SerializationContextInitializer>>() {

        @Override
        public Iterator<SerializationContextInitializer> run() {
            return ServiceLoader.load(SerializationContextInitializer.class, loader).iterator();
        }
    };
    Iterator<SerializationContextInitializer> initializers = WildFlySecurityManager.doUnchecked(action);
    boolean init = initializers.hasNext();
    while (initializers.hasNext()) {
        SerializationContextInitializer initializer = initializers.next();
        // Do not load initializers from protostream-types
        if (!initializer.getClass().getName().startsWith(PROTOSTREAM_BASE_PACKAGE_NAME)) {
            this.init(initializer);
        }
    }
    return init;
}
Also used : PrivilegedAction(java.security.PrivilegedAction) Iterator(java.util.Iterator) SerializationContextInitializer(org.infinispan.protostream.SerializationContextInitializer)

Aggregations

SerializationContextInitializer (org.infinispan.protostream.SerializationContextInitializer)2 UncheckedIOException (java.io.UncheckedIOException)1 PrivilegedAction (java.security.PrivilegedAction)1 Iterator (java.util.Iterator)1 Marshaller (org.infinispan.commons.marshall.Marshaller)1 AggregatedClassLoader (org.infinispan.commons.util.AggregatedClassLoader)1 PrivateGlobalConfigurationBuilder (org.infinispan.configuration.internal.PrivateGlobalConfigurationBuilder)1 SerializationContext (org.infinispan.protostream.SerializationContext)1 MBeanServerProvider (org.jboss.as.clustering.infinispan.MBeanServerProvider)1 Module (org.jboss.modules.Module)1