use of org.jboss.as.clustering.context.DefaultExecutorService in project wildfly by wildfly.
the class CacheServiceProviderRegistry method register.
@Override
public ServiceProviderRegistration<T> register(T service, Listener listener) {
Map.Entry<Listener, ExecutorService> newEntry = new AbstractMap.SimpleEntry<>(listener, null);
// Only create executor for new registrations
Map.Entry<Listener, ExecutorService> entry = this.listeners.computeIfAbsent(service, key -> {
if (listener != null) {
newEntry.setValue(new DefaultExecutorService(listener.getClass(), ExecutorServiceFactory.SINGLE_THREAD));
}
return newEntry;
});
if (entry != newEntry) {
throw new IllegalArgumentException(service.toString());
}
this.invoker.invoke(new RegisterLocalServiceTask(service));
return new SimpleServiceProviderRegistration<>(service, this, () -> {
Address localAddress = this.group.getAddress(this.group.getLocalMember());
try (Batch batch = this.batcher.createBatch()) {
this.cache.getAdvancedCache().withFlags(Flag.FORCE_SYNCHRONOUS, Flag.IGNORE_RETURN_VALUES).compute(service, this.properties.isTransactional() ? new CopyOnWriteAddressSetRemoveFunction(localAddress) : new ConcurrentAddressSetRemoveFunction(localAddress));
} finally {
Map.Entry<Listener, ExecutorService> oldEntry = this.listeners.remove(service);
if (oldEntry != null) {
ExecutorService executor = oldEntry.getValue();
if (executor != null) {
this.shutdown(executor);
}
}
}
});
}
Aggregations