@ -21,6 +21,7 @@ import java.util.Collection;
import java.util.HashMap ;
import java.util.HashMap ;
import java.util.List ;
import java.util.List ;
import java.util.Map ;
import java.util.Map ;
import java.util.concurrent.Executor ;
import java.util.function.Supplier ;
import java.util.function.Supplier ;
import org.springframework.beans.factory.BeanInitializationException ;
import org.springframework.beans.factory.BeanInitializationException ;
@ -30,7 +31,6 @@ import org.springframework.context.ApplicationContextAware;
import org.springframework.context.SmartLifecycle ;
import org.springframework.context.SmartLifecycle ;
import org.springframework.context.annotation.Bean ;
import org.springframework.context.annotation.Bean ;
import org.springframework.context.event.SmartApplicationListener ;
import org.springframework.context.event.SmartApplicationListener ;
import org.springframework.core.task.TaskExecutor ;
import org.springframework.lang.Nullable ;
import org.springframework.lang.Nullable ;
import org.springframework.messaging.MessageHandler ;
import org.springframework.messaging.MessageHandler ;
import org.springframework.messaging.converter.ByteArrayMessageConverter ;
import org.springframework.messaging.converter.ByteArrayMessageConverter ;
@ -158,7 +158,7 @@ public abstract class AbstractMessageBrokerConfiguration implements ApplicationC
@Bean
@Bean
public AbstractSubscribableChannel clientInboundChannel (
public AbstractSubscribableChannel clientInboundChannel (
@Qualifier ( "clientInboundChannelExecutor" ) Task Executor executor ) {
@Qualifier ( "clientInboundChannelExecutor" ) Executor executor ) {
ExecutorSubscribableChannel channel = new ExecutorSubscribableChannel ( executor ) ;
ExecutorSubscribableChannel channel = new ExecutorSubscribableChannel ( executor ) ;
channel . setLogger ( SimpLogging . forLog ( channel . getLogger ( ) ) ) ;
channel . setLogger ( SimpLogging . forLog ( channel . getLogger ( ) ) ) ;
@ -170,9 +170,9 @@ public abstract class AbstractMessageBrokerConfiguration implements ApplicationC
}
}
@Bean
@Bean
public Task Executor clientInboundChannelExecutor ( ) {
public Executor clientInboundChannelExecutor ( ) {
ChannelRegistration registration = getClientInboundChannelRegistration ( ) ;
ChannelRegistration registration = getClientInboundChannelRegistration ( ) ;
Task Executor executor = getTask Executor ( registration , "clientInboundChannel-" , this : : defaultTask Executor ) ;
Executor executor = getExecutor ( registration , "clientInboundChannel-" , this : : defaultExecutor ) ;
if ( executor instanceof ExecutorConfigurationSupport executorSupport ) {
if ( executor instanceof ExecutorConfigurationSupport executorSupport ) {
executorSupport . setPhase ( getPhase ( ) ) ;
executorSupport . setPhase ( getPhase ( ) ) ;
}
}
@ -209,7 +209,7 @@ public abstract class AbstractMessageBrokerConfiguration implements ApplicationC
@Bean
@Bean
public AbstractSubscribableChannel clientOutboundChannel (
public AbstractSubscribableChannel clientOutboundChannel (
@Qualifier ( "clientOutboundChannelExecutor" ) Task Executor executor ) {
@Qualifier ( "clientOutboundChannelExecutor" ) Executor executor ) {
ExecutorSubscribableChannel channel = new ExecutorSubscribableChannel ( executor ) ;
ExecutorSubscribableChannel channel = new ExecutorSubscribableChannel ( executor ) ;
channel . setLogger ( SimpLogging . forLog ( channel . getLogger ( ) ) ) ;
channel . setLogger ( SimpLogging . forLog ( channel . getLogger ( ) ) ) ;
@ -221,9 +221,9 @@ public abstract class AbstractMessageBrokerConfiguration implements ApplicationC
}
}
@Bean
@Bean
public Task Executor clientOutboundChannelExecutor ( ) {
public Executor clientOutboundChannelExecutor ( ) {
ChannelRegistration registration = getClientOutboundChannelRegistration ( ) ;
ChannelRegistration registration = getClientOutboundChannelRegistration ( ) ;
Task Executor executor = getTask Executor ( registration , "clientOutboundChannel-" , this : : defaultTask Executor ) ;
Executor executor = getExecutor ( registration , "clientOutboundChannel-" , this : : defaultExecutor ) ;
if ( executor instanceof ExecutorConfigurationSupport executorSupport ) {
if ( executor instanceof ExecutorConfigurationSupport executorSupport ) {
executorSupport . setPhase ( getPhase ( ) ) ;
executorSupport . setPhase ( getPhase ( ) ) ;
}
}
@ -250,11 +250,11 @@ public abstract class AbstractMessageBrokerConfiguration implements ApplicationC
@Bean
@Bean
public AbstractSubscribableChannel brokerChannel (
public AbstractSubscribableChannel brokerChannel (
AbstractSubscribableChannel clientInboundChannel , AbstractSubscribableChannel clientOutboundChannel ,
AbstractSubscribableChannel clientInboundChannel , AbstractSubscribableChannel clientOutboundChannel ,
@Qualifier ( "brokerChannelExecutor" ) Task Executor executor ) {
@Qualifier ( "brokerChannelExecutor" ) Executor executor ) {
MessageBrokerRegistry registry = getBrokerRegistry ( clientInboundChannel , clientOutboundChannel ) ;
MessageBrokerRegistry registry = getBrokerRegistry ( clientInboundChannel , clientOutboundChannel ) ;
ChannelRegistration registration = registry . getBrokerChannelRegistration ( ) ;
ChannelRegistration registration = registry . getBrokerChannelRegistration ( ) ;
ExecutorSubscribableChannel channel = ( registration . hasTask Executor ( ) ?
ExecutorSubscribableChannel channel = ( registration . hasExecutor ( ) ?
new ExecutorSubscribableChannel ( executor ) : new ExecutorSubscribableChannel ( ) ) ;
new ExecutorSubscribableChannel ( executor ) : new ExecutorSubscribableChannel ( ) ) ;
registration . interceptors ( new ImmutableMessageChannelInterceptor ( ) ) ;
registration . interceptors ( new ImmutableMessageChannelInterceptor ( ) ) ;
channel . setLogger ( SimpLogging . forLog ( channel . getLogger ( ) ) ) ;
channel . setLogger ( SimpLogging . forLog ( channel . getLogger ( ) ) ) ;
@ -263,18 +263,18 @@ public abstract class AbstractMessageBrokerConfiguration implements ApplicationC
}
}
@Bean
@Bean
public Task Executor brokerChannelExecutor (
public Executor brokerChannelExecutor (
AbstractSubscribableChannel clientInboundChannel , AbstractSubscribableChannel clientOutboundChannel ) {
AbstractSubscribableChannel clientInboundChannel , AbstractSubscribableChannel clientOutboundChannel ) {
MessageBrokerRegistry registry = getBrokerRegistry ( clientInboundChannel , clientOutboundChannel ) ;
MessageBrokerRegistry registry = getBrokerRegistry ( clientInboundChannel , clientOutboundChannel ) ;
ChannelRegistration registration = registry . getBrokerChannelRegistration ( ) ;
ChannelRegistration registration = registry . getBrokerChannelRegistration ( ) ;
Task Executor executor = getTask Executor ( registration , "brokerChannel-" , ( ) - > {
Executor executor = getExecutor ( registration , "brokerChannel-" , ( ) - > {
// Should never be used
// Should never be used
ThreadPoolTaskExecutor threadPoolTas kExecutor = new ThreadPoolTaskExecutor ( ) ;
ThreadPoolTaskExecutor fallbac kExecutor = new ThreadPoolTaskExecutor ( ) ;
threadPoolTas kExecutor. setCorePoolSize ( 0 ) ;
fallbac kExecutor. setCorePoolSize ( 0 ) ;
threadPoolTas kExecutor. setMaxPoolSize ( 1 ) ;
fallbac kExecutor. setMaxPoolSize ( 1 ) ;
threadPoolTas kExecutor. setQueueCapacity ( 0 ) ;
fallbac kExecutor. setQueueCapacity ( 0 ) ;
return threadPoolTas kExecutor;
return fallbac kExecutor;
} ) ;
} ) ;
if ( executor instanceof ExecutorConfigurationSupport executorSupport ) {
if ( executor instanceof ExecutorConfigurationSupport executorSupport ) {
executorSupport . setPhase ( getPhase ( ) ) ;
executorSupport . setPhase ( getPhase ( ) ) ;
@ -282,19 +282,19 @@ public abstract class AbstractMessageBrokerConfiguration implements ApplicationC
return executor ;
return executor ;
}
}
private Task Executor defaultTask Executor ( ) {
private Executor defaultExecutor ( ) {
return new TaskExecutorRegistration ( ) . getTaskExecutor ( ) ;
return new TaskExecutorRegistration ( ) . getTaskExecutor ( ) ;
}
}
private static Task Executor getTask Executor ( ChannelRegistration registration ,
private static Executor getExecutor ( ChannelRegistration registration ,
String threadNamePrefix , Supplier < Task Executor> fallback ) {
String threadNamePrefix , Supplier < Executor > fallback ) {
return registration . getTask Executor ( fallback ,
return registration . getExecutor ( fallback ,
executor - > setThreadNamePrefix ( executor , threadNamePrefix ) ) ;
executor - > setThreadNamePrefix ( executor , threadNamePrefix ) ) ;
}
}
private static void setThreadNamePrefix ( TaskExecutor taskE xecutor, String name ) {
private static void setThreadNamePrefix ( Executor e xecutor, String name ) {
if ( taskE xecutor instanceof CustomizableThreadCreator ctc ) {
if ( e xecutor instanceof CustomizableThreadCreator ctc ) {
ctc . setThreadNamePrefix ( name ) ;
ctc . setThreadNamePrefix ( name ) ;
}
}
}
}