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));
}
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
}
}
}
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
}
}
}
Aggregations