Skip to content

Commit 020ea76

Browse files
artembilangaryrussell
authored andcommitted
Make IOS.setTaskScheduler() as public (#2725)
* Make IOS.setTaskScheduler() as public * Make `IntegrationObjectSupport.setTaskScheduler()` as `public` and remove all the overrides for visibility * Fix Sonar smells for all the affected classes * * Fix `throws Exception` for affected classes to avoid compilation errors * * Fix "merely rethrow" smell * Revert `throws Exception` for `AbstractEndpoint.destroy()` * * Catch a couple exceptions from `destroy()`
1 parent 7980afe commit 020ea76

File tree

10 files changed

+157
-150
lines changed

10 files changed

+157
-150
lines changed

spring-integration-core/src/main/java/org/springframework/integration/aggregator/AbstractCorrelatingMessageHandler.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,8 +28,6 @@
2828
import java.util.concurrent.locks.Lock;
2929

3030
import org.aopalliance.aop.Advice;
31-
import org.apache.commons.logging.Log;
32-
import org.apache.commons.logging.LogFactory;
3331

3432
import org.springframework.aop.framework.ProxyFactory;
3533
import org.springframework.beans.factory.BeanFactory;
@@ -57,7 +55,6 @@
5755
import org.springframework.messaging.Message;
5856
import org.springframework.messaging.MessageChannel;
5957
import org.springframework.messaging.MessageDeliveryException;
60-
import org.springframework.scheduling.TaskScheduler;
6158
import org.springframework.util.Assert;
6259
import org.springframework.util.CollectionUtils;
6360

@@ -96,8 +93,6 @@
9693
public abstract class AbstractCorrelatingMessageHandler extends AbstractMessageProducingHandler
9794
implements DiscardingMessageHandler, DisposableBean, ApplicationEventPublisherAware, Lifecycle {
9895

99-
protected final Log logger = LogFactory.getLog(getClass());
100-
10196
private final Comparator<Message<?>> sequenceNumberComparator = new MessageSequenceComparator();
10297

10398
private final Map<UUID, ScheduledFuture<?>> expireGroupScheduledFutures = new ConcurrentHashMap<>();
@@ -286,11 +281,6 @@ public void setPopSequence(boolean popSequence) {
286281
this.popSequence = popSequence;
287282
}
288283

289-
@Override
290-
public void setTaskScheduler(TaskScheduler taskScheduler) {
291-
super.setTaskScheduler(taskScheduler);
292-
}
293-
294284
protected boolean isReleaseLockBeforeSend() {
295285
return this.releaseLockBeforeSend;
296286
}
@@ -444,7 +434,7 @@ protected EvaluationContext getEvaluationContext() {
444434
}
445435

446436
@Override
447-
protected void handleMessageInternal(Message<?> message) throws Exception {
437+
protected void handleMessageInternal(Message<?> message) throws InterruptedException {
448438
Object correlationKey = this.correlationStrategy.getCorrelationKey(message);
449439
Assert.state(correlationKey != null,
450440
"Null correlation not allowed. Maybe the CorrelationStrategy is failing?");

spring-integration-core/src/main/java/org/springframework/integration/channel/DefaultHeaderChannelRegistry.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2018 the original author or authors.
2+
* Copyright 2013-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -30,7 +30,6 @@
3030
import org.springframework.integration.support.channel.HeaderChannelRegistry;
3131
import org.springframework.lang.Nullable;
3232
import org.springframework.messaging.MessageChannel;
33-
import org.springframework.scheduling.TaskScheduler;
3433
import org.springframework.util.Assert;
3534

3635
/**
@@ -53,11 +52,11 @@ public class DefaultHeaderChannelRegistry extends IntegrationObjectSupport
5352

5453
private static final int DEFAULT_REAPER_DELAY = 60000;
5554

56-
protected static final AtomicLong id = new AtomicLong();
55+
protected static final AtomicLong id = new AtomicLong(); // NOSONAR
5756

58-
protected final Map<String, MessageChannelWrapper> channels = new ConcurrentHashMap<>();
57+
protected final Map<String, MessageChannelWrapper> channels = new ConcurrentHashMap<>(); // NOSONAR
5958

60-
protected final String uuid = UUID.randomUUID().toString() + ":";
59+
protected final String uuid = UUID.randomUUID().toString() + ":"; // NOSONAR
6160

6261
private boolean removeOnGet;
6362

@@ -108,11 +107,6 @@ public void setRemoveOnGet(boolean removeOnGet) {
108107
this.removeOnGet = removeOnGet;
109108
}
110109

111-
@Override
112-
public void setTaskScheduler(TaskScheduler taskScheduler) {
113-
super.setTaskScheduler(taskScheduler);
114-
}
115-
116110
@Override
117111
public final int size() {
118112
return this.channels.size();
@@ -157,16 +151,18 @@ public boolean isRunning() {
157151
}
158152

159153
@Override
154+
@Nullable
160155
public Object channelToChannelName(@Nullable Object channel) {
161156
return channelToChannelName(channel, this.reaperDelay);
162157
}
163158

164159
@Override
160+
@Nullable
165161
public Object channelToChannelName(@Nullable Object channel, long timeToLive) {
166162
if (!this.running && !this.explicitlyStopped && this.getTaskScheduler() != null) {
167163
start();
168164
}
169-
if (channel != null && channel instanceof MessageChannel) {
165+
if (channel instanceof MessageChannel) {
170166
String name = this.uuid + id.incrementAndGet();
171167
this.channels.put(name, new MessageChannelWrapper((MessageChannel) channel,
172168
System.currentTimeMillis() + timeToLive));
@@ -181,6 +177,7 @@ public Object channelToChannelName(@Nullable Object channel, long timeToLive) {
181177
}
182178

183179
@Override
180+
@Nullable
184181
public MessageChannel channelNameToChannel(@Nullable String name) {
185182
if (name != null) {
186183
MessageChannelWrapper messageChannelWrapper;

spring-integration-core/src/main/java/org/springframework/integration/context/IntegrationObjectSupport.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,20 @@ protected BeanFactory getBeanFactory() {
205205
return this.beanFactory;
206206
}
207207

208+
/**
209+
* Configure a {@link TaskScheduler} for those components which logic relies
210+
* on the scheduled tasks.
211+
* If not provided, falls back to the global {@code taskScheduler} bean
212+
* in the application context, provided by the Spring Integration infrastructure.
213+
* @param taskScheduler the {@link TaskScheduler} to use.
214+
* @since 5.1.3
215+
* @see #getTaskScheduler()
216+
*/
217+
public void setTaskScheduler(TaskScheduler taskScheduler) {
218+
Assert.notNull(taskScheduler, "taskScheduler must not be null");
219+
this.taskScheduler = taskScheduler;
220+
}
221+
208222
protected TaskScheduler getTaskScheduler() {
209223
if (this.taskScheduler == null && this.beanFactory != null) {
210224
this.taskScheduler = IntegrationContextUtils.getTaskScheduler(this.beanFactory);
@@ -219,11 +233,6 @@ protected DestinationResolver<MessageChannel> getChannelResolver() {
219233
return this.channelResolver;
220234
}
221235

222-
protected void setTaskScheduler(TaskScheduler taskScheduler) {
223-
Assert.notNull(taskScheduler, "taskScheduler must not be null");
224-
this.taskScheduler = taskScheduler;
225-
}
226-
227236
public ConversionService getConversionService() {
228237
if (this.conversionService == null && this.beanFactory != null) {
229238
this.conversionService = IntegrationUtils.getConversionService(this.beanFactory);

spring-integration-core/src/main/java/org/springframework/integration/endpoint/AbstractEndpoint.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,7 +26,6 @@
2626
import org.springframework.integration.context.IntegrationObjectSupport;
2727
import org.springframework.integration.context.IntegrationProperties;
2828
import org.springframework.integration.support.SmartLifecycleRoleController;
29-
import org.springframework.scheduling.TaskScheduler;
3029
import org.springframework.util.PatternMatchUtils;
3130
import org.springframework.util.StringUtils;
3231

@@ -56,9 +55,9 @@ public abstract class AbstractEndpoint extends IntegrationObjectSupport
5655

5756
private volatile boolean running;
5857

59-
protected final ReentrantLock lifecycleLock = new ReentrantLock();
58+
protected final ReentrantLock lifecycleLock = new ReentrantLock(); // NOSONAR
6059

61-
protected final Condition lifecycleCondition = this.lifecycleLock.newCondition();
60+
protected final Condition lifecycleCondition = this.lifecycleLock.newCondition(); // NOSONAR
6261

6362
private String role;
6463

@@ -89,11 +88,6 @@ public String getRole() {
8988
return this.role;
9089
}
9190

92-
@Override
93-
public void setTaskScheduler(TaskScheduler taskScheduler) {
94-
super.setTaskScheduler(taskScheduler);
95-
}
96-
9791
@Override
9892
protected void onInit() {
9993
super.onInit();
@@ -125,7 +119,7 @@ protected void onInit() {
125119
}
126120

127121
@Override
128-
public void destroy() throws Exception {
122+
public void destroy() throws Exception { // NOSONAR TODO: remove throws in 5.2
129123
if (this.roleController != null) {
130124
this.roleController.removeLifecycle(this);
131125
}

spring-integration-core/src/main/java/org/springframework/integration/handler/DelayHandler.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import org.springframework.messaging.MessageHandler;
4949
import org.springframework.messaging.MessageHandlingException;
5050
import org.springframework.messaging.MessagingException;
51+
import org.springframework.messaging.core.DestinationResolver;
5152
import org.springframework.messaging.support.ErrorMessage;
5253
import org.springframework.scheduling.TaskScheduler;
5354
import org.springframework.util.Assert;
@@ -142,7 +143,7 @@ public DelayHandler(String messageGroupId) {
142143
*/
143144
public DelayHandler(String messageGroupId, TaskScheduler taskScheduler) {
144145
this(messageGroupId);
145-
this.setTaskScheduler(taskScheduler);
146+
setTaskScheduler(taskScheduler);
146147
}
147148

148149
/**
@@ -272,11 +273,9 @@ private MessageChannel getErrorChannel() {
272273
if (this.delayedMessageErrorChannel != null) {
273274
return this.delayedMessageErrorChannel;
274275
}
275-
if (this.delayedMessageErrorChannelName != null) {
276-
if (getChannelResolver() != null) {
277-
this.delayedMessageErrorChannel = getChannelResolver()
278-
.resolveDestination(this.delayedMessageErrorChannelName);
279-
}
276+
DestinationResolver<MessageChannel> channelResolver = getChannelResolver();
277+
if (this.delayedMessageErrorChannelName != null && channelResolver != null) {
278+
this.delayedMessageErrorChannel = channelResolver.resolveDestination(this.delayedMessageErrorChannelName);
280279
}
281280
return this.delayedMessageErrorChannel;
282281
}
@@ -516,11 +515,9 @@ private void doReleaseMessage(Message<?> message) {
516515
}
517516
handleMessageInternal(message);
518517
}
519-
else {
520-
if (logger.isDebugEnabled()) {
521-
logger.debug("No message in the Message Store to release: " + message +
522-
". Likely another instance has already released it.");
523-
}
518+
else if (logger.isDebugEnabled()) {
519+
logger.debug("No message in the Message Store to release: " + message +
520+
". Likely another instance has already released it.");
524521
}
525522
}
526523

spring-integration-file/src/main/java/org/springframework/integration/file/FileWritingMessageHandler.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -341,15 +341,6 @@ public void setFlushWhenIdle(boolean flushWhenIdle) {
341341
this.flushWhenIdle = flushWhenIdle;
342342
}
343343

344-
/**
345-
* Configure a {@link TaskScheduler} for flush operations.
346-
* @param taskScheduler the {@link TaskScheduler} to use.
347-
*/
348-
@Override
349-
public void setTaskScheduler(TaskScheduler taskScheduler) { // NOSONAR
350-
super.setTaskScheduler(taskScheduler);
351-
}
352-
353344
/**
354345
* Set a {@link MessageFlushPredicate} to use when flushing files when
355346
* {@link FileExistsMode#APPEND_NO_FLUSH} is being used.

0 commit comments

Comments
 (0)