Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.springframework.integration.router.MethodInvokingRouter;
import org.springframework.integration.util.MessagingAnnotationUtils;
import org.springframework.messaging.MessageHandler;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

Expand Down Expand Up @@ -169,6 +170,7 @@ private void routerAttributes(List<Annotation> annotations, AbstractMessageRoute
}
Properties properties = (Properties) getConversionService().convert(mappings.toString(),
TypeDescriptor.valueOf(String.class), TypeDescriptor.valueOf(Properties.class));
Assert.state(properties != null, "The properties for channel mappings must not be null.");
methodInvokingRouter.replaceChannelMappings(properties);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import java.util.Properties;
import java.util.Set;

import org.jspecify.annotations.Nullable;

import org.springframework.core.convert.ConversionService;
import org.springframework.core.log.LogMessage;
import org.springframework.integration.support.management.MappingMessageRouterManagement;
Expand All @@ -50,6 +52,7 @@
* @author Artem Bilan
* @author Trung Pham
* @author Ngoc Nhan
* @author Glenn Renfro
*
* @since 2.1
*/
Expand All @@ -72,9 +75,9 @@ protected boolean removeEldestEntry(Entry<String, MessageChannel> eldest) {

});

private String prefix;
private @Nullable String prefix;

private String suffix;
private @Nullable String suffix;

private boolean resolutionRequired = true;

