Search in sources :

Example 1 with CommandDispatcherFactory

use of org.wildfly.clustering.dispatcher.CommandDispatcherFactory in project wildfly by wildfly.

the class InfinispanBeanManagerFactory method createBeanManager.

@Override
public BeanManager<I, T, TransactionBatch> createBeanManager(IdentifierFactory<I> identifierFactory, PassivationListener<T> passivationListener, RemoveListener<T> removeListener) {
    MarshallingContext context = new SimpleMarshallingContextFactory().createMarshallingContext(this.configuration.getMarshallingConfigurationRepository(), this.configuration.getBeanContext().getClassLoader());
    MarshalledValueFactory<MarshallingContext> factory = new SimpleMarshalledValueFactory(context);
    Cache<BeanKey<I>, BeanEntry<I>> beanCache = this.configuration.getCache();
    Cache<BeanGroupKey<I>, BeanGroupEntry<I, T>> groupCache = this.configuration.getCache();
    final CacheProperties properties = new InfinispanCacheProperties(groupCache.getCacheConfiguration());
    final String beanName = this.configuration.getBeanContext().getBeanName();
    BeanGroupFactory<I, T> groupFactory = new InfinispanBeanGroupFactory<>(groupCache, beanCache, factory, context, properties);
    Configuration<BeanGroupKey<I>, BeanGroupEntry<I, T>, BeanGroupFactory<I, T>> groupConfiguration = new SimpleConfiguration<>(groupCache, groupFactory);
    BeanFactory<I, T> beanFactory = new InfinispanBeanFactory<>(beanName, groupFactory, beanCache, properties, this.configuration.getBeanContext().getTimeout(), properties.isPersistent() ? passivationListener : null);
    Configuration<BeanKey<I>, BeanEntry<I>, BeanFactory<I, T>> beanConfiguration = new SimpleConfiguration<>(beanCache, beanFactory);
    final NodeFactory<Address> nodeFactory = this.configuration.getNodeFactory();
    final Registry<String, ?> registry = this.configuration.getRegistry();
    final KeyAffinityServiceFactory affinityFactory = this.configuration.getKeyAffinityServiceFactory();
    final CommandDispatcherFactory dispatcherFactory = this.configuration.getCommandDispatcherFactory();
    final Time timeout = this.configuration.getBeanContext().getTimeout();
    final ScheduledExecutorService scheduler = this.configuration.getScheduler();
    final ExpirationConfiguration<T> expiration = new ExpirationConfiguration<T>() {

        @Override
        public Time getTimeout() {
            return timeout;
        }

        @Override
        public RemoveListener<T> getRemoveListener() {
            return removeListener;
        }

        @Override
        public ScheduledExecutorService getExecutor() {
            return scheduler;
        }
    };
    final Executor executor = this.configuration.getExecutor();
    final BeanPassivationConfiguration passivationConfig = this.configuration.getPassivationConfiguration();
    final PassivationConfiguration<T> passivation = new PassivationConfiguration<T>() {

        @Override
        public PassivationListener<T> getPassivationListener() {
            return passivationListener;
        }

        @Override
        public BeanPassivationConfiguration getConfiguration() {
            return passivationConfig;
        }

        @Override
        public Executor getExecutor() {
            return executor;
        }
    };
    InfinispanBeanManagerConfiguration<T> configuration = new InfinispanBeanManagerConfiguration<T>() {

        @Override
        public String getBeanName() {
            return beanName;
        }

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

        @Override
        public Registry<String, ?> getRegistry() {
            return registry;
        }

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

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

        @Override
        public ExpirationConfiguration<T> getExpirationConfiguration() {
            return expiration;
        }

        @Override
        public PassivationConfiguration<T> getPassivationConfiguration() {
            return passivation;
        }

        @Override
        public CacheProperties getProperties() {
            return properties;
        }
    };
    return new InfinispanBeanManager<>(configuration, identifierFactory, beanConfiguration, groupConfiguration);
}
Also used : InfinispanBeanGroupFactory(org.wildfly.clustering.ejb.infinispan.group.InfinispanBeanGroupFactory) Address(org.infinispan.remoting.transport.Address) Time(org.wildfly.clustering.ejb.Time) BeanPassivationConfiguration(org.wildfly.clustering.ejb.BeanPassivationConfiguration) InfinispanCacheProperties(org.wildfly.clustering.ee.infinispan.InfinispanCacheProperties) CacheProperties(org.wildfly.clustering.ee.infinispan.CacheProperties) Executor(java.util.concurrent.Executor) SimpleMarshallingContextFactory(org.wildfly.clustering.marshalling.jboss.SimpleMarshallingContextFactory) InfinispanBeanFactory(org.wildfly.clustering.ejb.infinispan.bean.InfinispanBeanFactory) CommandDispatcherFactory(org.wildfly.clustering.dispatcher.CommandDispatcherFactory) MarshallingContext(org.wildfly.clustering.marshalling.jboss.MarshallingContext) InfinispanBeanGroupFactory(org.wildfly.clustering.ejb.infinispan.group.InfinispanBeanGroupFactory) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) InfinispanBeanFactory(org.wildfly.clustering.ejb.infinispan.bean.InfinispanBeanFactory) BeanPassivationConfiguration(org.wildfly.clustering.ejb.BeanPassivationConfiguration) KeyAffinityServiceFactory(org.wildfly.clustering.infinispan.spi.affinity.KeyAffinityServiceFactory) SimpleMarshalledValueFactory(org.wildfly.clustering.marshalling.jboss.SimpleMarshalledValueFactory) InfinispanCacheProperties(org.wildfly.clustering.ee.infinispan.InfinispanCacheProperties)

