Skip to content

Commit

Permalink
Fix new Sonar smells
Browse files Browse the repository at this point in the history
  • Loading branch information
artembilan committed Apr 11, 2019
1 parent 7924c27 commit 2588869
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*
* @since 2.1.6
*/
@Order(Ordered.LOWEST_PRECEDENCE - 100)
@Order(Ordered.LOWEST_PRECEDENCE - 100) // NOSONAR magic
public class RabbitListenerTestSelector extends RabbitListenerConfigurationSelector {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,36 +348,36 @@ public void setContainerConfigurer(Consumer<C> configurer) {
public C createListenerContainer(RabbitListenerEndpoint endpoint) {
C instance = createContainerInstance();

JavaUtils javaUtils = JavaUtils.INSTANCE.acceptIfNotNull(this.connectionFactory, instance::setConnectionFactory)
.acceptIfNotNull(this.errorHandler, instance::setErrorHandler);
if (this.messageConverter != null) {
if (endpoint != null) {
endpoint.setMessageConverter(this.messageConverter);
}
JavaUtils javaUtils =
JavaUtils.INSTANCE
.acceptIfNotNull(this.connectionFactory, instance::setConnectionFactory)
.acceptIfNotNull(this.errorHandler, instance::setErrorHandler);
if (this.messageConverter != null && endpoint != null) {
endpoint.setMessageConverter(this.messageConverter);
}
javaUtils
.acceptIfNotNull(this.acknowledgeMode, instance::setAcknowledgeMode)
.acceptIfNotNull(this.channelTransacted, instance::setChannelTransacted)
.acceptIfNotNull(this.applicationContext, instance::setApplicationContext)
.acceptIfNotNull(this.taskExecutor, instance::setTaskExecutor)
.acceptIfNotNull(this.transactionManager, instance::setTransactionManager)
.acceptIfNotNull(this.prefetchCount, instance::setPrefetchCount)
.acceptIfNotNull(this.defaultRequeueRejected, instance::setDefaultRequeueRejected)
.acceptIfNotNull(this.adviceChain, instance::setAdviceChain)
.acceptIfNotNull(this.recoveryBackOff, instance::setRecoveryBackOff)
.acceptIfNotNull(this.mismatchedQueuesFatal, instance::setMismatchedQueuesFatal)
.acceptIfNotNull(this.missingQueuesFatal, instance::setMissingQueuesFatal)
.acceptIfNotNull(this.consumerTagStrategy, instance::setConsumerTagStrategy)
.acceptIfNotNull(this.idleEventInterval, instance::setIdleEventInterval)
.acceptIfNotNull(this.failedDeclarationRetryInterval, instance::setFailedDeclarationRetryInterval)
.acceptIfNotNull(this.applicationEventPublisher, instance::setApplicationEventPublisher)
.acceptIfNotNull(this.autoStartup, instance::setAutoStartup)
.acceptIfNotNull(this.phase, instance::setPhase)
.acceptIfNotNull(this.afterReceivePostProcessors, instance::setAfterReceivePostProcessors);
.acceptIfNotNull(this.acknowledgeMode, instance::setAcknowledgeMode)
.acceptIfNotNull(this.channelTransacted, instance::setChannelTransacted)
.acceptIfNotNull(this.applicationContext, instance::setApplicationContext)
.acceptIfNotNull(this.taskExecutor, instance::setTaskExecutor)
.acceptIfNotNull(this.transactionManager, instance::setTransactionManager)
.acceptIfNotNull(this.prefetchCount, instance::setPrefetchCount)
.acceptIfNotNull(this.defaultRequeueRejected, instance::setDefaultRequeueRejected)
.acceptIfNotNull(this.adviceChain, instance::setAdviceChain)
.acceptIfNotNull(this.recoveryBackOff, instance::setRecoveryBackOff)
.acceptIfNotNull(this.mismatchedQueuesFatal, instance::setMismatchedQueuesFatal)
.acceptIfNotNull(this.missingQueuesFatal, instance::setMissingQueuesFatal)
.acceptIfNotNull(this.consumerTagStrategy, instance::setConsumerTagStrategy)
.acceptIfNotNull(this.idleEventInterval, instance::setIdleEventInterval)
.acceptIfNotNull(this.failedDeclarationRetryInterval, instance::setFailedDeclarationRetryInterval)
.acceptIfNotNull(this.applicationEventPublisher, instance::setApplicationEventPublisher)
.acceptIfNotNull(this.autoStartup, instance::setAutoStartup)
.acceptIfNotNull(this.phase, instance::setPhase)
.acceptIfNotNull(this.afterReceivePostProcessors, instance::setAfterReceivePostProcessors);
if (endpoint != null) { // endpoint settings overriding default factory settings
javaUtils
.acceptIfNotNull(endpoint.getAutoStartup(), instance::setAutoStartup)
.acceptIfNotNull(endpoint.getTaskExecutor(), instance::setTaskExecutor);
.acceptIfNotNull(endpoint.getAutoStartup(), instance::setAutoStartup)
.acceptIfNotNull(endpoint.getTaskExecutor(), instance::setTaskExecutor);
instance.setListenerId(endpoint.getId());

endpoint.setupListenerContainer(instance);
Expand All @@ -386,10 +386,12 @@ public C createListenerContainer(RabbitListenerEndpoint endpoint) {
AbstractAdaptableMessageListener messageListener = (AbstractAdaptableMessageListener) instance
.getMessageListener();
javaUtils
.acceptIfNotNull(this.beforeSendReplyPostProcessors, messageListener::setBeforeSendReplyPostProcessors)
.acceptIfNotNull(this.retryTemplate, messageListener::setRetryTemplate)
.acceptIfCondition(this.retryTemplate != null && this.recoveryCallback != null, this.recoveryCallback,
messageListener::setRecoveryCallback);
.acceptIfNotNull(this.beforeSendReplyPostProcessors,
messageListener::setBeforeSendReplyPostProcessors)
.acceptIfNotNull(this.retryTemplate, messageListener::setRetryTemplate)
.acceptIfCondition(this.retryTemplate != null && this.recoveryCallback != null,
this.recoveryCallback,
messageListener::setRecoveryCallback);
}
initializeContainer(instance, endpoint);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.springframework.amqp.rabbit.support.MessagePropertiesConverter;
import org.springframework.amqp.support.ConditionalExceptionLogger;
import org.springframework.amqp.support.ConsumerTagStrategy;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.amqp.utils.JavaUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
Expand Down Expand Up @@ -88,8 +87,6 @@ public class ListenerContainerFactoryBean extends AbstractFactoryBean<AbstractMe

private ErrorHandler errorHandler;

private MessageConverter messageConverter;

private Boolean deBatchingEnabled;

private Advice[] adviceChain;
Expand Down Expand Up @@ -383,7 +380,8 @@ public void setRetryDeclarationInterval(long retryDeclarationInterval) {

@Override
public Class<?> getObjectType() {
return this.listenerContainer == null ? AbstractMessageListenerContainer.class : this.listenerContainer.getClass();
return this.listenerContainer == null ? AbstractMessageListenerContainer.class : this.listenerContainer
.getClass();
}

@SuppressWarnings("deprecation")
Expand All @@ -392,43 +390,45 @@ protected AbstractMessageListenerContainer createInstance() { // NOSONAR complex
if (this.listenerContainer == null) {
AbstractMessageListenerContainer container = createContainer();
JavaUtils.INSTANCE
.acceptIfNotNull(this.applicationContext, container::setApplicationContext)
.acceptIfNotNull(this.beanName, container::setBeanName)
.acceptIfNotNull(this.applicationEventPublisher, container::setApplicationEventPublisher)
.acceptIfNotNull(this.channelTransacted, container::setChannelTransacted)
.acceptIfNotNull(this.acknowledgeMode, container::setAcknowledgeMode)
.acceptIfNotNull(this.queueNames, container::setQueueNames)
.acceptIfNotNull(this.queues, container::setQueues)
.acceptIfNotNull(this.exposeListenerChannel, container::setExposeListenerChannel)
.acceptIfNotNull(this.messageListener, container::setMessageListener)
.acceptIfNotNull(this.errorHandler, container::setErrorHandler)
.acceptIfNotNull(this.deBatchingEnabled, container::setDeBatchingEnabled)
.acceptIfNotNull(this.adviceChain, container::setAdviceChain)
.acceptIfNotNull(this.afterReceivePostProcessors, container::setAfterReceivePostProcessors)
.acceptIfNotNull(this.autoStartup, container::setAutoStartup)
.acceptIfNotNull(this.phase, container::setPhase)
.acceptIfNotNull(this.listenerId, container::setListenerId)
.acceptIfNotNull(this.consumerTagStrategy, container::setConsumerTagStrategy)
.acceptIfNotNull(this.consumerArgs, container::setConsumerArguments)
.acceptIfNotNull(this.noLocal, container::setNoLocal)
.acceptIfNotNull(this.exclusive, container::setExclusive)
.acceptIfNotNull(this.defaultRequeueRejected, container::setDefaultRequeueRejected)
.acceptIfNotNull(this.prefetchCount, container::setPrefetchCount)
.acceptIfNotNull(this.shutdownTimeout, container::setShutdownTimeout)
.acceptIfNotNull(this.idleEventInterval, container::setIdleEventInterval)
.acceptIfNotNull(this.transactionManager, container::setTransactionManager)
.acceptIfNotNull(this.transactionAttribute, container::setTransactionAttribute)
.acceptIfNotNull(this.taskExecutor, container::setTaskExecutor)
.acceptIfNotNull(this.recoveryInterval, container::setRecoveryInterval)
.acceptIfNotNull(this.recoveryBackOff, container::setRecoveryBackOff)
.acceptIfNotNull(this.messagePropertiesConverter, container::setMessagePropertiesConverter)
.acceptIfNotNull(this.rabbitAdmin, container::setAmqpAdmin)
.acceptIfNotNull(this.missingQueuesFatal, container::setMissingQueuesFatal)
.acceptIfNotNull(this.possibleAuthenticationFailureFatal, container::setPossibleAuthenticationFailureFatal)
.acceptIfNotNull(this.mismatchedQueuesFatal, container::setMismatchedQueuesFatal)
.acceptIfNotNull(this.autoDeclare, container::setAutoDeclare)
.acceptIfNotNull(this.failedDeclarationRetryInterval, container::setFailedDeclarationRetryInterval)
.acceptIfNotNull(this.exclusiveConsumerExceptionLogger, container::setExclusiveConsumerExceptionLogger);
.acceptIfNotNull(this.applicationContext, container::setApplicationContext)
.acceptIfNotNull(this.beanName, container::setBeanName)
.acceptIfNotNull(this.applicationEventPublisher, container::setApplicationEventPublisher)
.acceptIfNotNull(this.channelTransacted, container::setChannelTransacted)
.acceptIfNotNull(this.acknowledgeMode, container::setAcknowledgeMode)
.acceptIfNotNull(this.queueNames, container::setQueueNames)
.acceptIfNotNull(this.queues, container::setQueues)
.acceptIfNotNull(this.exposeListenerChannel, container::setExposeListenerChannel)
.acceptIfNotNull(this.messageListener, container::setMessageListener)
.acceptIfNotNull(this.errorHandler, container::setErrorHandler)
.acceptIfNotNull(this.deBatchingEnabled, container::setDeBatchingEnabled)
.acceptIfNotNull(this.adviceChain, container::setAdviceChain)
.acceptIfNotNull(this.afterReceivePostProcessors, container::setAfterReceivePostProcessors)
.acceptIfNotNull(this.autoStartup, container::setAutoStartup)
.acceptIfNotNull(this.phase, container::setPhase)
.acceptIfNotNull(this.listenerId, container::setListenerId)
.acceptIfNotNull(this.consumerTagStrategy, container::setConsumerTagStrategy)
.acceptIfNotNull(this.consumerArgs, container::setConsumerArguments)
.acceptIfNotNull(this.noLocal, container::setNoLocal)
.acceptIfNotNull(this.exclusive, container::setExclusive)
.acceptIfNotNull(this.defaultRequeueRejected, container::setDefaultRequeueRejected)
.acceptIfNotNull(this.prefetchCount, container::setPrefetchCount)
.acceptIfNotNull(this.shutdownTimeout, container::setShutdownTimeout)
.acceptIfNotNull(this.idleEventInterval, container::setIdleEventInterval)
.acceptIfNotNull(this.transactionManager, container::setTransactionManager)
.acceptIfNotNull(this.transactionAttribute, container::setTransactionAttribute)
.acceptIfNotNull(this.taskExecutor, container::setTaskExecutor)
.acceptIfNotNull(this.recoveryInterval, container::setRecoveryInterval)
.acceptIfNotNull(this.recoveryBackOff, container::setRecoveryBackOff)
.acceptIfNotNull(this.messagePropertiesConverter, container::setMessagePropertiesConverter)
.acceptIfNotNull(this.rabbitAdmin, container::setAmqpAdmin)
.acceptIfNotNull(this.missingQueuesFatal, container::setMissingQueuesFatal)
.acceptIfNotNull(this.possibleAuthenticationFailureFatal,
container::setPossibleAuthenticationFailureFatal)
.acceptIfNotNull(this.mismatchedQueuesFatal, container::setMismatchedQueuesFatal)
.acceptIfNotNull(this.autoDeclare, container::setAutoDeclare)
.acceptIfNotNull(this.failedDeclarationRetryInterval, container::setFailedDeclarationRetryInterval)
.acceptIfNotNull(this.exclusiveConsumerExceptionLogger,
container::setExclusiveConsumerExceptionLogger);
container.afterPropertiesSet();
this.listenerContainer = container;
}
Expand All @@ -439,24 +439,24 @@ private AbstractMessageListenerContainer createContainer() {
if (this.type.equals(Type.simple)) {
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(this.connectionFactory);
JavaUtils.INSTANCE
.acceptIfNotNull(this.concurrentConsumers, container::setConcurrentConsumers)
.acceptIfNotNull(this.maxConcurrentConsumers, container::setMaxConcurrentConsumers)
.acceptIfNotNull(this.startConsumerMinInterval, container::setStartConsumerMinInterval)
.acceptIfNotNull(this.stopConsumerMinInterval, container::setStopConsumerMinInterval)
.acceptIfNotNull(this.consecutiveActiveTrigger, container::setConsecutiveActiveTrigger)
.acceptIfNotNull(this.consecutiveIdleTrigger, container::setConsecutiveIdleTrigger)
.acceptIfNotNull(this.receiveTimeout, container::setReceiveTimeout)
.acceptIfNotNull(this.txSize, container::setTxSize)
.acceptIfNotNull(this.declarationRetries, container::setDeclarationRetries)
.acceptIfNotNull(this.retryDeclarationInterval, container::setRetryDeclarationInterval);
.acceptIfNotNull(this.concurrentConsumers, container::setConcurrentConsumers)
.acceptIfNotNull(this.maxConcurrentConsumers, container::setMaxConcurrentConsumers)
.acceptIfNotNull(this.startConsumerMinInterval, container::setStartConsumerMinInterval)
.acceptIfNotNull(this.stopConsumerMinInterval, container::setStopConsumerMinInterval)
.acceptIfNotNull(this.consecutiveActiveTrigger, container::setConsecutiveActiveTrigger)
.acceptIfNotNull(this.consecutiveIdleTrigger, container::setConsecutiveIdleTrigger)
.acceptIfNotNull(this.receiveTimeout, container::setReceiveTimeout)
.acceptIfNotNull(this.txSize, container::setTxSize)
.acceptIfNotNull(this.declarationRetries, container::setDeclarationRetries)
.acceptIfNotNull(this.retryDeclarationInterval, container::setRetryDeclarationInterval);
return container;
}
else {
DirectMessageListenerContainer container = new DirectMessageListenerContainer(this.connectionFactory);
JavaUtils.INSTANCE
.acceptIfNotNull(this.consumersPerQueue, container::setConsumersPerQueue)
.acceptIfNotNull(this.taskScheduler, container::setTaskScheduler)
.acceptIfNotNull(this.monitorInterval, container::setMonitorInterval);
.acceptIfNotNull(this.consumersPerQueue, container::setConsumersPerQueue)
.acceptIfNotNull(this.taskScheduler, container::setTaskScheduler)
.acceptIfNotNull(this.monitorInterval, container::setMonitorInterval);
return container;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
import org.springframework.amqp.support.ConditionalExceptionLogger;
import org.springframework.amqp.support.ConsumerTagStrategy;
import org.springframework.amqp.support.converter.MessageConversionException;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.amqp.support.postprocessor.MessagePostProcessorUtils;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.support.DefaultPointcutAdvisor;
Expand Down Expand Up @@ -175,8 +174,6 @@ public abstract class AbstractMessageListenerContainer extends RabbitAccessor

private ErrorHandler errorHandler = new ConditionalRejectingErrorHandler();

private MessageConverter messageConverter;

private boolean exposeListenerChannel = true;

private volatile MessageListener messageListener;
Expand Down Expand Up @@ -625,8 +622,8 @@ public void setForceCloseChannel(boolean forceCloseChannel) {
protected String getRoutingLookupKey() {
return super.getConnectionFactory() instanceof RoutingConnectionFactory
? this.lookupKeyQualifier + "[" + this.queues.stream()
.map(Queue::getName)
.collect(Collectors.joining(",")) + "]"
.map(Queue::getName)
.collect(Collectors.joining(",")) + "]"
: null;
}

Expand Down Expand Up @@ -1057,11 +1054,13 @@ public final void afterPropertiesSet() {
Assert.state(
this.exposeListenerChannel || !getAcknowledgeMode().isManual(),
"You cannot acknowledge messages manually if the channel is not exposed to the listener "
+ "(please check your configuration and set exposeListenerChannel=true or acknowledgeMode!=MANUAL)");
+ "(please check your configuration and set exposeListenerChannel=true or " +
"acknowledgeMode!=MANUAL)");
Assert.state(
!(getAcknowledgeMode().isAutoAck() && isChannelTransacted()),
"The acknowledgeMode is NONE (autoack in Rabbit terms) which is not consistent with having a "
+ "transactional channel. Either use a different AcknowledgeMode or make sure channelTransacted=false");
+ "transactional channel. Either use a different AcknowledgeMode or make sure " +
"channelTransacted=false");
validateConfiguration();
initialize();
}
Expand Down Expand Up @@ -1821,6 +1820,7 @@ public static class SharedConnectionNotInitializedException extends RuntimeExcep
protected SharedConnectionNotInitializedException(String msg) {
super(msg);
}

}

/**
Expand Down

0 comments on commit 2588869

Please sign in to comment.