Search in sources :

Example 1 with Marshaller

use of org.infinispan.commons.marshall.Marshaller in project wildfly by wildfly.

the class RemoteCacheContainerConfigurationServiceConfigurator method get.

@Override
public Configuration get() {
    String name = this.getServiceName().getSimpleName();
    ConfigurationBuilder builder = new ConfigurationBuilder();
    // Configure formal security first
    builder.security().read(this.security.get());
    // Apply properties next, which may override formal security configuration
    builder.withProperties(this.properties).connectionTimeout(this.connectionTimeout).maxRetries(this.maxRetries).version(ProtocolVersion.parseVersion(this.protocolVersion)).socketTimeout(this.socketTimeout).statistics().enabled(this.statisticsEnabled).jmxDomain("org.wildfly.clustering.infinispan").jmxEnabled(this.server != null).jmxName(name).mBeanServerLookup((this.server != null) ? new MBeanServerProvider(this.server.get()) : null).tcpNoDelay(this.tcpNoDelay).tcpKeepAlive(this.tcpKeepAlive).transactionTimeout(this.transactionTimeout, TimeUnit.MILLISECONDS);
    List<Module> modules = this.modules.get();
    Marshaller marshaller = this.marshallerFactory.apply(this.loader.get(), modules);
    builder.marshaller(marshaller);
    builder.classLoader(modules.size() > 1 ? new AggregatedClassLoader(modules.stream().map(Module::getClassLoader).collect(Collectors.toList())) : modules.get(0).getClassLoader());
    builder.connectionPool().read(this.connectionPool.get());
    builder.asyncExecutorFactory().read(this.threadPools.get(ThreadPoolResourceDefinition.CLIENT).get());
    for (Map.Entry<String, List<SupplierDependency<OutboundSocketBinding>>> cluster : this.clusters.entrySet()) {
        String clusterName = cluster.getKey();
        List<SupplierDependency<OutboundSocketBinding>> bindingDependencies = cluster.getValue();
        if (this.defaultRemoteCluster.equals(clusterName)) {
            for (Supplier<OutboundSocketBinding> bindingDependency : bindingDependencies) {
                OutboundSocketBinding binding = bindingDependency.get();
                builder.addServer().host(binding.getUnresolvedDestinationAddress()).port(binding.getDestinationPort());
            }
        } else {
            ClusterConfigurationBuilder clusterConfigurationBuilder = builder.addCluster(clusterName);
            for (Supplier<OutboundSocketBinding> bindingDependency : bindingDependencies) {
                OutboundSocketBinding binding = bindingDependency.get();
                clusterConfigurationBuilder.addClusterNode(binding.getUnresolvedDestinationAddress(), binding.getDestinationPort());
            }
        }
    }
    return builder.build();
}
Also used : ClusterConfigurationBuilder(org.infinispan.client.hotrod.configuration.ClusterConfigurationBuilder) ConfigurationBuilder(org.infinispan.client.hotrod.configuration.ConfigurationBuilder) Marshaller(org.infinispan.commons.marshall.Marshaller) OutboundSocketBinding(org.jboss.as.network.OutboundSocketBinding) SupplierDependency(org.wildfly.clustering.service.SupplierDependency) ServiceSupplierDependency(org.wildfly.clustering.service.ServiceSupplierDependency) MBeanServerProvider(org.jboss.as.clustering.infinispan.MBeanServerProvider) AggregatedClassLoader(org.infinispan.commons.util.AggregatedClassLoader) ClusterConfigurationBuilder(org.infinispan.client.hotrod.configuration.ClusterConfigurationBuilder) List(java.util.List) ArrayList(java.util.ArrayList) Module(org.jboss.modules.Module) Map(java.util.Map) EnumMap(java.util.EnumMap) HashMap(java.util.HashMap)

Example 2 with Marshaller

use of org.infinispan.commons.marshall.Marshaller 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 3 with Marshaller

use of org.infinispan.commons.marshall.Marshaller in project wildfly by wildfly.

the class HotRodSessionFactory method expired.

