use of org.wildfly.clustering.infinispan.spi.distribution.Locality 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.Locality 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.Locality in project wildfly by wildfly.
the class InfinispanSessionManager method start.
@Override
public void start() {
this.executor = Executors.newSingleThreadExecutor(createThreadFactory());
if (this.recorder != null) {
this.recorder.reset();
}
this.identifierFactory.start();
final List<Scheduler> schedulers = new ArrayList<>(2);
schedulers.add(new SessionExpirationScheduler(this.batcher, new ExpiredSessionRemover<>(this.factory, this.expirationListener)));
if (this.maxActiveSessions >= 0) {
schedulers.add(new SessionEvictionScheduler(this.cache.getName() + ".eviction", this.factory, this.batcher, this.dispatcherFactory, this.maxActiveSessions));
}
this.scheduler = new Scheduler() {
@Override
public void schedule(String sessionId, ImmutableSessionMetaData metaData) {
schedulers.forEach(scheduler -> scheduler.schedule(sessionId, metaData));
}
@Override
public void cancel(String sessionId) {
schedulers.forEach(scheduler -> scheduler.cancel(sessionId));
}
@Override
public void cancel(Locality locality) {
schedulers.forEach(scheduler -> scheduler.cancel(locality));
}
@Override
public void close() {
schedulers.forEach(scheduler -> scheduler.close());
}
};
this.dispatcher = this.dispatcherFactory.createCommandDispatcher(this.cache.getName() + ".schedulers", this.scheduler);
this.cache.addListener(this, this.filter);
this.schedule(new SimpleLocality(false), this.locality);
}
use of org.wildfly.clustering.infinispan.spi.distribution.Locality 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