AsyncTemplate: Fix Sonar Violation
Accessed `beanName` directly from a synchronized method. Also add `toString()`.
This commit is contained in:
@@ -233,7 +233,7 @@ public class AsyncRabbitTemplate implements SmartLifecycle, MessageListener, Ret
|
||||
}
|
||||
|
||||
public String getBeanName() {
|
||||
return beanName;
|
||||
return this.beanName;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -413,7 +413,7 @@ public class AsyncRabbitTemplate implements SmartLifecycle, MessageListener, Ret
|
||||
if (!this.running) {
|
||||
if (this.taskScheduler == null) {
|
||||
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
|
||||
scheduler.setThreadNamePrefix(this.beanName == null ? "asyncTemplate-" : (this.beanName + "-"));
|
||||
scheduler.setThreadNamePrefix(getBeanName() == null ? "asyncTemplate-" : (getBeanName() + "-"));
|
||||
scheduler.afterPropertiesSet();
|
||||
this.taskScheduler = scheduler;
|
||||
}
|
||||
@@ -537,6 +537,11 @@ public class AsyncRabbitTemplate implements SmartLifecycle, MessageListener, Ret
|
||||
return correlationId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.beanName == null ? super.toString() : (this.getClass().getSimpleName() + ": " + this.beanName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Base class for {@link ListenableFuture}s returned by {@link AsyncRabbitTemplate}.
|
||||
* @since 1.6
|
||||
|
||||
@@ -370,8 +370,7 @@ public class AsyncRabbitTemplateTests {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AsyncRabbitTemplate asyncTemplate(RabbitTemplate template,
|
||||
SimpleMessageListenerContainer container) {
|
||||
public AsyncRabbitTemplate asyncTemplate(RabbitTemplate template, SimpleMessageListenerContainer container) {
|
||||
return new AsyncRabbitTemplate(template, container);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user