Search in sources :

Example 1 with MediaType

use of org.infinispan.commons.dataconversion.MediaType in project wildfly-clustering-spring-session by wildfly-clustering.

the class InfinispanSessionRepository method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    ServletContext context = this.configuration.getServletContext();
    // Deployment name = host name + context path + version
    String deploymentName = context.getVirtualServerName() + context.getContextPath();
    String resourceName = this.configuration.getConfigurationResource();
    String templateName = this.configuration.getTemplateName();
    Integer maxActiveSessions = this.configuration.getMaxActiveSessions();
    SessionAttributePersistenceStrategy strategy = this.configuration.getPersistenceStrategy();
    COUNTER.incrementAndGet();
    this.stopTasks.add(() -> {
        // Stop RxJava schedulers when no longer in use
        if (COUNTER.decrementAndGet() == 0) {
            Schedulers.shutdown();
        }
    });
    ClassLoader containerLoader = WildFlySecurityManager.getClassLoaderPrivileged(InfinispanSessionManagerFactory.class);
    URL url = context.getResource(resourceName);
    if (url == null) {
        throw new FileNotFoundException(resourceName);
    }
    ConfigurationBuilderHolder holder = new ParserRegistry().parse(url);
    GlobalConfigurationBuilder global = holder.getGlobalConfigurationBuilder();
    String containerName = global.cacheContainer().name();
    TransportConfiguration transport = global.transport().create();
    JGroupsChannelConfigurator configurator = (transport.transport() != null) ? new JChannelConfigurator(context, transport) : null;
    JChannel channel = (configurator != null) ? configurator.createChannel(null) : null;
    if (channel != null) {
        channel.setName(transport.nodeName());
        channel.setDiscardOwnMessages(true);
        channel.connect(transport.clusterName());
        this.stopTasks.add(channel::close);
        GlobalJmxConfiguration jmx = global.jmx().create();
        if (jmx.enabled()) {
            ObjectName prefix = new ObjectName(jmx.domain(), "manager", ObjectName.quote(containerName));
            JmxConfigurator.registerChannel(channel, ManagementFactory.getPlatformMBeanServer(), prefix, transport.clusterName(), true);
            this.stopTasks.add(() -> {
                try {
                    JmxConfigurator.unregisterChannel(channel, ManagementFactory.getPlatformMBeanServer(), prefix, transport.clusterName());
                } catch (Exception e) {
                    context.log(e.getLocalizedMessage(), e);
                }
            });
        }
        Properties properties = new Properties();
        properties.put(JGroupsTransport.CHANNEL_CONFIGURATOR, new ForkChannelConfigurator(channel, containerName));
        global.transport().withProperties(properties);
    }
    Function<ClassLoader, ByteBufferMarshaller> marshallerFactory = this.configuration.getMarshallerFactory();
    CommandDispatcherFactory dispatcherFactory = (channel != null) ? new ChannelCommandDispatcherFactory(new ChannelCommandDispatcherFactoryConfiguration() {

        @Override
        public JChannel getChannel() {
            return channel;
        }

        @Override
        public ByteBufferMarshaller getMarshaller() {
            return SessionMarshallerFactory.PROTOSTREAM.apply(containerLoader);
        }

        @Override
        public Duration getTimeout() {
            return Duration.ofMillis(transport.initialClusterTimeout());
        }

        @Override
        public Function<ClassLoader, ByteBufferMarshaller> getMarshallerFactory() {
            return marshallerFactory;
        }

        @Override
        public Predicate<ByteBuffer> getUnknownForkPredicate() {
            return buffer -> buffer.remaining() == 0;
        }

        @Override
        public Function<ClassLoader, Contextualizer> getContextualizerFactory() {
            return loader -> new ContextReferenceExecutor<>(loader, ContextClassLoaderReference.INSTANCE);
        }
    }) : new LocalCommandDispatcherFactory(new LocalGroup(transport.nodeName()));
    if (channel != null) {
        ChannelCommandDispatcherFactory factory = (ChannelCommandDispatcherFactory) dispatcherFactory;
        this.stopTasks.add(factory::close);
    }
    holder.getGlobalConfigurationBuilder().classLoader(containerLoader).blockingThreadPool().threadFactory(new DefaultThreadFactory(BlockingManager.class)).expirationThreadPool().threadFactory(new DefaultThreadFactory(ExpirationManager.class)).listenerThreadPool().threadFactory(new DefaultThreadFactory(ListenerInvocation.class)).nonBlockingThreadPool().threadFactory(new DefaultNonBlockingThreadFactory(NonBlockingManager.class)).serialization().marshaller(new InfinispanProtoStreamMarshaller(new SimpleClassLoaderMarshaller(containerLoader), builder -> builder.load(containerLoader))).addContextInitializer(new SerializationContextInitializer() {

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

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

        @Override
        public void registerMarshallers(SerializationContext context) {
        }

        @Override
        public void registerSchema(SerializationContext context) {
        }
    }).globalState().configurationStorage(ConfigurationStorage.IMMUTABLE).disable();
    @SuppressWarnings("resource") EmbeddedCacheManager container = new DefaultCacheManager(holder, false);
    Configuration template = (templateName != null) ? container.getCacheConfiguration(templateName) : container.getDefaultCacheConfiguration();
    if (template == null) {
        if (templateName == null) {
            throw new IllegalArgumentException("Infinispan configuration does not define a default cache");
        }
        throw new IllegalArgumentException(String.format("No such configuration template: %s", templateName));
    }
    ConfigurationBuilder builder = new ConfigurationBuilder().read(template).template(false);
    builder.encoding().mediaType(MediaType.APPLICATION_OBJECT_TYPE);
    builder.clustering().hash().groups().enabled();
    // Disable expiration, if necessary
    ExpirationConfiguration expiration = builder.expiration().create();
    if ((expiration.lifespan() >= 0) || (expiration.maxIdle() >= 0)) {
        builder.expiration().lifespan(-1).maxIdle(-1);
    }
    EvictionStrategy eviction = (maxActiveSessions != null) ? EvictionStrategy.REMOVE : EvictionStrategy.MANUAL;
    builder.memory().storage(StorageType.HEAP).whenFull(eviction).maxCount((maxActiveSessions != null) ? maxActiveSessions.longValue() : -1);
    if (eviction.isEnabled()) {
        // Only evict creation meta-data entries
        // We will cascade eviction to the remaining entries for a given session
        builder.addModule(DataContainerConfigurationBuilder.class).evictable(SessionCreationMetaDataKey.class::isInstance);
    }
    container.defineConfiguration(deploymentName, builder.build());
    this.stopTasks.add(() -> container.undefineConfiguration(deploymentName));
    container.start();
    this.stopTasks.add(container::stop);
    ByteBufferMarshaller marshaller = marshallerFactory.apply(context.getClassLoader());
    MarshalledValueFactory<ByteBufferMarshaller> marshalledValueFactory = new ByteBufferMarshalledValueFactory(marshaller);
    ServiceLoader<Immutability> loadedImmutability = ServiceLoader.load(Immutability.class, Immutability.class.getClassLoader());
    Immutability immutability = new CompositeImmutability(new CompositeIterable<>(EnumSet.allOf(DefaultImmutability.class), EnumSet.allOf(SessionAttributeImmutability.class), EnumSet.allOf(SpringSecurityImmutability.class), loadedImmutability));
    Supplier<String> identifierFactory = this.configuration.getIdentifierFactory();
    KeyAffinityServiceFactory affinityFactory = new DefaultKeyAffinityServiceFactory();
    Map<String, String> indexes = this.configuration.getIndexes();
    Map<String, SSOManager<Void, String, String, Void, TransactionBatch>> managers = indexes.isEmpty() ? Collections.emptyMap() : new HashMap<>();
    for (Map.Entry<String, String> entry : indexes.entrySet()) {
        String cacheName = String.format("%s/%s", deploymentName, entry.getKey());
        String indexName = entry.getValue();
        container.defineConfiguration(cacheName, builder.build());
        this.stopTasks.add(() -> container.undefineConfiguration(cacheName));
        Cache<?, ?> cache = container.getCache(cacheName);
        cache.start();
        this.stopTasks.add(cache::stop);
        SSOManagerFactory<Void, String, String, TransactionBatch> ssoManagerFactory = new InfinispanSSOManagerFactory<>(new InfinispanSSOManagerFactoryConfiguration() {

            @Override
            public <K, V> Cache<K, V> getCache() {
                return container.getCache(cacheName);
            }

            @Override
            public KeyAffinityServiceFactory getKeyAffinityServiceFactory() {
                return affinityFactory;
            }
        });
        SSOManager<Void, String, String, Void, TransactionBatch> ssoManager = ssoManagerFactory.createSSOManager(new SSOManagerConfiguration<ByteBufferMarshaller, Void>() {

            @Override
            public Supplier<String> getIdentifierFactory() {
                return identifierFactory;
            }

            @Override
            public MarshalledValueFactory<ByteBufferMarshaller> getMarshalledValueFactory() {
                return marshalledValueFactory;
            }

            @Override
            public LocalContextFactory<Void> getLocalContextFactory() {
                return InfinispanSessionRepository.this;
            }
        });
        managers.put(indexName, ssoManager);
    }
    IndexResolver<Session> resolver = this.configuration.getIndexResolver();
    IndexingConfiguration<TransactionBatch> indexing = new IndexingConfiguration<TransactionBatch>() {

        @Override
        public Map<String, SSOManager<Void, String, String, Void, TransactionBatch>> getSSOManagers() {
            return managers;
        }

        @Override
        public IndexResolver<Session> getIndexResolver() {
            return resolver;
        }
    };
    Cache<?, ?> cache = container.getCache(deploymentName);
    cache.start();
    this.stopTasks.add(cache::stop);
    NodeFactory<org.jgroups.Address> memberFactory = (channel != null) ? (ChannelCommandDispatcherFactory) dispatcherFactory : new LocalGroup(context.getVirtualServerName());
    CacheGroup group = new CacheGroup(new CacheGroupConfiguration() {

        @Override
        public Cache<?, ?> getCache() {
            return cache;
        }

        @Override
        public NodeFactory<org.jgroups.Address> getMemberFactory() {
            return memberFactory;
        }
    });
    this.stopTasks.add(group::close);
    SessionManagerFactory<ServletContext, Void, TransactionBatch> managerFactory = new InfinispanSessionManagerFactory<>(new InfinispanSessionManagerFactoryConfiguration<HttpSession, ServletContext, HttpSessionActivationListener, ByteBufferMarshaller, Void>() {

        @Override
        public Integer getMaxActiveSessions() {
            return maxActiveSessions;
        }

        @Override
        public SessionAttributePersistenceStrategy getAttributePersistenceStrategy() {
            return strategy;
        }

        @Override
        public String getDeploymentName() {
            return deploymentName;
        }

        @Override
        public MarshalledValueFactory<ByteBufferMarshaller> getMarshalledValueFactory() {
            return marshalledValueFactory;
        }

        @Override
        public String getServerName() {
            return context.getVirtualServerName();
        }

        @Override
        public LocalContextFactory<Void> getLocalContextFactory() {
            return InfinispanSessionRepository.this;
        }

        @Override
        public <K, V> Cache<K, V> getCache() {
            return container.getCache(this.getDeploymentName());
        }

        @Override
        public Immutability getImmutability() {
            return immutability;
        }

        @Override
        public SpecificationProvider<HttpSession, ServletContext, HttpSessionActivationListener> getSpecificationProvider() {
            return SpringSpecificationProvider.INSTANCE;
        }

        @Override
        public CommandDispatcherFactory getCommandDispatcherFactory() {
            return dispatcherFactory;
        }

        @Override
        public KeyAffinityServiceFactory getKeyAffinityServiceFactory() {
            return affinityFactory;
        }

        @Override
        public NodeFactory<Address> getMemberFactory() {
            return group;
        }
    });
    this.stopTasks.add(managerFactory::close);
    ApplicationEventPublisher publisher = this.configuration.getEventPublisher();
    BiConsumer<ImmutableSession, BiFunction<Object, Session, ApplicationEvent>> sessionDestroyAction = new ImmutableSessionDestroyAction<>(publisher, context, indexing);
    SessionExpirationListener expirationListener = new ImmutableSessionExpirationListener(context, sessionDestroyAction);
    SessionManager<Void, TransactionBatch> manager = managerFactory.createSessionManager(new SessionManagerConfiguration<ServletContext>() {

        @Override
        public ServletContext getServletContext() {
            return context;
        }

        @Override
        public Supplier<String> getIdentifierFactory() {
            return identifierFactory;
        }

        @Override
        public SessionExpirationListener getExpirationListener() {
            return expirationListener;
        }

        @Override
        public Recordable<ImmutableSessionMetaData> getInactiveSessionRecorder() {
            // Spring session has no metrics capability
            return null;
        }
    });
    Optional<Duration> defaultTimeout = setDefaultMaxInactiveInterval(manager, Duration.ofMinutes(context.getSessionTimeout()));
    manager.start();
    this.stopTasks.add(manager::stop);
    this.repository = new DistributableSessionRepository<>(new DistributableSessionRepositoryConfiguration<TransactionBatch>() {

        @Override
        public SessionManager<Void, TransactionBatch> getSessionManager() {
            return manager;
        }

        @Override
        public Optional<Duration> getDefaultTimeout() {
            return defaultTimeout;
        }

        @Override
        public ApplicationEventPublisher getEventPublisher() {
            return publisher;
        }

        @Override
        public ServletContext getServletContext() {
            return context;
        }

        @Override
        public BiConsumer<ImmutableSession, BiFunction<Object, Session, ApplicationEvent>> getSessionDestroyAction() {
            return sessionDestroyAction;
        }

        @Override
        public IndexingConfiguration<TransactionBatch> getIndexingConfiguration() {
            return indexing;
        }
    });
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) CompositeImmutability(org.wildfly.clustering.ee.immutable.CompositeImmutability) SpringSpecificationProvider(org.wildfly.clustering.web.spring.SpringSpecificationProvider) DistributableSessionRepositoryConfiguration(org.wildfly.clustering.web.spring.DistributableSessionRepositoryConfiguration) IndexResolver(org.springframework.session.IndexResolver) Cache(org.infinispan.Cache) DefaultCacheManager(org.infinispan.manager.DefaultCacheManager) DefaultNonBlockingThreadFactory(org.wildfly.clustering.infinispan.spi.DefaultNonBlockingThreadFactory) ConfigurationBuilderHolder(org.infinispan.configuration.parsing.ConfigurationBuilderHolder) Duration(java.time.Duration) Map(java.util.Map) LocalGroup(org.wildfly.clustering.server.group.LocalGroup) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) LocalContextFactory(org.wildfly.clustering.web.LocalContextFactory) EnumSet(java.util.EnumSet) SpecificationProvider(org.wildfly.clustering.web.session.SpecificationProvider) CacheGroupConfiguration(org.wildfly.clustering.server.group.CacheGroupConfiguration) JGroupsTransport(org.infinispan.remoting.transport.jgroups.JGroupsTransport) ContextClassLoaderReference(org.jboss.as.clustering.context.ContextClassLoaderReference) ImmutableSessionMetaData(org.wildfly.clustering.web.session.ImmutableSessionMetaData) InfinispanSSOManagerFactory(org.wildfly.clustering.web.infinispan.sso.InfinispanSSOManagerFactory) Registration(org.wildfly.clustering.Registration) InfinispanSessionManagerFactory(org.wildfly.clustering.web.infinispan.session.InfinispanSessionManagerFactory) WildFlySecurityManager(org.wildfly.security.manager.WildFlySecurityManager) DisposableBean(org.springframework.beans.factory.DisposableBean) JChannel(org.jgroups.JChannel) SessionManagerConfiguration(org.wildfly.clustering.web.session.SessionManagerConfiguration) DefaultImmutability(org.wildfly.clustering.ee.immutable.DefaultImmutability) ExpirationConfiguration(org.infinispan.configuration.cache.ExpirationConfiguration) HttpSessionActivationListener(javax.servlet.http.HttpSessionActivationListener) Supplier(java.util.function.Supplier) InfinispanSSOManagerFactoryConfiguration(org.wildfly.clustering.web.infinispan.sso.InfinispanSSOManagerFactoryConfiguration) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) MarshalledValueFactory(org.wildfly.clustering.marshalling.spi.MarshalledValueFactory) SerializationContextInitializer(org.infinispan.protostream.SerializationContextInitializer) BiConsumer(java.util.function.BiConsumer) CompositeIterable(org.wildfly.clustering.ee.CompositeIterable) KeyAffinityServiceFactory(org.wildfly.clustering.infinispan.spi.affinity.KeyAffinityServiceFactory) ManagementFactory(java.lang.management.ManagementFactory) IndexingConfiguration(org.wildfly.clustering.web.spring.IndexingConfiguration) SessionCreationMetaDataKey(org.wildfly.clustering.web.infinispan.session.SessionCreationMetaDataKey) Address(org.infinispan.remoting.transport.Address) SessionAttributePersistenceStrategy(org.wildfly.clustering.web.session.SessionAttributePersistenceStrategy) SessionMarshallerFactory(org.wildfly.clustering.web.spring.SessionMarshallerFactory) Properties(java.util.Properties) StorageType(org.infinispan.configuration.cache.StorageType) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) SpringSession(org.wildfly.clustering.web.spring.SpringSession) LocalCommandDispatcherFactory(org.wildfly.clustering.server.dispatcher.LocalCommandDispatcherFactory) SimpleClassLoaderMarshaller(org.wildfly.clustering.marshalling.protostream.SimpleClassLoaderMarshaller) ApplicationEvent(org.springframework.context.ApplicationEvent) Recordable(org.wildfly.clustering.ee.Recordable) EvictionStrategy(org.infinispan.eviction.EvictionStrategy) ImmutableSessionExpirationListener(org.wildfly.clustering.web.spring.ImmutableSessionExpirationListener) SSOManagerFactory(org.wildfly.clustering.web.sso.SSOManagerFactory) DefaultThreadFactory(org.jboss.as.clustering.context.DefaultThreadFactory) DefaultKeyAffinityServiceFactory(org.wildfly.clustering.infinispan.spi.affinity.DefaultKeyAffinityServiceFactory) DistributableSessionRepository(org.wildfly.clustering.web.spring.DistributableSessionRepository) ServletContext(javax.servlet.ServletContext) SerializationContext(org.infinispan.protostream.SerializationContext) ListIterator(java.util.ListIterator) URL(java.net.URL) GlobalJmxConfiguration(org.infinispan.configuration.global.GlobalJmxConfiguration) BiFunction(java.util.function.BiFunction) SSOManager(org.wildfly.clustering.web.sso.SSOManager) Contextualizer(org.jboss.as.clustering.context.Contextualizer) TransactionBatch(org.wildfly.clustering.ee.cache.tx.TransactionBatch) NodeFactory(org.wildfly.clustering.spi.NodeFactory) ByteBuffer(java.nio.ByteBuffer) SessionManager(org.wildfly.clustering.web.session.SessionManager) SpringSecurityImmutability(org.wildfly.clustering.web.spring.security.SpringSecurityImmutability) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ContextReferenceExecutor(org.jboss.as.clustering.context.ContextReferenceExecutor) FindByIndexNameSessionRepository(org.springframework.session.FindByIndexNameSessionRepository) HttpSession(javax.servlet.http.HttpSession) SessionManagerFactory(org.wildfly.clustering.web.session.SessionManagerFactory) Predicate(java.util.function.Predicate) CacheGroup(org.wildfly.clustering.server.group.CacheGroup) ServiceLoader(java.util.ServiceLoader) ObjectName(javax.management.ObjectName) ChannelCommandDispatcherFactory(org.wildfly.clustering.server.dispatcher.ChannelCommandDispatcherFactory) FileNotFoundException(java.io.FileNotFoundException) List(java.util.List) ChannelCommandDispatcherFactoryConfiguration(org.wildfly.clustering.server.dispatcher.ChannelCommandDispatcherFactoryConfiguration) ConfigurationStorage(org.infinispan.globalstate.ConfigurationStorage) Optional(java.util.Optional) DataContainerConfigurationBuilder(org.wildfly.clustering.infinispan.spi.DataContainerConfigurationBuilder) ImmutableSessionDestroyAction(org.wildfly.clustering.web.spring.ImmutableSessionDestroyAction) JmxConfigurator(org.jgroups.jmx.JmxConfigurator) SSOManagerConfiguration(org.wildfly.clustering.web.sso.SSOManagerConfiguration) HashMap(java.util.HashMap) ByteBufferMarshaller(org.wildfly.clustering.marshalling.spi.ByteBufferMarshaller) Function(java.util.function.Function) InitializingBean(org.springframework.beans.factory.InitializingBean) Schedulers(io.reactivex.rxjava3.schedulers.Schedulers) MediaType(org.infinispan.commons.dataconversion.MediaType) ExpirationManager(org.infinispan.expiration.ExpirationManager) Registrar(org.wildfly.clustering.Registrar) Immutability(org.wildfly.clustering.ee.Immutability) InfinispanSessionManagerFactoryConfiguration(org.wildfly.clustering.web.infinispan.session.InfinispanSessionManagerFactoryConfiguration) ImmutableSession(org.wildfly.clustering.web.session.ImmutableSession) LinkedList(java.util.LinkedList) ByteBufferMarshalledValueFactory(org.wildfly.clustering.marshalling.spi.ByteBufferMarshalledValueFactory) SessionAttributeImmutability(org.wildfly.clustering.web.session.SessionAttributeImmutability) InfinispanProtoStreamMarshaller(org.wildfly.clustering.infinispan.spi.marshalling.InfinispanProtoStreamMarshaller) ListenerInvocation(org.infinispan.notifications.impl.ListenerInvocation) NonBlockingManager(org.infinispan.util.concurrent.NonBlockingManager) Session(org.springframework.session.Session) SessionExpirationListener(org.wildfly.clustering.web.session.SessionExpirationListener) TransportConfiguration(org.infinispan.configuration.global.TransportConfiguration) Configuration(org.infinispan.configuration.cache.Configuration) ParserRegistry(org.infinispan.configuration.parsing.ParserRegistry) JGroupsChannelConfigurator(org.infinispan.remoting.transport.jgroups.JGroupsChannelConfigurator) CommandDispatcherFactory(org.wildfly.clustering.spi.dispatcher.CommandDispatcherFactory) BlockingManager(org.infinispan.util.concurrent.BlockingManager) Collections(java.util.Collections) MarshalledValueFactory(org.wildfly.clustering.marshalling.spi.MarshalledValueFactory) ByteBufferMarshalledValueFactory(org.wildfly.clustering.marshalling.spi.ByteBufferMarshalledValueFactory) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) DataContainerConfigurationBuilder(org.wildfly.clustering.infinispan.spi.DataContainerConfigurationBuilder) JChannel(org.jgroups.JChannel) ImmutableSession(org.wildfly.clustering.web.session.ImmutableSession) DistributableSessionRepositoryConfiguration(org.wildfly.clustering.web.spring.DistributableSessionRepositoryConfiguration) CacheGroupConfiguration(org.wildfly.clustering.server.group.CacheGroupConfiguration) SessionManagerConfiguration(org.wildfly.clustering.web.session.SessionManagerConfiguration) ExpirationConfiguration(org.infinispan.configuration.cache.ExpirationConfiguration) InfinispanSSOManagerFactoryConfiguration(org.wildfly.clustering.web.infinispan.sso.InfinispanSSOManagerFactoryConfiguration) IndexingConfiguration(org.wildfly.clustering.web.spring.IndexingConfiguration) GlobalJmxConfiguration(org.infinispan.configuration.global.GlobalJmxConfiguration) ChannelCommandDispatcherFactoryConfiguration(org.wildfly.clustering.server.dispatcher.ChannelCommandDispatcherFactoryConfiguration) SSOManagerConfiguration(org.wildfly.clustering.web.sso.SSOManagerConfiguration) InfinispanSessionManagerFactoryConfiguration(org.wildfly.clustering.web.infinispan.session.InfinispanSessionManagerFactoryConfiguration) TransportConfiguration(org.infinispan.configuration.global.TransportConfiguration) Configuration(org.infinispan.configuration.cache.Configuration) Address(org.infinispan.remoting.transport.Address) CacheGroup(org.wildfly.clustering.server.group.CacheGroup) FileNotFoundException(java.io.FileNotFoundException) SerializationContextInitializer(org.infinispan.protostream.SerializationContextInitializer) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) InfinispanSSOManagerFactory(org.wildfly.clustering.web.infinispan.sso.InfinispanSSOManagerFactory) DistributableSessionRepositoryConfiguration(org.wildfly.clustering.web.spring.DistributableSessionRepositoryConfiguration) ImmutableSessionExpirationListener(org.wildfly.clustering.web.spring.ImmutableSessionExpirationListener) SessionExpirationListener(org.wildfly.clustering.web.session.SessionExpirationListener) GlobalJmxConfiguration(org.infinispan.configuration.global.GlobalJmxConfiguration) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) ByteBufferMarshaller(org.wildfly.clustering.marshalling.spi.ByteBufferMarshaller) ExpirationManager(org.infinispan.expiration.ExpirationManager) CompositeImmutability(org.wildfly.clustering.ee.immutable.CompositeImmutability) DefaultImmutability(org.wildfly.clustering.ee.immutable.DefaultImmutability) SpringSecurityImmutability(org.wildfly.clustering.web.spring.security.SpringSecurityImmutability) Immutability(org.wildfly.clustering.ee.Immutability) SessionAttributeImmutability(org.wildfly.clustering.web.session.SessionAttributeImmutability) SessionCreationMetaDataKey(org.wildfly.clustering.web.infinispan.session.SessionCreationMetaDataKey) SpringSpecificationProvider(org.wildfly.clustering.web.spring.SpringSpecificationProvider) SpecificationProvider(org.wildfly.clustering.web.session.SpecificationProvider) ByteBufferMarshalledValueFactory(org.wildfly.clustering.marshalling.spi.ByteBufferMarshalledValueFactory) Map(java.util.Map) HashMap(java.util.HashMap) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) SerializationContext(org.infinispan.protostream.SerializationContext) Contextualizer(org.jboss.as.clustering.context.Contextualizer) InfinispanSessionManagerFactory(org.wildfly.clustering.web.infinispan.session.InfinispanSessionManagerFactory) SimpleClassLoaderMarshaller(org.wildfly.clustering.marshalling.protostream.SimpleClassLoaderMarshaller) HttpSessionActivationListener(javax.servlet.http.HttpSessionActivationListener) URL(java.net.URL) ImmutableSessionDestroyAction(org.wildfly.clustering.web.spring.ImmutableSessionDestroyAction) Supplier(java.util.function.Supplier) DataContainerConfigurationBuilder(org.wildfly.clustering.infinispan.spi.DataContainerConfigurationBuilder) TransactionBatch(org.wildfly.clustering.ee.cache.tx.TransactionBatch) HttpSession(javax.servlet.http.HttpSession) SessionAttributePersistenceStrategy(org.wildfly.clustering.web.session.SessionAttributePersistenceStrategy) ParserRegistry(org.infinispan.configuration.parsing.ParserRegistry) NonBlockingManager(org.infinispan.util.concurrent.NonBlockingManager) ContextReferenceExecutor(org.jboss.as.clustering.context.ContextReferenceExecutor) BiFunction(java.util.function.BiFunction) LocalCommandDispatcherFactory(org.wildfly.clustering.server.dispatcher.LocalCommandDispatcherFactory) DefaultThreadFactory(org.jboss.as.clustering.context.DefaultThreadFactory) JGroupsChannelConfigurator(org.infinispan.remoting.transport.jgroups.JGroupsChannelConfigurator) LocalCommandDispatcherFactory(org.wildfly.clustering.server.dispatcher.LocalCommandDispatcherFactory) ChannelCommandDispatcherFactory(org.wildfly.clustering.server.dispatcher.ChannelCommandDispatcherFactory) CommandDispatcherFactory(org.wildfly.clustering.spi.dispatcher.CommandDispatcherFactory) ListenerInvocation(org.infinispan.notifications.impl.ListenerInvocation) DefaultCacheManager(org.infinispan.manager.DefaultCacheManager) InfinispanSSOManagerFactoryConfiguration(org.wildfly.clustering.web.infinispan.sso.InfinispanSSOManagerFactoryConfiguration) ChannelCommandDispatcherFactory(org.wildfly.clustering.server.dispatcher.ChannelCommandDispatcherFactory) ImmutableSessionExpirationListener(org.wildfly.clustering.web.spring.ImmutableSessionExpirationListener) ChannelCommandDispatcherFactoryConfiguration(org.wildfly.clustering.server.dispatcher.ChannelCommandDispatcherFactoryConfiguration) Duration(java.time.Duration) KeyAffinityServiceFactory(org.wildfly.clustering.infinispan.spi.affinity.KeyAffinityServiceFactory) DefaultKeyAffinityServiceFactory(org.wildfly.clustering.infinispan.spi.affinity.DefaultKeyAffinityServiceFactory) NodeFactory(org.wildfly.clustering.spi.NodeFactory) DefaultNonBlockingThreadFactory(org.wildfly.clustering.infinispan.spi.DefaultNonBlockingThreadFactory) DefaultKeyAffinityServiceFactory(org.wildfly.clustering.infinispan.spi.affinity.DefaultKeyAffinityServiceFactory) Cache(org.infinispan.Cache) SSOManager(org.wildfly.clustering.web.sso.SSOManager) InfinispanProtoStreamMarshaller(org.wildfly.clustering.infinispan.spi.marshalling.InfinispanProtoStreamMarshaller) NonBlockingManager(org.infinispan.util.concurrent.NonBlockingManager) BlockingManager(org.infinispan.util.concurrent.BlockingManager) LocalGroup(org.wildfly.clustering.server.group.LocalGroup) TransportConfiguration(org.infinispan.configuration.global.TransportConfiguration) Properties(java.util.Properties) ServletContext(javax.servlet.ServletContext) EvictionStrategy(org.infinispan.eviction.EvictionStrategy) ExpirationConfiguration(org.infinispan.configuration.cache.ExpirationConfiguration) IndexingConfiguration(org.wildfly.clustering.web.spring.IndexingConfiguration) ByteBuffer(java.nio.ByteBuffer) FileNotFoundException(java.io.FileNotFoundException) LocalContextFactory(org.wildfly.clustering.web.LocalContextFactory) Recordable(org.wildfly.clustering.ee.Recordable) ObjectName(javax.management.ObjectName) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ConfigurationBuilderHolder(org.infinispan.configuration.parsing.ConfigurationBuilderHolder) CompositeImmutability(org.wildfly.clustering.ee.immutable.CompositeImmutability) CacheGroupConfiguration(org.wildfly.clustering.server.group.CacheGroupConfiguration) SpringSession(org.wildfly.clustering.web.spring.SpringSession) HttpSession(javax.servlet.http.HttpSession) ImmutableSession(org.wildfly.clustering.web.session.ImmutableSession) Session(org.springframework.session.Session)

