Skip to content

Commit d73ded5

Browse files
committed
Some code style clean up
1 parent e00546d commit d73ded5

11 files changed

+58
-64
lines changed

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 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,7 +28,6 @@
2828
import org.springframework.context.ApplicationContext;
2929
import org.springframework.context.ApplicationContextAware;
3030
import org.springframework.core.convert.ConversionService;
31-
import org.springframework.core.convert.support.DefaultConversionService;
3231
import org.springframework.core.log.LogAccessor;
3332
import org.springframework.expression.Expression;
3433
import org.springframework.expression.ExpressionParser;
@@ -72,8 +71,6 @@ public abstract class IntegrationObjectSupport implements ComponentSourceAware,
7271

7372
protected final LogAccessor logger = new LogAccessor(getClass()); // NOSONAR protected
7473

75-
private final ConversionService defaultConversionService = DefaultConversionService.getSharedInstance();
76-
7774
private DestinationResolver<MessageChannel> channelResolver;
7875

7976
private String beanName;

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2025 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.
@@ -16,7 +16,6 @@
1616

1717
package org.springframework.integration.endpoint;
1818

19-
import java.util.concurrent.locks.Condition;
2019
import java.util.concurrent.locks.ReentrantLock;
2120

2221
import org.springframework.beans.factory.DisposableBean;
@@ -51,8 +50,6 @@ public abstract class AbstractEndpoint extends IntegrationObjectSupport
5150

5251
protected final ReentrantLock lifecycleLock = new ReentrantLock(); // NOSONAR
5352

54-
protected final Condition lifecycleCondition = this.lifecycleLock.newCondition(); // NOSONAR
55-
5653
private String role;
5754

5855
private SmartLifecycleRoleController roleController;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2021 the original author or authors.
2+
* Copyright 2016-2025 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.
@@ -48,7 +48,7 @@ protected Object doReceive() {
4848
}
4949

5050
/**
51-
* Subclasses must implement this method. Typically the returned value will be the
51+
* Subclasses must implement this method. Typically, the returned value will be the
5252
* payload of type T, but the returned value may also be a Message instance whose
5353
* payload is of type T.
5454
* @param maxFetchSizeToReceive the maximum number of messages to fetch if a fetch is

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2025 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.
@@ -156,11 +156,11 @@ protected Message<T> buildMessage(Object result) {
156156
}
157157
Message<?> message;
158158
Map<String, Object> headers = evaluateHeaders();
159-
if (result instanceof AbstractIntegrationMessageBuilder<?>) {
159+
if (result instanceof AbstractIntegrationMessageBuilder<?> messageBuilder) {
160160
if (!CollectionUtils.isEmpty(headers)) {
161-
((AbstractIntegrationMessageBuilder<?>) result).copyHeaders(headers);
161+
messageBuilder.copyHeaders(headers);
162162
}
163-
message = ((AbstractIntegrationMessageBuilder<?>) result).build();
163+
message = messageBuilder.build();
164164
}
165165
else if (result instanceof Message<?>) {
166166
message = (Message<?>) result;
@@ -216,7 +216,7 @@ private Map<String, Object> evaluateHeaders() {
216216
}
217217

218218
/**
219-
* Subclasses must implement this method. Typically the returned value will be the {@code payload} of
219+
* Subclasses must implement this method. Typically, the returned value will be the {@code payload} of
220220
* type T, but the returned value may also be a {@link Message} instance whose payload is of type T;
221221
* also can be {@link AbstractIntegrationMessageBuilder} which is used for additional headers population.
222222
* @return The value returned.

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.util.concurrent.ScheduledFuture;
2727
import java.util.concurrent.locks.Lock;
2828
import java.util.concurrent.locks.ReentrantLock;
29-
import java.util.stream.Collectors;
3029

3130
import org.aopalliance.aop.Advice;
3231
import org.reactivestreams.Subscription;
@@ -153,8 +152,8 @@ public void setAdviceChain(List<Advice> adviceChain) {
153152
/**
154153
* Configure a cap for messages to poll from the source per scheduling cycle.
155154
* A negative number means retrieve unlimited messages until the {@code MessageSource} returns {@code null}.
156-
* Zero means do not poll for any records - it
157-
* can be considered as pausing if 'maxMessagesPerPoll' is later changed to a non-zero value.
155+
* Zero means do not poll for any records -
156+
* it can be considered as pausing if 'maxMessagesPerPoll' is later changed to a non-zero value.
158157
* The polling cycle may exit earlier if the source returns null for the current receive call.
159158
* @param maxMessagesPerPoll the number of message to poll per schedule.
160159
*/
@@ -176,8 +175,8 @@ public void setBeanClassLoader(ClassLoader classLoader) {
176175
this.beanClassLoader = classLoader;
177176
}
178177