Expand Down Expand Up @@ -104,15 +107,15 @@ public void setChannelMappings(Map<String, String> channelMappings) {
* Specify a prefix to be added to each channel name prior to resolution.
* @param prefix The prefix.
*/
public void setPrefix(String prefix) {
public void setPrefix(@Nullable String prefix) {
this.prefix = prefix;
}

/**
* Specify a suffix to be added to each channel name prior to resolution.
* @param suffix The suffix.
*/
public void setSuffix(String suffix) {
public void setSuffix(@Nullable String suffix) {
this.suffix = suffix;
}

Expand Down Expand Up @@ -274,7 +277,7 @@ protected Collection<MessageChannel> determineTargetChannels(Message<?> message)
* @param message The message.
* @return The channel keys.
*/
protected abstract List<Object> getChannelKeys(Message<?> message);
protected abstract @Nullable List<Object> getChannelKeys(Message<?> message);

/**
* Convenience method allowing conversion of a list
Expand All @@ -289,7 +292,6 @@ protected Collection<MessageChannel> determineTargetChannels(Message<?> message)
@Override
@ManagedOperation
public void replaceChannelMappings(Properties channelMappings) {
Assert.notNull(channelMappings, "'channelMappings' must not be null");
Map<String, String> newChannelMappings = new LinkedHashMap<>();
Set<String> keys = channelMappings.stringPropertyNames();
for (String key : keys) {
Expand All @@ -304,7 +306,7 @@ private void doSetChannelMappings(Map<String, String> newChannelMappings) {
logger.debug(LogMessage.format("Channel mappings: %s replaced with: %s", oldChannelMappings, newChannelMappings));
}

private MessageChannel resolveChannelForName(String channelName, Message<?> message) {
private @Nullable MessageChannel resolveChannelForName(String channelName, Message<?> message) {
MessageChannel channel = null;
try {
channel = getChannelResolver().resolveDestination(channelName);
Expand Down Expand Up @@ -360,7 +362,7 @@ private void addChannel(Collection<MessageChannel> channels, Message<?> message,
}
}

private void addToCollection(Collection<MessageChannel> channels, Collection<?> channelKeys, Message<?> message) {
private void addToCollection(Collection<MessageChannel> channels, @Nullable Collection<?> channelKeys, Message<?> message) {
if (channelKeys == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

import org.jspecify.annotations.Nullable;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.support.DefaultConversionService;
Expand All @@ -47,6 +49,7 @@
* @author Stefan Ferstl
* @author Artem Bilan
* @author Christian Tzolov
* @author Glenn Renfro
*/
@ManagedResource
@IntegrationManagedResource
Expand All @@ -56,9 +59,9 @@ public abstract class AbstractMessageRouter extends AbstractMessageHandler imple

private final MessagingTemplate messagingTemplate = new MessagingTemplate();

private volatile MessageChannel defaultOutputChannel;
private volatile @Nullable MessageChannel defaultOutputChannel;

private volatile String defaultOutputChannelName;
private volatile @Nullable String defaultOutputChannelName;

private volatile boolean ignoreSendFailures;

Expand All @@ -85,7 +88,7 @@ public void setDefaultOutputChannel(MessageChannel defaultOutputChannel) {
* @since 4.3
*/
@Override
public MessageChannel getDefaultOutputChannel() {
public @Nullable MessageChannel getDefaultOutputChannel() {
if (this.defaultOutputChannelName != null) {
this.lock.lock();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.springframework.integration.router;

import org.jspecify.annotations.Nullable;

import org.springframework.messaging.MessageChannel;

/**
Expand All @@ -31,6 +33,7 @@ public interface MessageRouter {
* Get the default output channel.
* @return the channel.
*/
@Nullable
MessageChannel getDefaultOutputChannel();

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import java.util.LinkedList;
import java.util.List;

import org.jspecify.annotations.Nullable;

import org.springframework.messaging.Message;
import org.springframework.util.CollectionUtils;

Expand All @@ -31,6 +33,7 @@
* @author Oleg Zhurakousky
* @author Gary Russell
* @author Artem Bilan
* @author Glenn Renfro
*/
public class PayloadTypeRouter extends AbstractMappingMessageRouter {

Expand All @@ -46,7 +49,7 @@ public class PayloadTypeRouter extends AbstractMappingMessageRouter {
* preferring direct interface over indirect subclass
*/
@Override
protected List<Object> getChannelKeys(Message<?> message) {
protected @Nullable List<Object> getChannelKeys(Message<?> message) {
if (CollectionUtils.isEmpty(getChannelMappings())) {
return null;
}
Expand All @@ -59,7 +62,7 @@ protected List<Object> getChannelKeys(Message<?> message) {
return (closestMatch != null) ? Collections.singletonList(closestMatch) : null;
}

private String findClosestMatch(Class<?> type, boolean isArray) { // NOSONAR
private @Nullable String findClosestMatch(Class<?> type, boolean isArray) { // NOSONAR
int minTypeDiffWeight = Integer.MAX_VALUE;
List<String> matches = new LinkedList<>();
for (String candidate : getChannelMappings().keySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
* @author Artem Bilan
* @author Liujiong
* @author Gary Russell
* @author Glenn Renfro
*/
public class RecipientListRouter extends AbstractMessageRouter implements RecipientListRouterManagement {

Expand Down Expand Up @@ -151,11 +152,11 @@ public void addRecipient(String channelName) {
addRecipient(channelName, (MessageSelector) null);
}

public void addRecipient(String channelName, MessageSelector selector) {
public void addRecipient(String channelName, @Nullable MessageSelector selector) {
addRecipient(channelName, selector, this.recipients);
}

private void addRecipient(String channelName, MessageSelector selector, Queue<Recipient> recipientsToAdd) {
private void addRecipient(String channelName, @Nullable MessageSelector selector, Queue<Recipient> recipientsToAdd) {
Assert.hasText(channelName, "'channelName' must not be empty.");
Recipient recipient = new Recipient(channelName, selector);
setupRecipient(recipient);
Expand All @@ -166,7 +167,7 @@ public void addRecipient(MessageChannel channel) {
addRecipient(channel, null);
}

public void addRecipient(MessageChannel channel, MessageSelector selector) {
public void addRecipient(MessageChannel channel, @Nullable MessageSelector selector) {
Recipient recipient = new Recipient(channel, selector);
setupRecipient(recipient);
this.recipients.add(recipient);
Expand Down Expand Up @@ -273,19 +274,19 @@ protected void onInit() {

public static class Recipient {

private final MessageSelector selector;
private final @Nullable MessageSelector selector;

private MessageChannel channel;
private @Nullable MessageChannel channel;

private String channelName;
private @Nullable String channelName;

private DestinationResolver<MessageChannel> channelResolver;
private @Nullable DestinationResolver<MessageChannel> channelResolver;

public Recipient(MessageChannel channel) {
this(channel, null);
}

public Recipient(MessageChannel channel, MessageSelector selector) {
public Recipient(MessageChannel channel, @Nullable MessageSelector selector) {
this.channel = channel;
this.selector = selector;
}
Expand All @@ -294,7 +295,7 @@ public Recipient(String channelName) {
this(channelName, null);
}

public Recipient(String channelName, MessageSelector selector) {
public Recipient(String channelName, @Nullable MessageSelector selector) {
this.channelName = channelName;
this.selector = selector;
}
Expand All @@ -303,7 +304,7 @@ public void setChannelResolver(DestinationResolver<MessageChannel> channelResolv
this.channelResolver = channelResolver;
}

private MessageSelector getSelector() {
private @Nullable MessageSelector getSelector() {
return this.selector;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* Provides classes supporting the router pattern.
*/
@org.jspecify.annotations.NullMarked
package org.springframework.integration.router;