Example 2 with MediaType

use of org.infinispan.commons.dataconversion.MediaType in project infinispan by infinispan.

the class Put method exec.

@Override
protected CompletionStage<RestResponse> exec(ContextAwareCommandInvocation invocation, RestClient client, org.infinispan.cli.resources.Resource resource) {
    if ((file != null) && (args.size() != 1)) {
        throw Messages.MSG.illegalCommandArguments();
    } else if ((file == null) && (args.size() != 2)) {
        throw Messages.MSG.illegalCommandArguments();
    }
    RestCacheClient cacheClient = client.cache(cache != null ? cache : CacheResource.cacheName(resource));
    MediaType putEncoding = encoding != null ? MediaType.fromString(encoding) : invocation.getContext().getEncoding();
    RestEntity value = file != null ? RestEntity.create(putEncoding, new File(file.getAbsolutePath())) : RestEntity.create(putEncoding, args.get(1));
    if (ifAbsent) {
        return cacheClient.post(args.get(0), value, ttl, maxIdle);
    } else {
        return cacheClient.put(args.get(0), value, ttl, maxIdle);
    }
}
Also used : RestEntity(org.infinispan.client.rest.RestEntity) RestCacheClient(org.infinispan.client.rest.RestCacheClient) MediaType(org.infinispan.commons.dataconversion.MediaType) File(java.io.File)