179-
public void setTransactionSynchronizationFactory(TransactionSynchronizationFactory
180-
transactionSynchronizationFactory) {
178+
public void setTransactionSynchronizationFactory(
179+
TransactionSynchronizationFactory transactionSynchronizationFactory) {
181180

182181
this.transactionSynchronizationFactory = transactionSynchronizationFactory;
183182
}
@@ -189,7 +188,9 @@ public void setTransactionSynchronizationFactory(TransactionSynchronizationFacto
189188
* @since 4.3
190189
*/
191190
public MessageChannel getDefaultErrorChannel() {
192-
if (!this.errorHandlerIsDefault && this.errorHandler instanceof MessagePublishingErrorHandler messagePublishingErrorHandler) {
191+
if (!this.errorHandlerIsDefault && this.errorHandler
192+
instanceof MessagePublishingErrorHandler messagePublishingErrorHandler) {
193+
193194
return messagePublishingErrorHandler.getDefaultErrorChannel();
194195
}
195196
else {
@@ -323,7 +324,7 @@ private Callable<Message<?>> createPollingTask() {
323324
if (!CollectionUtils.isEmpty(this.adviceChain)) {
324325
receiveOnlyAdviceChain = this.adviceChain.stream()
325326
.filter(this::isReceiveOnlyAdvice)
326-
.collect(Collectors.toList());
327+
.toList();
327328
}
328329

329330
Callable<Message<?>> task = this::doPoll;
@@ -423,15 +424,15 @@ private Message<?> pollForMessage() {
423424
}
424425
catch (Exception ex) {
425426
pollingTaskError = ex;
426-
if (ex instanceof MessagingException) { // NOSONAR
427-
throw (MessagingException) ex;
427+
if (ex instanceof MessagingException messagingException) { // NOSONAR
428+
throw messagingException;
428429
}
429430
else {
430431
Message<?> failedMessage = null;
431432
if (this.transactionSynchronizationFactory != null) {
432433
Object resource = TransactionSynchronizationManager.getResource(getResourceToBind());
433-
if (resource instanceof IntegrationResourceHolder) {
434-
failedMessage = ((IntegrationResourceHolder) resource).getMessage();
434+
if (resource instanceof IntegrationResourceHolder integrationResourceHolder) {
435+
failedMessage = integrationResourceHolder.getMessage();
435436
}
436437
}
437438
throw new MessagingException(failedMessage, ex); // NOSONAR (null failedMessage)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2025 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.
@@ -22,7 +22,7 @@
2222
import org.springframework.util.Assert;
2323

2424
/**
25-
* A {@link MessageProducerSupport} sub-class that provides {@linkplain #payloadExpression}
25+
* A {@link MessageProducerSupport} subclass that provides {@linkplain #payloadExpression}
2626
* evaluation with result as a payload for Message to send.
2727
*
2828
* @author David Turanski

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2019 the original author or authors.
2+
* Copyright 2016-2025 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.
@@ -37,7 +37,7 @@ public interface IntegrationConsumer extends NamedComponent {
3737
MessageChannel getInputChannel();
3838

3939
/**
40-
* Return the output channel (may be null).
40+
* Return the output channel (maybe null).
4141
* @return the output channel.
4242
*/
4343
MessageChannel getOutputChannel();

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 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.
@@ -93,15 +93,15 @@ protected void onInit() {
9393

9494
@Override
9595
public void start() {
96-
if (this.object instanceof Lifecycle) {
97-
((Lifecycle) this.object).start();
96+
if (this.object instanceof Lifecycle lifecycle) {
97+
lifecycle.start();
9898
}
9999
}
100100

101101
@Override
102102
public void stop() {
103-
if (this.object instanceof Lifecycle) {
104-
((Lifecycle) this.object).stop();
103+
if (this.object instanceof Lifecycle lifecycle) {
104+
lifecycle.stop();
105105
}
106106
}
107107

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 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.
@@ -74,8 +74,8 @@ public PollingConsumer(PollableChannel inputChannel, MessageHandler handler) {
7474
}
7575
this.inputChannel = inputChannel;
7676
this.handler = handler;
77-
if (this.inputChannel instanceof ExecutorChannelInterceptorAware) {
78-
this.channelInterceptors = ((ExecutorChannelInterceptorAware) this.inputChannel).getInterceptors();
77+
if (this.inputChannel instanceof ExecutorChannelInterceptorAware executorChannelInterceptorAware) {
78+
this.channelInterceptors = executorChannelInterceptorAware.getInterceptors();
7979
}
8080
else {
8181
this.channelInterceptors = null;
@@ -93,11 +93,11 @@ public MessageChannel getInputChannel() {
9393

9494
@Override
9595
public MessageChannel getOutputChannel() {
96-
if (this.handler instanceof MessageProducer) {
97-
return ((MessageProducer) this.handler).getOutputChannel();
96+
if (this.handler instanceof MessageProducer messageProducer) {
97+
return messageProducer.getOutputChannel();
9898
}
99-
else if (this.handler instanceof MessageRouter) {
100-
return ((MessageRouter) this.handler).getDefaultOutputChannel();
99+
else if (this.handler instanceof MessageRouter messageRouter) {
100+
return messageRouter.getDefaultOutputChannel();
101101
}
102102
else {
103103
return null;
@@ -127,16 +127,16 @@ protected boolean isReactive() {
127127

128128
@Override
129129
protected void doStart() {
130-
if (this.handler instanceof Lifecycle) {
131-
((Lifecycle) this.handler).start();
130+
if (this.handler instanceof Lifecycle lifecycle) {
131+
lifecycle.start();
132132
}
133133
super.doStart();
134134
}
135135

136136
@Override
137137
protected void doStop() {
138-
if (this.handler instanceof Lifecycle) {
139-
((Lifecycle) this.handler).stop();
138+
if (this.handler instanceof Lifecycle lifecycle) {
139+
lifecycle.stop();
140140
}
141141
super.doStop();
142142
}
@@ -180,8 +180,7 @@ protected void handleMessage(Message<?> message) {
180180
private Message<?> applyBeforeHandle(Message<?> message, Deque<ExecutorChannelInterceptor> interceptorStack) {
181181
Message<?> theMessage = message;
182182
for (ChannelInterceptor interceptor : this.channelInterceptors) {
183-
if (interceptor instanceof ExecutorChannelInterceptor) {
184-
ExecutorChannelInterceptor executorInterceptor = (ExecutorChannelInterceptor) interceptor;
183+
if (interceptor instanceof ExecutorChannelInterceptor executorInterceptor) {
185184
theMessage = executorInterceptor.beforeHandle(theMessage, this.inputChannel, this.handler);
186185
if (theMessage == null) {
187186
logger.debug(() -> executorInterceptor.getClass().getSimpleName()

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2024 the original author or authors.
2+
* Copyright 2016-2025 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.
@@ -100,11 +100,11 @@ public ReactiveStreamsConsumer(MessageChannel inputChannel, Subscriber<Message<?
100100
this.publisher = IntegrationReactiveUtils.messageChannelToFlux(inputChannel);
101101
this.subscriber = subscriber;
102102
this.lifecycleDelegate = subscriber instanceof Lifecycle ? (Lifecycle) subscriber : null;
103-
if (subscriber instanceof MessageHandlerSubscriber) {
104-
this.handler = ((MessageHandlerSubscriber) subscriber).messageHandler;
103+
if (subscriber instanceof MessageHandlerSubscriber messageHandlerSubscriber) {
104+
this.handler = messageHandlerSubscriber.messageHandler;
105105
}
106-
else if (subscriber instanceof MessageHandler) {
107-
this.handler = (MessageHandler) subscriber;
106+
else if (subscriber instanceof MessageHandler messageHandler) {
107+
this.handler = messageHandler;
108108
}
109109
else {
110110
this.handler = this.subscriber::onNext;
@@ -126,7 +126,7 @@ public ReactiveStreamsConsumer(MessageChannel inputChannel, ReactiveMessageHandl
126126
this.publisher = IntegrationReactiveUtils.messageChannelToFlux(inputChannel);
127127
this.subscriber = null;
128128
this.lifecycleDelegate =
129-
reactiveMessageHandler instanceof Lifecycle ? (Lifecycle) reactiveMessageHandler : null;
129+
reactiveMessageHandler instanceof Lifecycle lifecycle ? lifecycle : null;
130130
}
131131

132132
public void setErrorHandler(ErrorHandler errorHandler) {
@@ -146,11 +146,11 @@ public MessageChannel getInputChannel() {
146146

147147
@Override
148148
public MessageChannel getOutputChannel() {
149-
if (this.handler instanceof MessageProducer) {
150-
return ((MessageProducer) this.handler).getOutputChannel();
149+
if (this.handler instanceof MessageProducer messageProducer) {
150+
return messageProducer.getOutputChannel();
151151
}
152-
else if (this.handler instanceof MessageRouter) {
153-
return ((MessageRouter) this.handler).getDefaultOutputChannel();
152+
else if (this.handler instanceof MessageRouter messageRouter) {
153+
return messageRouter.getDefaultOutputChannel();
154154
}
155155
else {
156156
return null;
@@ -258,15 +258,15 @@ public boolean isDisposed() {
258258

259259
@Override
260260
public void start() {
261-
if (this.messageHandler instanceof Lifecycle) {
262-
((Lifecycle) this.messageHandler).start();
261+
if (this.messageHandler instanceof Lifecycle lifecycle) {
262+
lifecycle.start();
263263
}
264264
}
265265

266266
@Override
267267
public void stop() {
268-
if (this.messageHandler instanceof Lifecycle) {
269-
((Lifecycle) this.messageHandler).stop();
268+
if (this.messageHandler instanceof Lifecycle lifecycle) {
269+
lifecycle.stop();
270270
}
271271
}
272272

0 commit comments

Comments
 (0)