@ClientCacheEntryExpired
public void expired(ClientCacheEntryCustomEvent<byte[]> event) {
    RemoteCache<SessionCreationMetaDataKey, SessionCreationMetaDataEntry<L>> creationMetaDataCache = this.creationMetaDataCache;
    RemoteCache<SessionAccessMetaDataKey, SessionAccessMetaData> accessMetaDataCache = this.accessMetaDataCache;
    ImmutableSessionMetaDataFactory<CompositeSessionMetaDataEntry<L>> metaDataFactory = this.metaDataFactory;
    ImmutableSessionAttributesFactory<V> attributesFactory = this.attributesFactory;
    Remover<String> attributesRemover = this.attributesRemover;
    Collection<SessionExpirationListener> listeners = this.listeners;
    boolean nearCacheEnabled = this.nearCacheEnabled;
    Runnable task = new Runnable() {

        @Override
        public void run() {
            ByteBuffer buffer = ByteBuffer.wrap(event.getEventData());
            byte[] key = new byte[UnsignedNumeric.readUnsignedInt(buffer)];
            buffer.get(key);
            byte[] value = buffer.remaining() > 0 ? new byte[UnsignedNumeric.readUnsignedInt(buffer)] : null;
            if (value != null) {
                buffer.get(value);
            }
            Marshaller marshaller = creationMetaDataCache.getRemoteCacheManager().getConfiguration().marshaller();
            String id = null;
            try {
                SessionCreationMetaDataKey creationKey = (SessionCreationMetaDataKey) marshaller.objectFromByteBuffer(key);
                id = creationKey.getId();
                @SuppressWarnings("unchecked") SessionCreationMetaDataEntry<L> creationEntry = (value != null) ? (SessionCreationMetaDataEntry<L>) marshaller.objectFromByteBuffer(value) : new SessionCreationMetaDataEntry<>(new SimpleSessionCreationMetaData(Instant.EPOCH));
                // Ensure entry is removed from near cache
                if (nearCacheEnabled) {
                    creationMetaDataCache.withFlags(Flag.SKIP_LISTENER_NOTIFICATION).remove(creationKey);
                }
                SessionAccessMetaData accessMetaData = accessMetaDataCache.withFlags(Flag.FORCE_RETURN_VALUE).remove(new SessionAccessMetaDataKey(id));
                if (accessMetaData != null) {
                    V attributesValue = attributesFactory.findValue(id);
                    if (attributesValue != null) {
                        ImmutableSessionMetaData metaData = metaDataFactory.createImmutableSessionMetaData(id, new CompositeSessionMetaDataEntry<>(creationEntry, accessMetaData));
                        ImmutableSessionAttributes attributes = attributesFactory.createImmutableSessionAttributes(id, attributesValue);
                        ImmutableSession session = HotRodSessionFactory.this.createImmutableSession(id, metaData, attributes);
                        Logger.ROOT_LOGGER.tracef("Session %s has expired.", id);
                        for (SessionExpirationListener listener : listeners) {
                            listener.sessionExpired(session);
                        }
                        attributesRemover.remove(id);
                    }
                }
            } catch (IOException | ClassNotFoundException e) {
                Logger.ROOT_LOGGER.failedToExpireSession(e, id);
            }
        }
    };
    this.executor.submit(task);
}
Also used : ImmutableSession(org.wildfly.clustering.web.session.ImmutableSession) SessionExpirationListener(org.wildfly.clustering.web.session.SessionExpirationListener) CompositeSessionMetaDataEntry(org.wildfly.clustering.web.cache.session.CompositeSessionMetaDataEntry) Marshaller(org.infinispan.commons.marshall.Marshaller) ImmutableSessionAttributes(org.wildfly.clustering.web.session.ImmutableSessionAttributes) IOException(java.io.IOException) ImmutableSessionMetaData(org.wildfly.clustering.web.session.ImmutableSessionMetaData) ByteBuffer(java.nio.ByteBuffer) SimpleSessionCreationMetaData(org.wildfly.clustering.web.cache.session.SimpleSessionCreationMetaData) SessionAccessMetaData(org.wildfly.clustering.web.cache.session.SessionAccessMetaData) SessionCreationMetaDataEntry(org.wildfly.clustering.web.cache.session.SessionCreationMetaDataEntry) ClientCacheEntryExpired(org.infinispan.client.hotrod.annotation.ClientCacheEntryExpired)

Aggregations

Marshaller (org.infinispan.commons.marshall.Marshaller)3 AggregatedClassLoader (org.infinispan.commons.util.AggregatedClassLoader)2 MBeanServerProvider (org.jboss.as.clustering.infinispan.MBeanServerProvider)2 Module (org.jboss.modules.Module)2 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 EnumMap (java.util.EnumMap)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 ClientCacheEntryExpired (org.infinispan.client.hotrod.annotation.ClientCacheEntryExpired)1 ClusterConfigurationBuilder (org.infinispan.client.hotrod.configuration.ClusterConfigurationBuilder)1 ConfigurationBuilder (org.infinispan.client.hotrod.configuration.ConfigurationBuilder)1 PrivateGlobalConfigurationBuilder (org.infinispan.configuration.internal.PrivateGlobalConfigurationBuilder)1 SerializationContext (org.infinispan.protostream.SerializationContext)1 SerializationContextInitializer (org.infinispan.protostream.SerializationContextInitializer)1 OutboundSocketBinding (org.jboss.as.network.OutboundSocketBinding)1 ServiceSupplierDependency (org.wildfly.clustering.service.ServiceSupplierDependency)1