Example 3 with MediaType

use of org.infinispan.commons.dataconversion.MediaType in project infinispan by infinispan.

the class CoreConfigurationSerializer method writeEncoding.

private void writeEncoding(ConfigurationWriter writer, Configuration configuration) {
    MediaType keyDataType = configuration.encoding().keyDataType().mediaType();
    MediaType valueDataType = configuration.encoding().valueDataType().mediaType();
    if (keyDataType != null || valueDataType != null) {
        writer.writeStartElement(Element.ENCODING);
        if (keyDataType != null) {
            writer.writeStartElement(Element.KEY_DATA_TYPE);
            writer.writeAttribute(Attribute.MEDIA_TYPE, keyDataType.toString());
            writer.writeEndElement();
        }
        if (valueDataType != null) {
            writer.writeStartElement(Element.VALUE_DATA_TYPE);
            writer.writeAttribute(Attribute.MEDIA_TYPE, valueDataType.toString());
            writer.writeEndElement();
        }
        writer.writeEndElement();
    }
}
Also used : MediaType(org.infinispan.commons.dataconversion.MediaType)

Example 4 with MediaType

use of org.infinispan.commons.dataconversion.MediaType in project infinispan by infinispan.

the class CodecUtils method readCustomMediaType.

static MediaType readCustomMediaType(ByteBuf buffer) {
    byte[] customMediaTypeBytes = ByteBufUtil.readArray(buffer);
    String strCustomMediaType = new String(customMediaTypeBytes, CharsetUtil.UTF_8);
    MediaType customMediaType = MediaType.fromString(strCustomMediaType);
    return customMediaType.withParameters(readMediaTypeParams(buffer));
}
Also used : MediaType(org.infinispan.commons.dataconversion.MediaType)