Example 2 with CommandDispatcherFactory

use of org.wildfly.clustering.dispatcher.CommandDispatcherFactory in project wildfly by wildfly.

the class BeanEvictionSchedulerTestCase method test.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
@org.junit.Ignore
public void test() throws Exception {
    String name = "bean";
    String evictedBeanId = "evicted";
    String activeBeanId = "active";
    CommandDispatcherFactory dispatcherFactory = mock(CommandDispatcherFactory.class);
    CommandDispatcher<BeanGroupEvictionContext<String>> dispatcher = mock(CommandDispatcher.class);
    Batcher<TransactionBatch> batcher = mock(Batcher.class);
    TransactionBatch batch = mock(TransactionBatch.class);
    Evictor<String> evictor = mock(Evictor.class);
    PassivationConfiguration<Bean<String, Object>> config = mock(PassivationConfiguration.class);
    BeanPassivationConfiguration passivationConfig = mock(BeanPassivationConfiguration.class);
    ArgumentCaptor<Command> capturedCommand = ArgumentCaptor.forClass(Command.class);
    ArgumentCaptor<BeanGroupEvictionContext> capturedContext = ArgumentCaptor.forClass(BeanGroupEvictionContext.class);
    when(dispatcherFactory.createCommandDispatcher(same(name), (BeanGroupEvictionContext<String>) capturedContext.capture())).thenReturn(dispatcher);
    when(config.getConfiguration()).thenReturn(passivationConfig);
    when(passivationConfig.getMaxSize()).thenReturn(1);
    try (Scheduler<String> scheduler = new BeanGroupEvictionScheduler<>(name, batcher, evictor, dispatcherFactory, config)) {
        BeanGroupEvictionContext<String> context = capturedContext.getValue();
        assertSame(scheduler, context);
        scheduler.schedule(evictedBeanId);
        verifyZeroInteractions(dispatcher);
        scheduler.schedule(activeBeanId);
        verify(dispatcher).submitOnCluster(capturedCommand.capture());
        when(batcher.createBatch()).thenReturn(batch);
        capturedCommand.getValue().execute(context);
        verify(evictor).evict(evictedBeanId);
        verify(evictor, never()).evict(activeBeanId);
        verify(batch).close();
    }
    verify(dispatcher).close();
}
Also used : TransactionBatch(org.wildfly.clustering.ee.infinispan.TransactionBatch) BeanPassivationConfiguration(org.wildfly.clustering.ejb.BeanPassivationConfiguration) Bean(org.wildfly.clustering.ejb.Bean) Command(org.wildfly.clustering.dispatcher.Command) CommandDispatcherFactory(org.wildfly.clustering.dispatcher.CommandDispatcherFactory) Test(org.junit.Test)

Example 3 with CommandDispatcherFactory

use of org.wildfly.clustering.dispatcher.CommandDispatcherFactory 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 4 with CommandDispatcherFactory

use of org.wildfly.clustering.dispatcher.CommandDispatcherFactory 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

CommandDispatcherFactory (org.wildfly.clustering.dispatcher.CommandDispatcherFactory)4 TransactionBatch (org.wildfly.clustering.ee.infinispan.TransactionBatch)3 Address (org.infinispan.remoting.transport.Address)2 Test (org.junit.Test)2 Command (org.wildfly.clustering.dispatcher.Command)2 CacheProperties (org.wildfly.clustering.ee.infinispan.CacheProperties)2 InfinispanCacheProperties (org.wildfly.clustering.ee.infinispan.InfinispanCacheProperties)2 BeanPassivationConfiguration (org.wildfly.clustering.ejb.BeanPassivationConfiguration)2 Executor (java.util.concurrent.Executor)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 InfinispanBatcher (org.wildfly.clustering.ee.infinispan.InfinispanBatcher)1 Bean (org.wildfly.clustering.ejb.Bean)1 Time (org.wildfly.clustering.ejb.Time)1 InfinispanBeanFactory (org.wildfly.clustering.ejb.infinispan.bean.InfinispanBeanFactory)1 InfinispanBeanGroupFactory (org.wildfly.clustering.ejb.infinispan.group.InfinispanBeanGroupFactory)1 KeyAffinityServiceFactory (org.wildfly.clustering.infinispan.spi.affinity.KeyAffinityServiceFactory)1 Key (org.wildfly.clustering.infinispan.spi.distribution.Key)1 MarshallingContext (org.wildfly.clustering.marshalling.jboss.MarshallingContext)1 SimpleMarshalledValueFactory (org.wildfly.clustering.marshalling.jboss.SimpleMarshalledValueFactory)1 SimpleMarshallingContextFactory (org.wildfly.clustering.marshalling.jboss.SimpleMarshallingContextFactory)1