Search in sources :

Example 1 with Address

use of org.infinispan.remoting.transport.Address in project wildfly by wildfly.

the class DefaultCacheContainerTestCase method getCoordinator.

@Test
public void getCoordinator() {
    Address expected = mock(Address.class);
    when(this.manager.getCoordinator()).thenReturn(expected);
    Address result = this.subject.getCoordinator();
    assertSame(expected, result);
}
Also used : Address(org.infinispan.remoting.transport.Address) Test(org.junit.Test)

Example 2 with Address

use of org.infinispan.remoting.transport.Address in project wildfly by wildfly.

the class InfinispanBeanManager method dataRehashed.

@DataRehashed
public void dataRehashed(DataRehashedEvent<BeanKey<I>, BeanEntry<I>> event) {
    Address localAddress = this.cache.getCacheManager().getAddress();
    Locality newLocality = new ConsistentHashLocality(localAddress, event.getConsistentHashAtEnd());
    if (event.isPre()) {
        Future<?> future = this.rehashFuture.getAndSet(null);
        if (future != null) {
            future.cancel(true);
        }
        try {
            this.executor.submit(() -> {
                this.schedulerContext.getBeanScheduler().cancel(newLocality);
                this.schedulerContext.getBeanGroupScheduler().cancel(newLocality);
            });
        } catch (RejectedExecutionException e) {
        // Executor was shutdown
        }
    } else {
        Locality oldLocality = new ConsistentHashLocality(localAddress, event.getConsistentHashAtStart());
        try {
            this.rehashFuture.set(this.executor.submit(() -> this.schedule(oldLocality, newLocality)));
        } catch (RejectedExecutionException e) {
        // Executor was shutdown
        }
    }
}
Also used : Address(org.infinispan.remoting.transport.Address) Locality(org.wildfly.clustering.infinispan.spi.distribution.Locality) SimpleLocality(org.wildfly.clustering.infinispan.spi.distribution.SimpleLocality) ConsistentHashLocality(org.wildfly.clustering.infinispan.spi.distribution.ConsistentHashLocality) ConsistentHashLocality(org.wildfly.clustering.infinispan.spi.distribution.ConsistentHashLocality) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) DataRehashed(org.infinispan.notifications.cachelistener.annotation.DataRehashed)

Example 3 with Address

use of org.infinispan.remoting.transport.Address 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 4 with Address

use of org.infinispan.remoting.transport.Address in project wildfly by wildfly.

the class InfinispanSessionManager method dataRehashed.

@DataRehashed
public void dataRehashed(DataRehashedEvent<SessionCreationMetaDataKey, ?> event) {
    Cache<SessionCreationMetaDataKey, ?> cache = event.getCache();
    Address localAddress = cache.getCacheManager().getAddress();
    Locality newLocality = new ConsistentHashLocality(localAddress, event.getConsistentHashAtEnd());
    if (event.isPre()) {
        Future<?> future = this.rehashFuture.getAndSet(null);
        if (future != null) {
            future.cancel(true);
        }
        try {
            this.executor.submit(() -> this.scheduler.cancel(newLocality));
        } catch (RejectedExecutionException e) {
        // Executor was shutdown
        }
    } else {
        Locality oldLocality = new ConsistentHashLocality(localAddress, event.getConsistentHashAtStart());
        try {
            this.rehashFuture.set(this.executor.submit(() -> this.schedule(oldLocality, newLocality)));
        } catch (RejectedExecutionException e) {
        // Executor was shutdown
        }
    }
}
Also used : Address(org.infinispan.remoting.transport.Address) Locality(org.wildfly.clustering.infinispan.spi.distribution.Locality) SimpleLocality(org.wildfly.clustering.infinispan.spi.distribution.SimpleLocality) ConsistentHashLocality(org.wildfly.clustering.infinispan.spi.distribution.ConsistentHashLocality) ConsistentHashLocality(org.wildfly.clustering.infinispan.spi.distribution.ConsistentHashLocality) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) DataRehashed(org.infinispan.notifications.cachelistener.annotation.DataRehashed)

Example 5 with Address

use of org.infinispan.remoting.transport.Address in project wildfly by wildfly.

the class InfinispanSessionManager method locatePrimaryOwner.

private Node locatePrimaryOwner(String sessionId) {
    DistributionManager dist = this.cache.getAdvancedCache().getDistributionManager();
    Address address = (dist != null) ? dist.getPrimaryLocation(new Key<>(sessionId)) : null;
    return (address != null) ? this.nodeFactory.createNode(address) : this.dispatcherFactory.getGroup().getLocalNode();
}
Also used : Address(org.infinispan.remoting.transport.Address) DistributionManager(org.infinispan.distribution.DistributionManager) Key(org.wildfly.clustering.infinispan.spi.distribution.Key)

Aggregations

Address (org.infinispan.remoting.transport.Address)15 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)3 Test (org.junit.Test)3 Map (java.util.Map)2 EndInvalidationCommand (org.hibernate.cache.infinispan.util.EndInvalidationCommand)2 DistributionManager (org.infinispan.distribution.DistributionManager)2 ConsistentHash (org.infinispan.distribution.ch.ConsistentHash)2 DataRehashed (org.infinispan.notifications.cachelistener.annotation.DataRehashed)2 CommandDispatcherFactory (org.wildfly.clustering.dispatcher.CommandDispatcherFactory)2 Node (org.wildfly.clustering.group.Node)2 ConsistentHashLocality (org.wildfly.clustering.infinispan.spi.distribution.ConsistentHashLocality)2 Locality (org.wildfly.clustering.infinispan.spi.distribution.Locality)2 SimpleLocality (org.wildfly.clustering.infinispan.spi.distribution.SimpleLocality)2 PrivilegedAction (java.security.PrivilegedAction)1 AbstractMap (java.util.AbstractMap)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1