Skip to content

Commit 2edab39

Browse files
authored
The spring-integration-jms minor changes
1. add Javadoc for few classes. 2. use pattern matching for `instanceof` Signed-off-by: Jiandong Ma <[email protected]>
1 parent dab6cad commit 2edab39

14 files changed

+95
-93
lines changed

spring-integration-jms/src/main/java/org/springframework/integration/jms/AbstractJmsChannel.java

Lines changed: 7 additions & 1 deletion
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.
@@ -23,9 +23,15 @@
2323
import org.springframework.util.Assert;
2424

2525
/**
26+
* A base {@link AbstractMessageChannel} implementation for JMS-backed message channels.
27+
*
2628
* @author Mark Fisher
2729
* @author Gary Russell
30+
*
2831
* @since 2.0
32+
*
33+
* @see PollableJmsChannel
34+
* @see SubscribableJmsChannel
2935
*/
3036
public abstract class AbstractJmsChannel extends AbstractMessageChannel {
3137

spring-integration-jms/src/main/java/org/springframework/integration/jms/ChannelPublishingJmsMessageListener.java

Lines changed: 3 additions & 3 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.
@@ -406,8 +406,8 @@ public void onMessage(jakarta.jms.Message jmsMessage, Session session) throws JM
406406
headers.put(IntegrationMessageHeaderAccessor.DELIVERY_ATTEMPT, new AtomicInteger());
407407
}
408408
requestMessage =
409-
(result instanceof Message<?>) ?
410-
this.messageBuilderFactory.fromMessage((Message<?>) result).copyHeaders(headers).build() :
409+
result instanceof Message<?> message ?
410+
this.messageBuilderFactory.fromMessage(message).copyHeaders(headers).build() :
411411
this.messageBuilderFactory.withPayload(result).copyHeaders(headers).build();
412412
}
413413
catch (RuntimeException e) {

spring-integration-jms/src/main/java/org/springframework/integration/jms/DefaultJmsHeaderMapper.java

Lines changed: 7 additions & 7 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.
@@ -159,9 +159,9 @@ private void populateCorrelationIdPropertyFromHeaders(MessageHeaders headers, ja
159159
if (jmsCorrelationId instanceof Number) {
160160
jmsCorrelationId = jmsCorrelationId.toString();
161161
}
162-
if (jmsCorrelationId instanceof String) {
162+
if (jmsCorrelationId instanceof String jmsCorrelationIdStr) {
163163
try {
164-
jmsMessage.setJMSCorrelationID((String) jmsCorrelationId);
164+
jmsMessage.setJMSCorrelationID(jmsCorrelationIdStr);
165165
}
166166
catch (Exception ex) {
167167
LOGGER.info("Failed to set JMSCorrelationID, skipping", ex);
@@ -171,9 +171,9 @@ private void populateCorrelationIdPropertyFromHeaders(MessageHeaders headers, ja
171171

172172
private void populateReplyToPropertyFromHeaders(MessageHeaders headers, jakarta.jms.Message jmsMessage) {
173173
Object jmsReplyTo = headers.get(JmsHeaders.REPLY_TO);
174-
if (jmsReplyTo instanceof Destination) {
174+
if (jmsReplyTo instanceof Destination destination) {
175175
try {
176-
jmsMessage.setJMSReplyTo((Destination) jmsReplyTo);
176+
jmsMessage.setJMSReplyTo(destination);
177177
}
178178
catch (Exception ex) {
179179
LOGGER.info("Failed to set JMSReplyTo, skipping", ex);
@@ -183,9 +183,9 @@ private void populateReplyToPropertyFromHeaders(MessageHeaders headers, jakarta.
183183

184184
private void populateTypePropertyFromHeaders(MessageHeaders headers, jakarta.jms.Message jmsMessage) {
185185
Object jmsType = headers.get(JmsHeaders.TYPE);
186-
if (jmsType instanceof String) {
186+
if (jmsType instanceof String jmsTypeStr) {
187187
try {
188-
jmsMessage.setJMSType((String) jmsType);
188+
jmsMessage.setJMSType(jmsTypeStr);
189189
}
190190
catch (Exception ex) {
191191
LOGGER.info("Failed to set JMSType, skipping", ex);

spring-integration-jms/src/main/java/org/springframework/integration/jms/DynamicJmsTemplate.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 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.
@@ -24,6 +24,15 @@
2424
import org.springframework.util.Assert;
2525

2626
/**
27+
* A {@code JmsTemplate} implementation used by {@link JmsSendingMessageHandler} for
28+
* propagating QoS properties from the request message into the underlying {@code
29+
* producer.send(message, getDeliveryMode(), getPriority(), getTimeToLive())} API.
30+
* Propagation is only applied when {@code explicitQosEnabled} is true.
31+
* <p>
32+
* Starting with version 5.0.8, a default value of the receive-timeout is -1 (no wait)
33+
* for the {@link CachingConnectionFactory} and {@code cacheConsumers}, otherwise
34+
* it is 1 second.
35+
*
2736
* @author Mark Fisher
2837
* @author Artem Bilan
2938
*
@@ -45,8 +54,8 @@ public void setReceiveTimeout(long receiveTimeout) {
4554
public void setConnectionFactory(ConnectionFactory connectionFactory) {
4655
super.setConnectionFactory(connectionFactory);
4756
if (!this.receiveTimeoutExplicitlySet) {
48-
if (connectionFactory instanceof CachingConnectionFactory &&
49-
((CachingConnectionFactory) connectionFactory).isCacheConsumers()) {
57+
if (connectionFactory instanceof CachingConnectionFactory cachingConnectionFactory &&
58+
cachingConnectionFactory.isCacheConsumers()) {
5059
super.setReceiveTimeout(JmsDestinationAccessor.RECEIVE_TIMEOUT_NO_WAIT);
5160
}
5261
else {

spring-integration-jms/src/main/java/org/springframework/integration/jms/JmsDestinationPollingSource.java

Lines changed: 4 additions & 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.
@@ -137,8 +137,8 @@ protected Object doReceive() {
137137
}
138138
}
139139
AbstractIntegrationMessageBuilder<?> builder =
140-
(object instanceof Message)
141-
? getMessageBuilderFactory().fromMessage((Message<?>) object)
140+
(object instanceof Message<?> message)
141+
? getMessageBuilderFactory().fromMessage(message)
142142
: getMessageBuilderFactory().withPayload(object);
143143
return builder.copyHeadersIfAbsent(mappedHeaders);
144144
}
@@ -148,7 +148,7 @@ protected Object doReceive() {
148148
}
149149

150150
private jakarta.jms.Message doReceiveJmsMessage() {
151-
jakarta.jms.Message jmsMessage = null;
151+
jakarta.jms.Message jmsMessage;
152152
if (this.destination != null) {
153153
jmsMessage = this.jmsTemplate.receiveSelected(this.destination, this.messageSelector);
154154
}

spring-integration-jms/src/main/java/org/springframework/integration/jms/JmsInboundGateway.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2023 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.
@@ -109,7 +109,7 @@ public void setShouldTrack(boolean shouldTrack) {
109109
/**
110110
* Set to {@code false} to prevent listener container shutdown when the endpoint is stopped.
111111
* Then, if so configured, any cached consumer(s) in the container will remain.
112-
* Otherwise, the shared connection and will be closed and the listener invokers shut
112+
* Otherwise, the shared connection will be closed and the listener invokers shut
113113
* down; this behavior is new starting with version 5.1. Default: true.
114114
* @param shutdownContainerOnStop false to not shutdown.
115115
* @since 5.1

spring-integration-jms/src/main/java/org/springframework/integration/jms/JmsMessageDrivenEndpoint.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 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.
@@ -140,7 +140,7 @@ public void setShouldTrack(boolean shouldTrack) {
140140
/**
141141
* Set to {@code false} to prevent listener container shutdown when the endpoint is stopped.
142142
* Then, if so configured, any cached consumer(s) in the container will remain.
143-
* Otherwise, the shared connection and will be closed and the listener invokers shut
143+
* Otherwise, the shared connection will be closed and the listener invokers shut
144144
* down; this behavior is new starting with version 5.1. Default: true.
145145
* @param shutdownContainerOnStop false to not shutdown.
146146
* @since 5.1

spring-integration-jms/src/main/java/org/springframework/integration/jms/JmsOutboundGateway.java

Lines changed: 19 additions & 19 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.
@@ -467,11 +467,11 @@ private Destination determineRequestDestination(Message<?> message, Session sess
467467
}
468468
if (this.requestDestinationExpressionProcessor != null) {
469469
Object result = this.requestDestinationExpressionProcessor.processMessage(message);
470-
if (result instanceof Destination) {
471-
return (Destination) result;
470+
if (result instanceof Destination destination) {
471+
return destination;
472472
}
473-
if (result instanceof String) {
474-
return resolveRequestDestination((String) result, session);
473+
if (result instanceof String destinationName) {
474+
return resolveRequestDestination(destinationName, session);
475475
}
476476
throw new MessageDeliveryException(message,
477477
"Evaluation of requestDestinationExpression failed " +
@@ -496,11 +496,11 @@ private Destination determineReplyDestination(Message<?> message, Session sessio
496496
}
497497
if (this.replyDestinationExpressionProcessor != null) {
498498
Object result = this.replyDestinationExpressionProcessor.processMessage(message);
499-
if (result instanceof Destination) {
500-
return (Destination) result;
499+
if (result instanceof Destination destination) {
500+
return destination;
501501
}
502-
if (result instanceof String) {
503-
return resolveReplyDestination((String) result, session);
502+
if (result instanceof String destinationName) {
503+
return resolveReplyDestination(destinationName, session);
504504
}
505505
throw new MessageDeliveryException(message,
506506
"Evaluation of replyDestinationExpression failed to produce a Destination or destination name. " +
@@ -771,8 +771,8 @@ protected Object handleRequestMessage(final Message<?> requestMessage) {
771771
}
772772
}
773773

774-
if (reply instanceof jakarta.jms.Message) {
775-
return buildReply((jakarta.jms.Message) reply);
774+
if (reply instanceof jakarta.jms.Message jmsMessage) {
775+
return buildReply(jmsMessage);
776776
}
777777
else {
778778
return reply;
@@ -799,8 +799,8 @@ private AbstractIntegrationMessageBuilder<?> buildReply(jakarta.jms.Message jmsR
799799
// do not propagate back the gateway's internal correlation id
800800
jmsReplyHeaders.remove(this.correlationKey);
801801
}
802-
if (result instanceof Message) {
803-
return getMessageBuilderFactory().fromMessage((Message<?>) result).copyHeaders(jmsReplyHeaders);
802+
if (result instanceof Message<?> message) {
803+
return getMessageBuilderFactory().fromMessage(message).copyHeaders(jmsReplyHeaders);
804804
}
805805
else {
806806
return getMessageBuilderFactory().withPayload(result).copyHeaders(jmsReplyHeaders);
@@ -850,8 +850,8 @@ private Object sendAndReceiveWithContainer(Message<?> requestMessage) throws JMS
850850
* Remove the gateway's internal correlation Id to avoid conflicts with an upstream
851851
* gateway.
852852
*/
853-
if (reply instanceof jakarta.jms.Message) {
854-
((jakarta.jms.Message) reply).setJMSCorrelationID(null);
853+
if (reply instanceof jakarta.jms.Message jmsMessage) {
854+
jmsMessage.setJMSCorrelationID(null);
855855
}
856856
return reply;
857857
}
@@ -1239,11 +1239,11 @@ private jakarta.jms.Message receiveReplyMessage(MessageConsumer messageConsumer)
12391239
*/
12401240
private void deleteDestinationIfTemporary(Destination destination) {
12411241
try {
1242-
if (destination instanceof TemporaryQueue) {
1243-
((TemporaryQueue) destination).delete();
1242+
if (destination instanceof TemporaryQueue temporaryQueue) {
1243+
temporaryQueue.delete();
12441244
}
1245-
else if (destination instanceof TemporaryTopic) {
1246-
((TemporaryTopic) destination).delete();
1245+
else if (destination instanceof TemporaryTopic temporaryTopic) {
1246+
temporaryTopic.delete();
12471247
}
12481248
}
12491249
catch (@SuppressWarnings("unused") JMSException e) {

spring-integration-jms/src/main/java/org/springframework/integration/jms/JmsSendingMessageHandler.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.
@@ -212,11 +212,11 @@ private Object determineDestination(Message<?> message) {
212212
}
213213

214214
private void send(Object destination, Object objectToSend, MessagePostProcessor messagePostProcessor) {
215-
if (destination instanceof Destination) {
216-
this.jmsTemplate.convertAndSend((Destination) destination, objectToSend, messagePostProcessor);
215+
if (destination instanceof Destination destinationObj) {
216+
this.jmsTemplate.convertAndSend(destinationObj, objectToSend, messagePostProcessor);
217217
}
218-
else if (destination instanceof String) {
219-
this.jmsTemplate.convertAndSend((String) destination, objectToSend, messagePostProcessor);
218+
else if (destination instanceof String destinationStr) {
219+
this.jmsTemplate.convertAndSend(destinationStr, objectToSend, messagePostProcessor);
220220
}
221221
else { // fallback to default destination of the template
222222
this.jmsTemplate.convertAndSend(objectToSend, messagePostProcessor);

spring-integration-jms/src/main/java/org/springframework/integration/jms/PollableJmsChannel.java

Lines changed: 11 additions & 22 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.
@@ -31,6 +31,8 @@
3131
import org.springframework.messaging.support.ExecutorChannelInterceptor;
3232

3333
/**
34+
* A JMS-backed channel from which messages can be received through polling.
35+
*
3436
* @author Mark Fisher
3537
* @author Oleg Zhurakousky
3638
* @author Gary Russell
@@ -75,9 +77,7 @@ public Message<?> receive() {
7577
Deque<ChannelInterceptor> interceptorStack = null;
7678
boolean counted = false;
7779
try {
78-
if (isLoggingEnabled()) {
79-
logger.trace(() -> "preReceive on channel '" + this + "'");
80-
}
80+
logger.trace(() -> "preReceive on channel '" + this + "'");
8181
if (!interceptorList.getInterceptors().isEmpty()) {
8282
interceptorStack = new ArrayDeque<>();
8383

@@ -118,26 +118,15 @@ private Message<?> receiveAndConvertToMessage() {
118118
}
119119

120120
if (object == null) {
121-
if (isLoggingEnabled()) {
122-
logger.trace(() -> "postReceive on channel '" + this + "', message is null");
123-
}
121+
logger.trace(() -> "postReceive on channel '" + this + "', message is null");
124122
return null;
125123
}
126-
else {
127-
Message<?> message;
128-
if (object instanceof Message<?>) {
129-
message = (Message<?>) object;
130-
}
131-
else {
132-
message = getMessageBuilderFactory()
133-
.withPayload(object)
134-
.build();
135-
}
136-
if (isLoggingEnabled()) {
137-
logger.debug(() -> "postReceive on channel '" + this + "', message: " + message);
138-
}
139-
return message;
140-
}
124+
Message<?> message = object instanceof Message<?> msg
125+
? msg
126+
: getMessageBuilderFactory().withPayload(object).build();
127+
logger.debug(() -> "postReceive on channel '" + this + "', message: " + message);
128+
129+
return message;
141130
}
142131

143132
private void incrementReceiveCounter() {

spring-integration-jms/src/main/java/org/springframework/integration/jms/SubscribableJmsChannel.java

Lines changed: 3 additions & 3 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.
@@ -218,8 +218,8 @@ public void onMessage(jakarta.jms.Message message) {
218218
}
219219
if (converted != null) {
220220
messageToSend =
221-
converted instanceof Message<?>
222-
? (Message<?>) converted
221+
converted instanceof Message<?> convertedMessage
222+
? convertedMessage
223223
: this.messageBuilderFactory.withPayload(converted).build();
224224
this.dispatcher.dispatch(messageToSend);
225225
}

0 commit comments

Comments
 (0)