Search in sources :

Example 1 with DefaultExecutorService

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);
                }
            }
        }
    });
}
Also used : Listener(org.wildfly.clustering.provider.ServiceProviderRegistration.Listener) Address(org.infinispan.remoting.transport.Address) DefaultExecutorService(org.jboss.as.clustering.context.DefaultExecutorService) Batch(org.wildfly.clustering.ee.Batch) DefaultExecutorService(org.jboss.as.clustering.context.DefaultExecutorService) ExecutorService(java.util.concurrent.ExecutorService) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) AbstractMap(java.util.AbstractMap)

Aggregations

AbstractMap (java.util.AbstractMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 ExecutorService (java.util.concurrent.ExecutorService)1 Address (org.infinispan.remoting.transport.Address)1 DefaultExecutorService (org.jboss.as.clustering.context.DefaultExecutorService)1 Batch (org.wildfly.clustering.ee.Batch)1 Listener (org.wildfly.clustering.provider.ServiceProviderRegistration.Listener)1