AsyncTemplate: Fix Sonar Violation

Accessed `beanName` directly from a synchronized method.

Also add `toString()`.
This commit is contained in:
Gary Russell
2016-03-06 10:14:04 -05:00
parent 84cf11881b
commit 0498261e1c
2 changed files with 8 additions and 4 deletions

View File

@@ -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

View File

@@ -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);
}