Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -20,6 +20,8 @@
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;

import org.jspecify.annotations.Nullable;

import org.springframework.integration.endpoint.AbstractMessageSource;
import org.springframework.jmx.support.ObjectNameManager;
import org.springframework.messaging.MessagingException;
Expand All @@ -35,11 +37,11 @@
*/
public class AttributePollingMessageSource extends AbstractMessageSource<Object> {

private volatile ObjectName objectName;
private volatile @Nullable ObjectName objectName;

private volatile String attributeName;
private volatile @Nullable String attributeName;

private volatile MBeanServerConnection server;
private volatile @Nullable MBeanServerConnection server;

/**
* Provide the MBeanServer where the JMX MBean has been registered.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;

import org.springframework.util.Assert;

Expand Down Expand Up @@ -61,7 +62,7 @@ public DefaultMBeanObjectConverter(MBeanAttributeFilter filter) {

@Override
public Object convert(MBeanServerConnection connection, ObjectInstance instance) {
Map<String, Object> attributeMap = new HashMap<>();
Map<String, @Nullable Object> attributeMap = new HashMap<>();

try {
ObjectName objName = instance.getObjectName();
Expand Down Expand Up @@ -109,7 +110,7 @@ public Object convert(MBeanServerConnection connection, ObjectInstance instance)
return attributeMap;
}

private Object checkAndConvert(Object input) {
private @Nullable Object checkAndConvert(@Nullable Object input) {
Object converted = null;
if (input instanceof CompositeData) {
converted = convertFromCompositeData((CompositeData) input);
Expand All @@ -129,9 +130,9 @@ else if (input != null && input.getClass().isArray()) {
}
}

private Object convertFromArray(Object input) {
private @Nullable Object convertFromArray(Object input) {
if (CompositeData.class.isAssignableFrom(input.getClass().getComponentType())) {
List<Object> converted = new ArrayList<>();
List<@Nullable Object> converted = new ArrayList<>();
int length = Array.getLength(input);
for (int i = 0; i < length; i++) {
Object value = checkAndConvert(Array.get(input, i));
Expand All @@ -146,15 +147,15 @@ private Object convertFromArray(Object input) {
return null;
}

private Object convertFromCompositeData(CompositeData data) {
private @Nullable Object convertFromCompositeData(CompositeData data) {
if (data.getCompositeType().isArray()) {
// TODO? I haven't found an example where this gets thrown - but need to test it on Tomcat/Jetty or
// something
LOGGER.warn("(data.getCompositeType().isArray for " + data.toString());
LOGGER.warn("(data.getCompositeType().isArray for " + data);
return null;
}
else {
Map<String, Object> returnable = new HashMap<>();
Map<String, @Nullable Object> returnable = new HashMap<>();
Set<String> keys = data.getCompositeType().keySet();
for (String key : keys) {
// we don't need to repeat name of this as an attribute
Expand All @@ -168,14 +169,14 @@ private Object convertFromCompositeData(CompositeData data) {
}
}

private Object convertFromTabularData(TabularData data) {
private @Nullable Object convertFromTabularData(TabularData data) {
if (data.getTabularType().isArray()) {
// TODO? I haven't found an example where this gets thrown, so might not be required
LOGGER.warn("TabularData.isArray for " + data.toString());
LOGGER.warn("TabularData.isArray for " + data);
return null;
}
else {
Map<Object, Object> returnable = new HashMap<>();
Map<Object, @Nullable Object> returnable = new HashMap<>();
@SuppressWarnings("unchecked")
Set<List<?>> keySet = (Set<List<?>>) data.keySet();
for (List<?> keys : keySet) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
import javax.management.Notification;
import javax.management.ObjectName;

import org.jspecify.annotations.Nullable;

import org.springframework.integration.mapping.OutboundMessageMapper;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.util.Assert;

Expand Down Expand Up @@ -64,7 +65,7 @@ public Notification fromMessage(Message<?> message) {
return notification;
}

private String resolveNotificationType(Message<?> message) {
private @Nullable String resolveNotificationType(Message<?> message) {
String type = message.getHeaders().get(JmxHeaders.NOTIFICATION_TYPE, String.class);
return (type != null) ? type : this.defaultNotificationType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import javax.management.ObjectName;
import javax.management.QueryExp;

import org.jspecify.annotations.Nullable;

import org.springframework.integration.endpoint.AbstractMessageSource;
import org.springframework.messaging.MessagingException;
import org.springframework.util.Assert;
Expand All @@ -42,9 +44,9 @@
*/
public class MBeanTreePollingMessageSource extends AbstractMessageSource<Object> {

private volatile MBeanServerConnection server;
private volatile @Nullable MBeanServerConnection server;

private volatile ObjectName queryName = null;
private volatile @Nullable ObjectName queryName = null;

private volatile QueryExp queryExpression = ObjectName.WILDCARD;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import javax.management.ObjectInstance;
import javax.management.ObjectName;

import org.jspecify.annotations.Nullable;

import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.integration.endpoint.MessageProducerSupport;
Expand All @@ -55,13 +57,13 @@ public class NotificationListeningMessageProducer extends MessageProducerSupport

private final AtomicBoolean listenerRegisteredOnStartup = new AtomicBoolean();

private MBeanServerConnection server;
private @Nullable MBeanServerConnection server;

private ObjectName[] mBeanObjectNames;
private @Nullable ObjectName @Nullable[] mBeanObjectNames;

private NotificationFilter filter;
private @Nullable NotificationFilter filter;

private Object handback;
private @Nullable Object handback;

/**
* Provide a reference to the MBeanServer where the notification
Expand Down Expand Up @@ -108,7 +110,7 @@ public void setHandback(Object handback) {
* sent to this producer's output channel.
*/
@Override
public void handleNotification(Notification notification, Object handback) {
public void handleNotification(Notification notification, @Nullable Object handback) {
this.logger.info(() -> "received notification: " + notification + ", and handback: " + handback);
AbstractIntegrationMessageBuilder<?> builder = getMessageBuilderFactory().withPayload(notification);
if (handback != null) {
Expand Down Expand Up @@ -148,7 +150,7 @@ protected void doStart() {
Assert.notNull(this.mBeanObjectNames, "An ObjectName is required.");
try {
Collection<ObjectName> objectNames = this.retrieveMBeanNames();
if (objectNames.size() < 1) {
if (objectNames.isEmpty()) {
this.logger.error(() -> "No MBeans found matching ObjectName pattern(s): " +
Arrays.toString(this.mBeanObjectNames));
}
Expand Down Expand Up @@ -195,15 +197,17 @@ protected void doStop() {
*/
protected Collection<ObjectName> retrieveMBeanNames() {
List<ObjectName> objectNames = new ArrayList<>();
for (ObjectName pattern : this.mBeanObjectNames) {
Assert.notNull(this.server, "MBeanServer is required.");
Assert.notNull(this.mBeanObjectNames, "An ObjectName is required.");
for (@Nullable ObjectName pattern : this.mBeanObjectNames) {
Set<ObjectInstance> mBeanInfos;
try {
mBeanInfos = this.server.queryMBeans(pattern, null);
}
catch (IOException e) {
throw new IllegalStateException("IOException on MBeanServerConnection.", e);
}
if (mBeanInfos.size() == 0) {
if (mBeanInfos.isEmpty()) {
this.logger.debug(() -> "No MBeans found matching pattern: " + pattern);
}
for (ObjectInstance instance : mBeanInfos) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@
package org.springframework.integration.jmx;

import java.util.Map;
import java.util.Objects;

import javax.management.MalformedObjectNameException;
import javax.management.Notification;
import javax.management.ObjectName;

import org.jspecify.annotations.Nullable;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.beans.factory.ListableBeanFactory;
Expand All @@ -34,7 +37,6 @@
import org.springframework.jmx.export.notification.NotificationPublisher;
import org.springframework.jmx.export.notification.NotificationPublisherAware;
import org.springframework.jmx.support.ObjectNameManager;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.util.Assert;

Expand All @@ -58,9 +60,9 @@ public class NotificationPublishingMessageHandler extends AbstractMessageHandler

private final ObjectName objectName;

private String defaultNotificationType;
private @Nullable String defaultNotificationType;

private OutboundMessageMapper<Notification> notificationMapper;
private @Nullable OutboundMessageMapper<Notification> notificationMapper;

/**
* Construct an instance based on the provided object name.
Expand Down Expand Up @@ -138,7 +140,8 @@ public final void onInit() {

@Override
protected void handleMessageInternal(Message<?> message) {
this.delegate.publish(this.notificationMapper.fromMessage(message));
Assert.state(this.notificationMapper != null, "'notificationMapper' must not be null");
this.delegate.publish(Objects.requireNonNull(this.notificationMapper.fromMessage(message)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this Objects.requireNonNull() yet.

}

/**
Expand All @@ -149,7 +152,7 @@ protected void handleMessageInternal(Message<?> message) {
@IntegrationManagedResource
public static class PublisherDelegate implements NotificationPublisherAware {

private NotificationPublisher notificationPublisher;
private @Nullable NotificationPublisher notificationPublisher;

@Override
public void setNotificationPublisher(NotificationPublisher notificationPublisher) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;

import org.jspecify.annotations.Nullable;

import org.springframework.integration.IntegrationPatternType;
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
import org.springframework.integration.util.ClassUtils;
Expand Down Expand Up @@ -69,9 +71,9 @@ public class OperationInvokingMessageHandler extends AbstractReplyProducingMessa

private final MBeanServerConnection server;

private ObjectName defaultObjectName;
private @Nullable ObjectName defaultObjectName;

private String operationName;
private @Nullable String operationName;

private boolean expectReply = true;

Expand All @@ -90,7 +92,7 @@ public OperationInvokingMessageHandler(MBeanServerConnection server) {
* available on the Message being handled.
* @param objectName The object name.
*/
public void setObjectName(String objectName) {
public void setObjectName(@Nullable String objectName) {
try {
if (objectName != null) {
this.defaultObjectName = ObjectNameManager.getInstance(objectName);
Expand Down Expand Up @@ -131,7 +133,7 @@ public IntegrationPatternType getIntegrationPatternType() {
}

@Override
protected Object handleRequestMessage(Message<?> requestMessage) {
protected @Nullable Object handleRequestMessage(Message<?> requestMessage) {
ObjectName objectName = resolveObjectName(requestMessage);
String operation = resolveOperationName(requestMessage);
Map<String, Object> paramsFromMessage = resolveParameters(requestMessage);
Expand All @@ -157,7 +159,7 @@ protected Object handleRequestMessage(Message<?> requestMessage) {
}
}

private Object invokeOperation(Message<?> requestMessage, ObjectName objectName, String operation,
private @Nullable Object invokeOperation(Message<?> requestMessage, ObjectName objectName, String operation,
Map<String, Object> paramsFromMessage) throws JMException, IOException {

MBeanInfo mbeanInfo = this.server.getMBeanInfo(objectName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

import javax.management.MBeanServer;

import org.jspecify.annotations.Nullable;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
Expand Down Expand Up @@ -63,22 +65,28 @@ public class IntegrationMBeanExportConfiguration implements ImportAware, Environ
*/
public static final String MBEAN_EXPORTER_NAME = "integrationMbeanExporter";

@SuppressWarnings("NullAway.Init")
private AnnotationAttributes attributes;

@SuppressWarnings("NullAway.Init")
private BeanFactory beanFactory;

private BeanExpressionResolver resolver = new StandardBeanExpressionResolver();

private BeanExpressionContext expressionContext;
private @Nullable BeanExpressionContext expressionContext;

@SuppressWarnings("NullAway.Init")
private Environment environment;

@Override
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
this.beanFactory = beanFactory;
if (beanFactory instanceof ConfigurableListableBeanFactory) {
this.resolver = ((ConfigurableListableBeanFactory) beanFactory).getBeanExpressionResolver();
this.expressionContext = new BeanExpressionContext((ConfigurableListableBeanFactory) beanFactory, null);
if (beanFactory instanceof ConfigurableListableBeanFactory configurableListableBeanFactory) {
var beanExpressionResolver = configurableListableBeanFactory.getBeanExpressionResolver();
if (beanExpressionResolver != null) {
this.resolver = beanExpressionResolver;
}
this.expressionContext = new BeanExpressionContext(configurableListableBeanFactory, null);
}
}

Expand All @@ -89,10 +97,12 @@ public void setEnvironment(Environment environment) {

@Override
public void setImportMetadata(AnnotationMetadata importMetadata) {
Map<String, Object> map = importMetadata.getAnnotationAttributes(EnableIntegrationMBeanExport.class.getName());
this.attributes = AnnotationAttributes.fromMap(map);
Assert.notNull(this.attributes, () ->
@Nullable Map<String, @Nullable Object> map = importMetadata.getAnnotationAttributes(
EnableIntegrationMBeanExport.class.getName());
AnnotationAttributes attributes = AnnotationAttributes.fromMap(map);
Assert.notNull(attributes, () ->
"@EnableIntegrationMBeanExport is not present on importing class " + importMetadata.getClassName());
this.attributes = attributes;
}

@Bean(name = MBEAN_EXPORTER_NAME)
Expand All @@ -108,22 +118,19 @@ public IntegrationMBeanExporter mbeanExporter() {

private void setupDomain(IntegrationMBeanExporter exporter) {
String defaultDomain = this.attributes.getString("defaultDomain");
if (this.environment != null) {
defaultDomain = this.environment.resolvePlaceholders(defaultDomain);
}
defaultDomain = this.environment.resolvePlaceholders(defaultDomain);
if (StringUtils.hasText(defaultDomain)) {
exporter.setDefaultDomain(defaultDomain);
}
}

private void setupServer(IntegrationMBeanExporter exporter) {
String server = this.attributes.getString("server");
if (this.environment != null) {
server = this.environment.resolvePlaceholders(server);
}
server = this.environment.resolvePlaceholders(server);
if (StringUtils.hasText(server)) {
MBeanServer bean;
if (server.startsWith("#{") && server.endsWith("}")) {
Assert.state(this.expressionContext != null, "'expressionContext' must not be null");
bean = (MBeanServer) this.resolver.evaluate(server, this.expressionContext);
}
else {
Expand Down
Loading