Search in sources :

Example 1 with ConsistentHashLocality

use of org.wildfly.clustering.infinispan.spi.distribution.ConsistentHashLocality in project wildfly by wildfly.

the class InfinispanBeanManager method start.

@Override
public void start() {
    this.executor = Executors.newSingleThreadExecutor(createThreadFactory());
    this.affinity.start();
    Time timeout = this.expiration.getTimeout();
    Scheduler<I> noopScheduler = new Scheduler<I>() {

        @Override
        public void schedule(I id) {
        }

        @Override
        public void cancel(I id) {
        }

        @Override
        public void cancel(Locality locality) {
        }

        @Override
        public void close() {
        }
    };
    Scheduler<I> beanScheduler = (timeout != null) && (timeout.getValue() >= 0) ? new BeanExpirationScheduler<>(this.batcher, new ExpiredBeanRemover<>(this.beanFactory), this.expiration) : noopScheduler;
    Scheduler<I> groupScheduler = (this.passivation.getConfiguration().getMaxSize() >= 0) ? new BeanGroupEvictionScheduler<>(this.beanName + ".eviction", this.batcher, this.groupFactory, this.dispatcherFactory, this.passivation) : noopScheduler;
    this.schedulerContext = new SchedulerContext<I>() {

        @Override
        public void close() {
            groupScheduler.close();
            beanScheduler.close();
        }

        @Override
        public Scheduler<I> getBeanScheduler() {
            return beanScheduler;
        }

        @Override
        public Scheduler<I> getBeanGroupScheduler() {
            return groupScheduler;
        }
    };
    this.dispatcher = this.dispatcherFactory.createCommandDispatcher(this.beanName + ".schedulers", this.schedulerContext);
    this.cache.addListener(this, this.filter, null);
    this.schedule(new SimpleLocality(false), new ConsistentHashLocality(this.cache));
}
Also used : Locality(org.wildfly.clustering.infinispan.spi.distribution.Locality) SimpleLocality(org.wildfly.clustering.infinispan.spi.distribution.SimpleLocality) ConsistentHashLocality(org.wildfly.clustering.infinispan.spi.distribution.ConsistentHashLocality) Time(org.wildfly.clustering.ejb.Time) SimpleLocality(org.wildfly.clustering.infinispan.spi.distribution.SimpleLocality) ConsistentHashLocality(org.wildfly.clustering.infinispan.spi.distribution.ConsistentHashLocality)

Example 2 with ConsistentHashLocality

use of org.wildfly.clustering.infinispan.spi.distribution.ConsistentHashLocality 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 ConsistentHashLocality

use of org.wildfly.clustering.infinispan.spi.distribution.ConsistentHashLocality 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)

Aggregations

ConsistentHashLocality (org.wildfly.clustering.infinispan.spi.distribution.ConsistentHashLocality)3 Locality (org.wildfly.clustering.infinispan.spi.distribution.Locality)3 SimpleLocality (org.wildfly.clustering.infinispan.spi.distribution.SimpleLocality)3 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)2 DataRehashed (org.infinispan.notifications.cachelistener.annotation.DataRehashed)2 Address (org.infinispan.remoting.transport.Address)2 Time (org.wildfly.clustering.ejb.Time)1