Example 5 with MediaType

use of org.infinispan.commons.dataconversion.MediaType in project infinispan by infinispan.

the class EncoderCache method withMediaType.

@Override
public AdvancedCache<K, V> withMediaType(String keyMediaType, String valueMediaType) {
    MediaType kType = MediaType.fromString(keyMediaType);
    MediaType vType = MediaType.fromString(valueMediaType);
    return withMediaType(kType, vType);
}
Also used : MediaType(org.infinispan.commons.dataconversion.MediaType)

Aggregations

MediaType (org.infinispan.commons.dataconversion.MediaType)54 NettyRestResponse (org.infinispan.rest.NettyRestResponse)13 MediaTypeUtils.negotiateMediaType (org.infinispan.rest.resources.MediaTypeUtils.negotiateMediaType)12 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)9 Map (java.util.Map)8 EncoderRegistry (org.infinispan.marshall.core.EncoderRegistry)7 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)6 List (java.util.List)5 Function (java.util.function.Function)5 AdvancedCache (org.infinispan.AdvancedCache)5 Cache (org.infinispan.Cache)5 DataConversion (org.infinispan.encoding.DataConversion)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 CacheException (org.infinispan.commons.CacheException)4 Configuration (org.infinispan.configuration.cache.Configuration)4 IOException (java.io.IOException)3 Collections (java.util.Collections)3 Optional (java.util.Optional)3