Search in sources :

Example 6 with TransactionBatch

use of org.wildfly.clustering.ee.infinispan.TransactionBatch in project wildfly by wildfly.

the class InfinispanSessionManagerFactory method createSessionManager.

@Override
public <L> SessionManager<L, TransactionBatch> createSessionManager(final SessionManagerConfiguration<L> configuration) {
    final Batcher<TransactionBatch> batcher = new InfinispanBatcher(this.config.getCache());
    final Cache<Key<String>, ?> cache = this.config.getCache();
    final CacheProperties properties = new InfinispanCacheProperties(cache.getCacheConfiguration());
    final IdentifierFactory<String> factory = new AffinityIdentifierFactory<>(configuration.getIdentifierFactory(), cache, this.config.getKeyAffinityServiceFactory());
    final CommandDispatcherFactory dispatcherFactory = this.config.getCommandDispatcherFactory();
    final NodeFactory<Address> nodeFactory = this.config.getNodeFactory();
    final int maxActiveSessions = this.config.getSessionManagerFactoryConfiguration().getMaxActiveSessions();
    InfinispanSessionManagerConfiguration config = new InfinispanSessionManagerConfiguration() {

        @Override
        public SessionExpirationListener getExpirationListener() {
            return configuration.getExpirationListener();
        }

        @Override
        public ServletContext getServletContext() {
            return configuration.getServletContext();
        }

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

        @Override
        public CacheProperties getProperties() {
            return properties;
        }

        @Override
        public IdentifierFactory<String> getIdentifierFactory() {
            return factory;
        }

        @Override
        public Batcher<TransactionBatch> getBatcher() {
            return batcher;
        }

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

        @Override
        public NodeFactory<Address> getNodeFactory() {
            return nodeFactory;
        }

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

        @Override
        public Recordable<ImmutableSession> getInactiveSessionRecorder() {
            return configuration.getInactiveSessionRecorder();
        }
    };
    return new InfinispanSessionManager<>(this.createSessionFactory(properties, configuration.getLocalContextFactory()), config);
}
Also used : ImmutableSession(org.wildfly.clustering.web.session.ImmutableSession) Address(org.infinispan.remoting.transport.Address) TransactionBatch(org.wildfly.clustering.ee.infinispan.TransactionBatch) InfinispanBatcher(org.wildfly.clustering.ee.infinispan.InfinispanBatcher) InfinispanCacheProperties(org.wildfly.clustering.ee.infinispan.InfinispanCacheProperties) CacheProperties(org.wildfly.clustering.ee.infinispan.CacheProperties) AffinityIdentifierFactory(org.wildfly.clustering.web.infinispan.AffinityIdentifierFactory) CommandDispatcherFactory(org.wildfly.clustering.dispatcher.CommandDispatcherFactory) Key(org.wildfly.clustering.infinispan.spi.distribution.Key) InfinispanCacheProperties(org.wildfly.clustering.ee.infinispan.InfinispanCacheProperties)

Example 7 with TransactionBatch

use of org.wildfly.clustering.ee.infinispan.TransactionBatch in project wildfly by wildfly.

the class SessionEvictionSchedulerTestCase method test.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void test() throws Exception {
    String name = "cache";
    String evictedSessionId = "evicted";
    String activeSessionId = "active";
    ImmutableSessionMetaData evictedSessionMetaData = mock(ImmutableSessionMetaData.class);
    ImmutableSessionMetaData activeSessionMetaData = mock(ImmutableSessionMetaData.class);
    CommandDispatcherFactory dispatcherFactory = mock(CommandDispatcherFactory.class);
    CommandDispatcher<SessionEvictionContext> dispatcher = mock(CommandDispatcher.class);
    Evictor<String> evictor = mock(Evictor.class);
    Batcher<TransactionBatch> batcher = mock(Batcher.class);
    TransactionBatch batch = mock(TransactionBatch.class);
    ArgumentCaptor<Command> capturedCommand = ArgumentCaptor.forClass(Command.class);
    ArgumentCaptor<SessionEvictionContext> capturedContext = ArgumentCaptor.forClass(SessionEvictionContext.class);
    when(dispatcherFactory.createCommandDispatcher(same(name), capturedContext.capture())).thenReturn(dispatcher);
    try (Scheduler scheduler = new SessionEvictionScheduler(name, evictor, batcher, dispatcherFactory, 1)) {
        SessionEvictionContext context = capturedContext.getValue();
        assertSame(scheduler, context);
        scheduler.schedule(evictedSessionId, evictedSessionMetaData);
        verifyZeroInteractions(dispatcher);
        scheduler.schedule(activeSessionId, activeSessionMetaData);
        verify(dispatcher).submitOnCluster(capturedCommand.capture());
        when(batcher.createBatch()).thenReturn(batch);
        capturedCommand.getValue().execute(context);
        verify(evictor).evict(evictedSessionId);
        verify(batch).close();
        verify(evictor, never()).evict(activeSessionId);
    }
    verify(dispatcher).close();
}
Also used : TransactionBatch(org.wildfly.clustering.ee.infinispan.TransactionBatch) ImmutableSessionMetaData(org.wildfly.clustering.web.session.ImmutableSessionMetaData) Command(org.wildfly.clustering.dispatcher.Command) CommandDispatcherFactory(org.wildfly.clustering.dispatcher.CommandDispatcherFactory) Test(org.junit.Test)

Aggregations

TransactionBatch (org.wildfly.clustering.ee.infinispan.TransactionBatch)7 Test (org.junit.Test)5 CommandDispatcherFactory (org.wildfly.clustering.dispatcher.CommandDispatcherFactory)3 Configuration (org.infinispan.configuration.cache.Configuration)2 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)2 Command (org.wildfly.clustering.dispatcher.Command)2 CacheProperties (org.wildfly.clustering.ee.infinispan.CacheProperties)2 InfinispanBatcher (org.wildfly.clustering.ee.infinispan.InfinispanBatcher)2 InfinispanCacheProperties (org.wildfly.clustering.ee.infinispan.InfinispanCacheProperties)2 Key (org.wildfly.clustering.infinispan.spi.distribution.Key)2 AffinityIdentifierFactory (org.wildfly.clustering.web.infinispan.AffinityIdentifierFactory)2 Map (java.util.Map)1 Address (org.infinispan.remoting.transport.Address)1 Bean (org.wildfly.clustering.ejb.Bean)1 BeanPassivationConfiguration (org.wildfly.clustering.ejb.BeanPassivationConfiguration)1 CoarseSessionsFactory (org.wildfly.clustering.web.infinispan.sso.coarse.CoarseSessionsFactory)1 ImmutableSession (org.wildfly.clustering.web.session.ImmutableSession)1 ImmutableSessionMetaData (org.wildfly.clustering.web.session.ImmutableSessionMetaData)1