Introduce null-safety of Spring Framework API
This commit introduces 2 new @Nullable and @NonNullApi annotations that leverage JSR 305 (dormant but available via Findbugs jsr305 dependency and already used by libraries like OkHttp) meta-annotations to specify explicitly null-safety of Spring Framework parameters and return values. In order to avoid adding too much annotations, the default is set at package level with @NonNullApi and @Nullable annotations are added when needed at parameter or return value level. These annotations are intended to be used on Spring Framework itself but also by other Spring projects. @Nullable annotations have been introduced based on Javadoc and search of patterns like "return null;". It is expected that nullability of Spring Framework API will be polished with complementary commits. In practice, this will make the whole Spring Framework API null-safe for Kotlin projects (when KT-10942 will be fixed) since Kotlin will be able to leverage these annotations to know if a parameter or a return value is nullable or not. But this is also useful for Java developers as well since IntelliJ IDEA, for example, also understands these annotations to generate warnings when unsafe nullable usages are detected. Issue: SPR-15540
This commit is contained in:
@@ -19,6 +19,7 @@ package org.springframework.jms;
|
||||
import javax.jms.JMSException;
|
||||
|
||||
import org.springframework.core.NestedRuntimeException;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Base class for exception thrown by the framework whenever it
|
||||
@@ -67,6 +68,7 @@ public abstract class JmsException extends NestedRuntimeException {
|
||||
* @return a string specifying the vendor-specific error code if the
|
||||
* root cause is an instance of JMSException, or {@code null}
|
||||
*/
|
||||
@Nullable
|
||||
public String getErrorCode() {
|
||||
Throwable cause = getCause();
|
||||
if (cause instanceof JMSException) {
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
/**
|
||||
* Annotations and support classes for declarative JMS listener endpoints.
|
||||
*/
|
||||
@NonNullApi
|
||||
package org.springframework.jms.annotation;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.springframework.jms.listener.AbstractMessageListenerContainer;
|
||||
import org.springframework.jms.listener.MessageListenerContainer;
|
||||
import org.springframework.jms.listener.endpoint.JmsActivationSpecConfig;
|
||||
import org.springframework.jms.listener.endpoint.JmsMessageEndpointManager;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Base model for a JMS listener endpoint
|
||||
@@ -64,6 +65,7 @@ public abstract class AbstractJmsListenerEndpoint implements JmsListenerEndpoint
|
||||
/**
|
||||
* Return the name of the destination for this endpoint.
|
||||
*/
|
||||
@Nullable
|
||||
public String getDestination() {
|
||||
return this.destination;
|
||||
}
|
||||
@@ -78,6 +80,7 @@ public abstract class AbstractJmsListenerEndpoint implements JmsListenerEndpoint
|
||||
/**
|
||||
* Return the name for the durable subscription, if any.
|
||||
*/
|
||||
@Nullable
|
||||
public String getSubscription() {
|
||||
return this.subscription;
|
||||
}
|
||||
@@ -93,6 +96,7 @@ public abstract class AbstractJmsListenerEndpoint implements JmsListenerEndpoint
|
||||
/**
|
||||
* Return the JMS message selector expression, if any.
|
||||
*/
|
||||
@Nullable
|
||||
public String getSelector() {
|
||||
return this.selector;
|
||||
}
|
||||
@@ -111,6 +115,7 @@ public abstract class AbstractJmsListenerEndpoint implements JmsListenerEndpoint
|
||||
/**
|
||||
* Return the concurrency for the listener, if any.
|
||||
*/
|
||||
@Nullable
|
||||
public String getConcurrency() {
|
||||
return this.concurrency;
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import org.springframework.beans.factory.parsing.CompositeComponentDefinition;
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.beans.factory.xml.BeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -313,6 +314,7 @@ abstract class AbstractListenerContainerParser implements BeanDefinitionParser {
|
||||
* Create the {@link BeanDefinition} for the container factory using the specified
|
||||
* shared property values.
|
||||
*/
|
||||
@Nullable
|
||||
protected abstract RootBeanDefinition createContainerFactory(String factoryId, Element containerEle, ParserContext parserContext,
|
||||
PropertyValues commonContainerProperties, PropertyValues specificContainerProperties);
|
||||
|
||||
@@ -323,6 +325,7 @@ abstract class AbstractListenerContainerParser implements BeanDefinitionParser {
|
||||
PropertyValues commonContainerProperties, PropertyValues specificContainerProperties);
|
||||
|
||||
|
||||
@Nullable
|
||||
protected Integer parseAcknowledgeMode(Element ele, ParserContext parserContext) {
|
||||
String acknowledge = ele.getAttribute(ACKNOWLEDGE_ATTRIBUTE);
|
||||
if (StringUtils.hasText(acknowledge)) {
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.messaging.handler.annotation.support.DefaultMessageHandlerMethodFactory;
|
||||
import org.springframework.messaging.handler.annotation.support.MessageHandlerMethodFactory;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -65,6 +66,7 @@ public class JmsListenerEndpointRegistrar implements BeanFactoryAware, Initializ
|
||||
* Return the {@link JmsListenerEndpointRegistry} instance for this
|
||||
* registrar, may be {@code null}.
|
||||
*/
|
||||
@Nullable
|
||||
public JmsListenerEndpointRegistry getEndpointRegistry() {
|
||||
return this.endpointRegistry;
|
||||
}
|
||||
@@ -84,6 +86,7 @@ public class JmsListenerEndpointRegistrar implements BeanFactoryAware, Initializ
|
||||
/**
|
||||
* Return the custom {@link MessageHandlerMethodFactory} to use, if any.
|
||||
*/
|
||||
@Nullable
|
||||
public MessageHandlerMethodFactory getMessageHandlerMethodFactory() {
|
||||
return this.messageHandlerMethodFactory;
|
||||
}
|
||||
@@ -164,7 +167,7 @@ public class JmsListenerEndpointRegistrar implements BeanFactoryAware, Initializ
|
||||
* <p>The {@code factory} may be {@code null} if the default factory has to be
|
||||
* used for that endpoint.
|
||||
*/
|
||||
public void registerEndpoint(JmsListenerEndpoint endpoint, JmsListenerContainerFactory<?> factory) {
|
||||
public void registerEndpoint(JmsListenerEndpoint endpoint, @Nullable JmsListenerContainerFactory<?> factory) {
|
||||
Assert.notNull(endpoint, "Endpoint must be set");
|
||||
Assert.hasText(endpoint.getId(), "Endpoint id must be set");
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.SmartLifecycle;
|
||||
import org.springframework.context.event.ContextRefreshedEvent;
|
||||
import org.springframework.jms.listener.MessageListenerContainer;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -93,6 +94,7 @@ public class JmsListenerEndpointRegistry implements DisposableBean, SmartLifecyc
|
||||
* @see JmsListenerEndpoint#getId()
|
||||
* @see #getListenerContainerIds()
|
||||
*/
|
||||
@Nullable
|
||||
public MessageListenerContainer getListenerContainer(String id) {
|
||||
Assert.notNull(id, "Container identifier must not be null");
|
||||
return this.listenerContainers.get(id);
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter;
|
||||
import org.springframework.jms.support.QosSettings;
|
||||
import org.springframework.jms.support.converter.MessageConverter;
|
||||
import org.springframework.jms.support.destination.DestinationResolver;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.messaging.handler.annotation.SendTo;
|
||||
import org.springframework.messaging.handler.annotation.support.MessageHandlerMethodFactory;
|
||||
import org.springframework.messaging.handler.invocation.InvocableHandlerMethod;
|
||||
@@ -124,7 +125,7 @@ public class MethodJmsListenerEndpoint extends AbstractJmsListenerEndpoint imple
|
||||
* Set the {@link BeanFactory} to use to resolve expressions (may be {@code null}).
|
||||
*/
|
||||
@Override
|
||||
public void setBeanFactory(BeanFactory beanFactory) {
|
||||
public void setBeanFactory(@Nullable BeanFactory beanFactory) {
|
||||
if (this.embeddedValueResolver == null && beanFactory instanceof ConfigurableBeanFactory) {
|
||||
this.embeddedValueResolver = new EmbeddedValueResolver((ConfigurableBeanFactory) beanFactory);
|
||||
}
|
||||
@@ -174,6 +175,7 @@ public class MethodJmsListenerEndpoint extends AbstractJmsListenerEndpoint imple
|
||||
/**
|
||||
* Return the default response destination, if any.
|
||||
*/
|
||||
@Nullable
|
||||
protected String getDefaultResponseDestination() {
|
||||
Method specificMethod = getMostSpecificMethod();
|
||||
SendTo ann = getSendTo(specificMethod);
|
||||
|
||||
@@ -2,4 +2,7 @@
|
||||
* Support package for declarative messaging configuration,
|
||||
* with Java configuration and XML schema support.
|
||||
*/
|
||||
@NonNullApi
|
||||
package org.springframework.jms.config;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
|
||||
@@ -39,6 +39,7 @@ import javax.jms.TemporaryTopic;
|
||||
import javax.jms.Topic;
|
||||
import javax.jms.TopicSession;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
@@ -278,6 +279,7 @@ public class CachingConnectionFactory extends SingleConnectionFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
String methodName = method.getName();
|
||||
if (methodName.equals("equals")) {
|
||||
|
||||
@@ -30,6 +30,7 @@ import javax.jms.TopicSession;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.transaction.support.ResourceHolderSynchronization;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -64,7 +65,7 @@ public abstract class ConnectionFactoryUtils {
|
||||
* @see SmartConnectionFactory#shouldStop
|
||||
* @see org.springframework.jms.support.JmsUtils#closeConnection
|
||||
*/
|
||||
public static void releaseConnection(Connection con, ConnectionFactory cf, boolean started) {
|
||||
public static void releaseConnection(Connection con, @Nullable ConnectionFactory cf, boolean started) {
|
||||
if (con == null) {
|
||||
return;
|
||||
}
|
||||
@@ -131,8 +132,9 @@ public abstract class ConnectionFactoryUtils {
|
||||
* @return the transactional Session, or {@code null} if none found
|
||||
* @throws JMSException in case of JMS failure
|
||||
*/
|
||||
@Nullable
|
||||
public static Session getTransactionalSession(final ConnectionFactory cf,
|
||||
final Connection existingCon, final boolean synchedLocalTransactionAllowed)
|
||||
@Nullable final Connection existingCon, final boolean synchedLocalTransactionAllowed)
|
||||
throws JMSException {
|
||||
|
||||
return doGetTransactionalSession(cf, new ResourceFactory() {
|
||||
@@ -173,8 +175,9 @@ public abstract class ConnectionFactoryUtils {
|
||||
* @return the transactional Session, or {@code null} if none found
|
||||
* @throws JMSException in case of JMS failure
|
||||
*/
|
||||
@Nullable
|
||||
public static QueueSession getTransactionalQueueSession(final QueueConnectionFactory cf,
|
||||
final QueueConnection existingCon, final boolean synchedLocalTransactionAllowed)
|
||||
@Nullable final QueueConnection existingCon, final boolean synchedLocalTransactionAllowed)
|
||||
throws JMSException {
|
||||
|
||||
return (QueueSession) doGetTransactionalSession(cf, new ResourceFactory() {
|
||||
@@ -215,8 +218,9 @@ public abstract class ConnectionFactoryUtils {
|
||||
* @return the transactional Session, or {@code null} if none found
|
||||
* @throws JMSException in case of JMS failure
|
||||
*/
|
||||
@Nullable
|
||||
public static TopicSession getTransactionalTopicSession(final TopicConnectionFactory cf,
|
||||
final TopicConnection existingCon, final boolean synchedLocalTransactionAllowed)
|
||||
@Nullable final TopicConnection existingCon, final boolean synchedLocalTransactionAllowed)
|
||||
throws JMSException {
|
||||
|
||||
return (TopicSession) doGetTransactionalSession(cf, new ResourceFactory() {
|
||||
@@ -256,6 +260,7 @@ public abstract class ConnectionFactoryUtils {
|
||||
* @throws JMSException in case of JMS failure
|
||||
* @see #doGetTransactionalSession(javax.jms.ConnectionFactory, ResourceFactory, boolean)
|
||||
*/
|
||||
@Nullable
|
||||
public static Session doGetTransactionalSession(
|
||||
ConnectionFactory connectionFactory, ResourceFactory resourceFactory) throws JMSException {
|
||||
|
||||
@@ -274,6 +279,7 @@ public abstract class ConnectionFactoryUtils {
|
||||
* @return the transactional Session, or {@code null} if none found
|
||||
* @throws JMSException in case of JMS failure
|
||||
*/
|
||||
@Nullable
|
||||
public static Session doGetTransactionalSession(
|
||||
ConnectionFactory connectionFactory, ResourceFactory resourceFactory, boolean startConnection)
|
||||
throws JMSException {
|
||||
@@ -361,6 +367,7 @@ public abstract class ConnectionFactoryUtils {
|
||||
* @return an appropriate Session fetched from the holder,
|
||||
* or {@code null} if none found
|
||||
*/
|
||||
@Nullable
|
||||
Session getSession(JmsResourceHolder holder);
|
||||
|
||||
/**
|
||||
@@ -369,6 +376,7 @@ public abstract class ConnectionFactoryUtils {
|
||||
* @return an appropriate Connection fetched from the holder,
|
||||
* or {@code null} if none found
|
||||
*/
|
||||
@Nullable
|
||||
Connection getConnection(JmsResourceHolder holder);
|
||||
|
||||
/**
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.jms.Connection;
|
||||
import javax.jms.ConnectionFactory;
|
||||
import javax.jms.JMSException;
|
||||
@@ -30,6 +31,7 @@ import javax.jms.TransactionInProgressException;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.transaction.support.ResourceHolderSupport;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -77,7 +79,7 @@ public class JmsResourceHolder extends ResourceHolderSupport {
|
||||
* @param connectionFactory the JMS ConnectionFactory that this
|
||||
* resource holder is associated with (may be {@code null})
|
||||
*/
|
||||
public JmsResourceHolder(ConnectionFactory connectionFactory) {
|
||||
public JmsResourceHolder(@Nullable ConnectionFactory connectionFactory) {
|
||||
this.connectionFactory = connectionFactory;
|
||||
}
|
||||
|
||||
@@ -108,7 +110,7 @@ public class JmsResourceHolder extends ResourceHolderSupport {
|
||||
* @param connection the JMS Connection
|
||||
* @param session the JMS Session
|
||||
*/
|
||||
public JmsResourceHolder(ConnectionFactory connectionFactory, Connection connection, Session session) {
|
||||
public JmsResourceHolder(@Nullable ConnectionFactory connectionFactory, Connection connection, Session session) {
|
||||
this.connectionFactory = connectionFactory;
|
||||
addConnection(connection);
|
||||
addSession(session, connection);
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.jms.Connection;
|
||||
import javax.jms.ConnectionFactory;
|
||||
import javax.jms.ExceptionListener;
|
||||
@@ -40,6 +41,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -144,6 +146,7 @@ public class SingleConnectionFactory implements ConnectionFactory, QueueConnecti
|
||||
* Return the target ConnectionFactory which will be used to lazily
|
||||
* create a single Connection, if any.
|
||||
*/
|
||||
@org.springframework.lang.Nullable
|
||||
public ConnectionFactory getTargetConnectionFactory() {
|
||||
return this.targetConnectionFactory;
|
||||
}
|
||||
@@ -165,6 +168,7 @@ public class SingleConnectionFactory implements ConnectionFactory, QueueConnecti
|
||||
* Return a JMS client ID for the single Connection created and exposed
|
||||
* by this ConnectionFactory, if any.
|
||||
*/
|
||||
@org.springframework.lang.Nullable
|
||||
protected String getClientId() {
|
||||
return this.clientId;
|
||||
}
|
||||
@@ -182,6 +186,7 @@ public class SingleConnectionFactory implements ConnectionFactory, QueueConnecti
|
||||
* Return the JMS ExceptionListener implementation that should be registered
|
||||
* with the single Connection created by this factory, if any.
|
||||
*/
|
||||
@Nullable
|
||||
protected ExceptionListener getExceptionListener() {
|
||||
return this.exceptionListener;
|
||||
}
|
||||
@@ -436,6 +441,7 @@ public class SingleConnectionFactory implements ConnectionFactory, QueueConnecti
|
||||
* creation of a raw standard Session
|
||||
* @throws JMSException if thrown by the JMS API
|
||||
*/
|
||||
@Nullable
|
||||
protected Session getSession(Connection con, Integer mode) throws JMSException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -2,4 +2,7 @@
|
||||
* Provides a PlatformTransactionManager implementation for a single
|
||||
* JMS ConnectionFactory, and a SingleConnectionFactory adapter.
|
||||
*/
|
||||
@NonNullApi
|
||||
package org.springframework.jms.connection;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
|
||||
@@ -20,6 +20,8 @@ import javax.jms.JMSException;
|
||||
import javax.jms.QueueBrowser;
|
||||
import javax.jms.Session;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Callback for browsing the messages in a JMS queue.
|
||||
*
|
||||
@@ -44,6 +46,7 @@ public interface BrowserCallback<T> {
|
||||
* (or {@code null} if none)
|
||||
* @throws javax.jms.JMSException if thrown by JMS API methods
|
||||
*/
|
||||
@Nullable
|
||||
T doInJms(Session session, QueueBrowser browser) throws JMSException;
|
||||
|
||||
}
|
||||
|
||||
@@ -17,8 +17,10 @@
|
||||
package org.springframework.jms.core;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.jms.Destination;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.messaging.core.MessagePostProcessor;
|
||||
@@ -100,6 +102,7 @@ public interface JmsMessageOperations extends MessageSendingOperations<Destinati
|
||||
* @return the received message, possibly {@code null} if the message could not
|
||||
* be received, for example due to a timeout
|
||||
*/
|
||||
@Nullable
|
||||
Message<?> receive(String destinationName) throws MessagingException;
|
||||
|
||||
/**
|
||||
@@ -110,6 +113,7 @@ public interface JmsMessageOperations extends MessageSendingOperations<Destinati
|
||||
* @return the converted payload of the reply message, possibly {@code null} if
|
||||
* the message could not be received, for example due to a timeout
|
||||
*/
|
||||
@Nullable
|
||||
<T> T receiveAndConvert(String destinationName, Class<T> targetClass) throws MessagingException;
|
||||
|
||||
/**
|
||||
@@ -119,6 +123,7 @@ public interface JmsMessageOperations extends MessageSendingOperations<Destinati
|
||||
* @return the reply, possibly {@code null} if the message could not be received,
|
||||
* for example due to a timeout
|
||||
*/
|
||||
@Nullable
|
||||
Message<?> sendAndReceive(String destinationName, Message<?> requestMessage) throws MessagingException;
|
||||
|
||||
/**
|
||||
@@ -132,6 +137,7 @@ public interface JmsMessageOperations extends MessageSendingOperations<Destinati
|
||||
* @return the payload of the reply message, possibly {@code null} if the message
|
||||
* could not be received, for example due to a timeout
|
||||
*/
|
||||
@Nullable
|
||||
<T> T convertSendAndReceive(String destinationName, Object request, Class<T> targetClass) throws MessagingException;
|
||||
|
||||
/**
|
||||
@@ -146,6 +152,7 @@ public interface JmsMessageOperations extends MessageSendingOperations<Destinati
|
||||
* @return the payload of the reply message, possibly {@code null} if the message
|
||||
* could not be received, for example due to a timeout
|
||||
*/
|
||||
@Nullable
|
||||
<T> T convertSendAndReceive(String destinationName, Object request, Map<String, Object> headers, Class<T> targetClass)
|
||||
throws MessagingException;
|
||||
|
||||
@@ -162,6 +169,7 @@ public interface JmsMessageOperations extends MessageSendingOperations<Destinati
|
||||
* @return the payload of the reply message, possibly {@code null} if the message
|
||||
* could not be received, for example due to a timeout
|
||||
*/
|
||||
@Nullable
|
||||
<T> T convertSendAndReceive(String destinationName, Object request, Class<T> targetClass,
|
||||
MessagePostProcessor requestPostProcessor) throws MessagingException;
|
||||
|
||||
@@ -178,6 +186,7 @@ public interface JmsMessageOperations extends MessageSendingOperations<Destinati
|
||||
* @return the payload of the reply message, possibly {@code null} if the message
|
||||
* could not be received, for example due to a timeout
|
||||
*/
|
||||
@Nullable
|
||||
<T> T convertSendAndReceive(String destinationName, Object request, Map<String, Object> headers,
|
||||
Class<T> targetClass, MessagePostProcessor requestPostProcessor) throws MessagingException;
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import javax.jms.Message;
|
||||
import javax.jms.Queue;
|
||||
|
||||
import org.springframework.jms.JmsException;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Specifies a basic set of JMS operations.
|
||||
@@ -202,6 +203,7 @@ public interface JmsOperations {
|
||||
* @return the message received by the consumer, or {@code null} if the timeout expires
|
||||
* @throws JmsException checked JMSException converted to unchecked
|
||||
*/
|
||||
@Nullable
|
||||
Message receive() throws JmsException;
|
||||
|
||||
/**
|
||||
@@ -213,6 +215,7 @@ public interface JmsOperations {
|
||||
* @return the message received by the consumer, or {@code null} if the timeout expires
|
||||
* @throws JmsException checked JMSException converted to unchecked
|
||||
*/
|
||||
@Nullable
|
||||
Message receive(Destination destination) throws JmsException;
|
||||
|
||||
/**
|
||||
@@ -225,6 +228,7 @@ public interface JmsOperations {
|
||||
* @return the message received by the consumer, or {@code null} if the timeout expires
|
||||
* @throws JmsException checked JMSException converted to unchecked
|
||||
*/
|
||||
@Nullable
|
||||
Message receive(String destinationName) throws JmsException;
|
||||
|
||||
/**
|
||||
@@ -238,6 +242,7 @@ public interface JmsOperations {
|
||||
* @return the message received by the consumer, or {@code null} if the timeout expires
|
||||
* @throws JmsException checked JMSException converted to unchecked
|
||||
*/
|
||||
@Nullable
|
||||
Message receiveSelected(String messageSelector) throws JmsException;
|
||||
|
||||
/**
|
||||
@@ -251,6 +256,7 @@ public interface JmsOperations {
|
||||
* @return the message received by the consumer, or {@code null} if the timeout expires
|
||||
* @throws JmsException checked JMSException converted to unchecked
|
||||
*/
|
||||
@Nullable
|
||||
Message receiveSelected(Destination destination, String messageSelector) throws JmsException;
|
||||
|
||||
/**
|
||||
@@ -265,6 +271,7 @@ public interface JmsOperations {
|
||||
* @return the message received by the consumer, or {@code null} if the timeout expires
|
||||
* @throws JmsException checked JMSException converted to unchecked
|
||||
*/
|
||||
@Nullable
|
||||
Message receiveSelected(String destinationName, String messageSelector) throws JmsException;
|
||||
|
||||
|
||||
@@ -282,6 +289,7 @@ public interface JmsOperations {
|
||||
* @return the message produced for the consumer or {@code null} if the timeout expires.
|
||||
* @throws JmsException checked JMSException converted to unchecked
|
||||
*/
|
||||
@Nullable
|
||||
Object receiveAndConvert() throws JmsException;
|
||||
|
||||
/**
|
||||
@@ -294,6 +302,7 @@ public interface JmsOperations {
|
||||
* @return the message produced for the consumer or {@code null} if the timeout expires.
|
||||
* @throws JmsException checked JMSException converted to unchecked
|
||||
*/
|
||||
@Nullable
|
||||
Object receiveAndConvert(Destination destination) throws JmsException;
|
||||
|
||||
/**
|
||||
@@ -307,6 +316,7 @@ public interface JmsOperations {
|
||||
* @return the message produced for the consumer or {@code null} if the timeout expires.
|
||||
* @throws JmsException checked JMSException converted to unchecked
|
||||
*/
|
||||
@Nullable
|
||||
Object receiveAndConvert(String destinationName) throws JmsException;
|
||||
|
||||
/**
|
||||
@@ -321,6 +331,7 @@ public interface JmsOperations {
|
||||
* @return the message produced for the consumer or {@code null} if the timeout expires.
|
||||
* @throws JmsException checked JMSException converted to unchecked
|
||||
*/
|
||||
@Nullable
|
||||
Object receiveSelectedAndConvert(String messageSelector) throws JmsException;
|
||||
|
||||
/**
|
||||
@@ -335,6 +346,7 @@ public interface JmsOperations {
|
||||
* @return the message produced for the consumer or {@code null} if the timeout expires.
|
||||
* @throws JmsException checked JMSException converted to unchecked
|
||||
*/
|
||||
@Nullable
|
||||
Object receiveSelectedAndConvert(Destination destination, String messageSelector) throws JmsException;
|
||||
|
||||
/**
|
||||
@@ -350,6 +362,7 @@ public interface JmsOperations {
|
||||
* @return the message produced for the consumer or {@code null} if the timeout expires.
|
||||
* @throws JmsException checked JMSException converted to unchecked
|
||||
*/
|
||||
@Nullable
|
||||
Object receiveSelectedAndConvert(String destinationName, String messageSelector) throws JmsException;
|
||||
|
||||
|
||||
@@ -369,6 +382,7 @@ public interface JmsOperations {
|
||||
* @throws JmsException checked JMSException converted to unchecked
|
||||
* @since 4.1
|
||||
*/
|
||||
@Nullable
|
||||
Message sendAndReceive(MessageCreator messageCreator) throws JmsException;
|
||||
|
||||
/**
|
||||
@@ -383,6 +397,7 @@ public interface JmsOperations {
|
||||
* @throws JmsException checked JMSException converted to unchecked
|
||||
* @since 4.1
|
||||
*/
|
||||
@Nullable
|
||||
Message sendAndReceive(Destination destination, MessageCreator messageCreator) throws JmsException;
|
||||
|
||||
/**
|
||||
@@ -398,6 +413,7 @@ public interface JmsOperations {
|
||||
* @throws JmsException checked JMSException converted to unchecked
|
||||
* @since 4.1
|
||||
*/
|
||||
@Nullable
|
||||
Message sendAndReceive(String destinationName, MessageCreator messageCreator) throws JmsException;
|
||||
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.jms.core;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import javax.jms.Connection;
|
||||
import javax.jms.ConnectionFactory;
|
||||
import javax.jms.DeliveryMode;
|
||||
@@ -38,6 +39,7 @@ import org.springframework.jms.support.QosSettings;
|
||||
import org.springframework.jms.support.converter.MessageConverter;
|
||||
import org.springframework.jms.support.converter.SimpleMessageConverter;
|
||||
import org.springframework.jms.support.destination.JmsDestinationAccessor;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
@@ -786,7 +788,8 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations
|
||||
* @return the JMS Message received, or {@code null} if none
|
||||
* @throws JMSException if thrown by JMS API methods
|
||||
*/
|
||||
protected Message doReceive(Session session, Destination destination, String messageSelector)
|
||||
@Nullable
|
||||
protected Message doReceive(Session session, Destination destination, @Nullable String messageSelector)
|
||||
throws JMSException {
|
||||
|
||||
return doReceive(session, createConsumer(session, destination, messageSelector));
|
||||
@@ -799,6 +802,7 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations
|
||||
* @return the JMS Message received, or {@code null} if none
|
||||
* @throws JMSException if thrown by JMS API methods
|
||||
*/
|
||||
@Nullable
|
||||
protected Message doReceive(Session session, MessageConsumer consumer) throws JMSException {
|
||||
try {
|
||||
// Use transaction timeout (if available).
|
||||
@@ -869,7 +873,8 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations
|
||||
* @param message the JMS Message to convert (can be {@code null})
|
||||
* @return the content of the message, or {@code null} if none
|
||||
*/
|
||||
protected Object doConvertFromMessage(Message message) {
|
||||
@Nullable
|
||||
protected Object doConvertFromMessage(@Nullable Message message) {
|
||||
if (message != null) {
|
||||
try {
|
||||
return getRequiredMessageConverter().fromMessage(message);
|
||||
@@ -924,6 +929,7 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations
|
||||
* <p>Return the response message or {@code null} if no message has
|
||||
* @throws JMSException if thrown by JMS API methods
|
||||
*/
|
||||
@Nullable
|
||||
protected Message doSendAndReceive(Session session, Destination destination, MessageCreator messageCreator)
|
||||
throws JMSException {
|
||||
|
||||
@@ -1065,6 +1071,7 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations
|
||||
* @return an appropriate Connection fetched from the holder,
|
||||
* or {@code null} if none found
|
||||
*/
|
||||
@Nullable
|
||||
protected Connection getConnection(JmsResourceHolder holder) {
|
||||
return holder.getConnection();
|
||||
}
|
||||
@@ -1076,6 +1083,7 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations
|
||||
* @return an appropriate Session fetched from the holder,
|
||||
* or {@code null} if none found
|
||||
*/
|
||||
@Nullable
|
||||
protected Session getSession(JmsResourceHolder holder) {
|
||||
return holder.getSession();
|
||||
}
|
||||
@@ -1141,7 +1149,7 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations
|
||||
* @return the new JMS MessageConsumer
|
||||
* @throws JMSException if thrown by JMS API methods
|
||||
*/
|
||||
protected MessageConsumer createConsumer(Session session, Destination destination, String messageSelector)
|
||||
protected MessageConsumer createConsumer(Session session, Destination destination, @Nullable String messageSelector)
|
||||
throws JMSException {
|
||||
|
||||
// Only pass in the NoLocal flag in case of a Topic:
|
||||
@@ -1168,7 +1176,7 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations
|
||||
* @see #setMessageIdEnabled
|
||||
* @see #setMessageTimestampEnabled
|
||||
*/
|
||||
protected QueueBrowser createBrowser(Session session, Queue queue, String messageSelector)
|
||||
protected QueueBrowser createBrowser(Session session, Queue queue, @Nullable String messageSelector)
|
||||
throws JMSException {
|
||||
|
||||
return session.createBrowser(queue, messageSelector);
|
||||
|
||||
@@ -20,6 +20,8 @@ import javax.jms.JMSException;
|
||||
import javax.jms.MessageProducer;
|
||||
import javax.jms.Session;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Callback for sending a message to a JMS destination.
|
||||
*
|
||||
@@ -49,6 +51,7 @@ public interface ProducerCallback<T> {
|
||||
* (or {@code null} if none)
|
||||
* @throws javax.jms.JMSException if thrown by JMS API methods
|
||||
*/
|
||||
@Nullable
|
||||
T doInJms(Session session, MessageProducer producer) throws JMSException;
|
||||
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@ package org.springframework.jms.core;
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.Session;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Callback for executing any number of operations on a provided {@link Session}.
|
||||
*
|
||||
@@ -40,6 +42,7 @@ public interface SessionCallback<T> {
|
||||
* (or {@code null} if none)
|
||||
* @throws javax.jms.JMSException if thrown by JMS API methods
|
||||
*/
|
||||
@Nullable
|
||||
T doInJms(Session session) throws JMSException;
|
||||
|
||||
}
|
||||
|
||||
@@ -2,4 +2,7 @@
|
||||
* Core package of the JMS support.
|
||||
* Provides a JmsTemplate class and various callback interfaces.
|
||||
*/
|
||||
@NonNullApi
|
||||
package org.springframework.jms.core;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
|
||||
@@ -2,4 +2,7 @@
|
||||
* Classes supporting the {@code org.springframework.jms.core} package.
|
||||
* Contains a base class for JmsTemplate usage.
|
||||
*/
|
||||
@NonNullApi
|
||||
package org.springframework.jms.core.support;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.springframework.jms.JmsException;
|
||||
import org.springframework.jms.connection.ConnectionFactoryUtils;
|
||||
import org.springframework.jms.support.JmsUtils;
|
||||
import org.springframework.jms.support.destination.JmsDestinationAccessor;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
@@ -100,6 +101,7 @@ public abstract class AbstractJmsListeningContainer extends JmsDestinationAccess
|
||||
* Return the JMS client ID for the shared Connection created and used
|
||||
* by this container, if any.
|
||||
*/
|
||||
@Nullable
|
||||
public String getClientId() {
|
||||
return this.clientId;
|
||||
}
|
||||
@@ -146,6 +148,7 @@ public abstract class AbstractJmsListeningContainer extends JmsDestinationAccess
|
||||
* Return the bean name that this listener container has been assigned
|
||||
* in its containing bean factory, if any.
|
||||
*/
|
||||
@Nullable
|
||||
protected final String getBeanName() {
|
||||
return this.beanName;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.jms.listener;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import javax.jms.Connection;
|
||||
import javax.jms.Destination;
|
||||
import javax.jms.ExceptionListener;
|
||||
@@ -32,6 +33,7 @@ import javax.jms.Topic;
|
||||
import org.springframework.jms.support.JmsUtils;
|
||||
import org.springframework.jms.support.QosSettings;
|
||||
import org.springframework.jms.support.converter.MessageConverter;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ErrorHandler;
|
||||
@@ -213,6 +215,7 @@ public abstract class AbstractMessageListenerContainer extends AbstractJmsListen
|
||||
* if the configured destination is not an actual {@link Destination} type;
|
||||
* c.f. {@link #setDestinationName(String) when the destination is a String}.
|
||||
*/
|
||||
@Nullable
|
||||
public Destination getDestination() {
|
||||
return (this.destination instanceof Destination ? (Destination) this.destination : null);
|
||||
}
|
||||
@@ -229,7 +232,7 @@ public abstract class AbstractMessageListenerContainer extends AbstractJmsListen
|
||||
* @param destinationName the desired destination (can be {@code null})
|
||||
* @see #setDestination(javax.jms.Destination)
|
||||
*/
|
||||
public void setDestinationName(String destinationName) {
|
||||
public void setDestinationName(@Nullable String destinationName) {
|
||||
Assert.notNull(destinationName, "'destinationName' must not be null");
|
||||
this.destination = destinationName;
|
||||
}
|
||||
@@ -240,6 +243,7 @@ public abstract class AbstractMessageListenerContainer extends AbstractJmsListen
|
||||
* {@link String} type; c.f. {@link #setDestination(Destination) when
|
||||
* it is an actual Destination}.
|
||||
*/
|
||||
@Nullable
|
||||
public String getDestinationName() {
|
||||
return (this.destination instanceof String ? (String) this.destination : null);
|
||||
}
|
||||
@@ -261,13 +265,14 @@ public abstract class AbstractMessageListenerContainer extends AbstractJmsListen
|
||||
* DefaultMessageListenerContainer, as long as the cache level is less than
|
||||
* CACHE_CONSUMER). However, this is considered advanced usage; use it with care!
|
||||
*/
|
||||
public void setMessageSelector(String messageSelector) {
|
||||
public void setMessageSelector(@Nullable String messageSelector) {
|
||||
this.messageSelector = messageSelector;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the JMS message selector expression (or {@code null} if none).
|
||||
*/
|
||||
@Nullable
|
||||
public String getMessageSelector() {
|
||||
return this.messageSelector;
|
||||
}
|
||||
@@ -415,6 +420,7 @@ public abstract class AbstractMessageListenerContainer extends AbstractJmsListen
|
||||
* Return the name of a subscription to create, if any.
|
||||
* @since 4.1
|
||||
*/
|
||||
@Nullable
|
||||
public String getSubscriptionName() {
|
||||
return this.subscriptionName;
|
||||
}
|
||||
@@ -441,6 +447,7 @@ public abstract class AbstractMessageListenerContainer extends AbstractJmsListen
|
||||
/**
|
||||
* Return the name of a durable subscription to create, if any.
|
||||
*/
|
||||
@Nullable
|
||||
public String getDurableSubscriptionName() {
|
||||
return (this.subscriptionDurable ? this.subscriptionName : null);
|
||||
}
|
||||
@@ -500,7 +507,7 @@ public abstract class AbstractMessageListenerContainer extends AbstractJmsListen
|
||||
* to use the default vas.
|
||||
* @since 5.0
|
||||
*/
|
||||
public void setReplyQosSettings(QosSettings replyQosSettings) {
|
||||
public void setReplyQosSettings(@Nullable QosSettings replyQosSettings) {
|
||||
this.replyQosSettings = replyQosSettings;
|
||||
}
|
||||
|
||||
@@ -534,6 +541,7 @@ public abstract class AbstractMessageListenerContainer extends AbstractJmsListen
|
||||
* Return the JMS ExceptionListener to notify in case of a JMSException thrown
|
||||
* by the registered message listener or the invocation infrastructure, if any.
|
||||
*/
|
||||
@Nullable
|
||||
public ExceptionListener getExceptionListener() {
|
||||
return this.exceptionListener;
|
||||
}
|
||||
@@ -553,6 +561,7 @@ public abstract class AbstractMessageListenerContainer extends AbstractJmsListen
|
||||
* while processing a Message.
|
||||
* @since 4.1
|
||||
*/
|
||||
@Nullable
|
||||
public ErrorHandler getErrorHandler() {
|
||||
return this.errorHandler;
|
||||
}
|
||||
@@ -864,6 +873,7 @@ public abstract class AbstractMessageListenerContainer extends AbstractJmsListen
|
||||
* @return the new JMS MessageConsumer
|
||||
* @throws javax.jms.JMSException if thrown by JMS API methods
|
||||
*/
|
||||
@Nullable
|
||||
protected MessageConsumer createConsumer(Session session, Destination destination) throws JMSException {
|
||||
if (isPubSubDomain() && destination instanceof Topic) {
|
||||
if (isSubscriptionShared()) {
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.springframework.jms.connection.ConnectionFactoryUtils;
|
||||
import org.springframework.jms.connection.JmsResourceHolder;
|
||||
import org.springframework.jms.connection.SingleConnectionFactory;
|
||||
import org.springframework.jms.support.JmsUtils;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
import org.springframework.transaction.support.DefaultTransactionDefinition;
|
||||
@@ -267,7 +268,7 @@ public abstract class AbstractPollingMessageListenerContainer extends AbstractMe
|
||||
* @see #doExecuteListener(javax.jms.Session, javax.jms.Message)
|
||||
*/
|
||||
protected boolean doReceiveAndExecute(
|
||||
Object invoker, Session session, MessageConsumer consumer, TransactionStatus status)
|
||||
Object invoker, Session session, MessageConsumer consumer, @Nullable TransactionStatus status)
|
||||
throws JMSException {
|
||||
|
||||
Connection conToClose = null;
|
||||
@@ -443,6 +444,7 @@ public abstract class AbstractPollingMessageListenerContainer extends AbstractMe
|
||||
* @return an appropriate Connection fetched from the holder,
|
||||
* or {@code null} if none found
|
||||
*/
|
||||
@Nullable
|
||||
protected Connection getConnection(JmsResourceHolder holder) {
|
||||
return holder.getConnection();
|
||||
}
|
||||
@@ -454,6 +456,7 @@ public abstract class AbstractPollingMessageListenerContainer extends AbstractMe
|
||||
* @return an appropriate Session fetched from the holder,
|
||||
* or {@code null} if none found
|
||||
*/
|
||||
@Nullable
|
||||
protected Session getSession(JmsResourceHolder holder) {
|
||||
return holder.getSession();
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import org.springframework.context.SmartLifecycle;
|
||||
import org.springframework.jms.support.QosSettings;
|
||||
import org.springframework.jms.support.converter.MessageConverter;
|
||||
import org.springframework.jms.support.destination.DestinationResolver;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Internal abstraction used by the framework representing a message
|
||||
@@ -41,12 +42,14 @@ public interface MessageListenerContainer extends SmartLifecycle {
|
||||
* Return the {@link MessageConverter} that can be used to
|
||||
* convert {@link javax.jms.Message}, if any.
|
||||
*/
|
||||
@Nullable
|
||||
MessageConverter getMessageConverter();
|
||||
|
||||
/**
|
||||
* Return the {@link DestinationResolver} to use to resolve
|
||||
* destinations by names.
|
||||
*/
|
||||
@Nullable
|
||||
DestinationResolver getDestinationResolver();
|
||||
|
||||
/**
|
||||
@@ -68,6 +71,7 @@ public interface MessageListenerContainer extends SmartLifecycle {
|
||||
* if the broker's defaults should be used.
|
||||
* @since 5.0
|
||||
*/
|
||||
@Nullable
|
||||
QosSettings getReplyQosSettings();
|
||||
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ import org.springframework.jms.support.converter.SimpleMessageConverter;
|
||||
import org.springframework.jms.support.converter.SmartMessageConverter;
|
||||
import org.springframework.jms.support.destination.DestinationResolver;
|
||||
import org.springframework.jms.support.destination.DynamicDestinationResolver;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -176,7 +177,7 @@ public abstract class AbstractAdaptableMessageListener
|
||||
* {@code null} to use the default values.
|
||||
* @since 5.0
|
||||
*/
|
||||
public void setResponseQosSettings(QosSettings responseQosSettings) {
|
||||
public void setResponseQosSettings(@Nullable QosSettings responseQosSettings) {
|
||||
this.responseQosSettings = responseQosSettings;
|
||||
}
|
||||
|
||||
@@ -184,6 +185,7 @@ public abstract class AbstractAdaptableMessageListener
|
||||
* Return the {@link QosSettings} to use when sending a response or {@code null} if
|
||||
* the defaults should be used.
|
||||
*/
|
||||
@Nullable
|
||||
protected QosSettings getResponseQosSettings() {
|
||||
return this.responseQosSettings;
|
||||
}
|
||||
@@ -256,7 +258,7 @@ public abstract class AbstractAdaptableMessageListener
|
||||
* @see #getResponseDestination
|
||||
* @see #sendResponse
|
||||
*/
|
||||
protected void handleResult(Object result, Message request, Session session) {
|
||||
protected void handleResult(Object result, Message request, @Nullable Session session) {
|
||||
if (session != null) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Listener method returned result [" + result +
|
||||
@@ -394,6 +396,7 @@ public abstract class AbstractAdaptableMessageListener
|
||||
* @see #setDefaultResponseTopicName
|
||||
* @see #setDestinationResolver
|
||||
*/
|
||||
@Nullable
|
||||
protected Destination resolveDefaultResponseDestination(Session session) throws JMSException {
|
||||
if (this.defaultResponseDestination instanceof Destination) {
|
||||
return (Destination) this.defaultResponseDestination;
|
||||
|
||||
@@ -21,6 +21,7 @@ import javax.jms.JMSException;
|
||||
import javax.jms.Session;
|
||||
|
||||
import org.springframework.jms.support.destination.DestinationResolver;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -86,6 +87,7 @@ public class JmsResponse<T> {
|
||||
* @return the {@link Destination} to use
|
||||
* @throws JMSException if the DestinationResolver failed to resolve the destination
|
||||
*/
|
||||
@Nullable
|
||||
public Destination resolveDestination(DestinationResolver destinationResolver, Session session)
|
||||
throws JMSException {
|
||||
|
||||
|
||||
@@ -3,4 +3,7 @@
|
||||
* methods, converting messages to appropriate message content types
|
||||
* (such as String or byte array) that get passed into listener methods.
|
||||
*/
|
||||
@NonNullApi
|
||||
package org.springframework.jms.listener.adapter;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
|
||||
@@ -21,6 +21,7 @@ import javax.jms.Session;
|
||||
import org.springframework.core.Constants;
|
||||
import org.springframework.jms.support.QosSettings;
|
||||
import org.springframework.jms.support.converter.MessageConverter;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Common configuration object for activating a JMS message endpoint.
|
||||
@@ -267,6 +268,7 @@ public class JmsActivationSpecConfig {
|
||||
/**
|
||||
* Return the {@link MessageConverter} to use, if any.
|
||||
*/
|
||||
@Nullable
|
||||
public MessageConverter getMessageConverter() {
|
||||
return this.messageConverter;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.springframework.jms.listener.MessageListenerContainer;
|
||||
import org.springframework.jms.support.QosSettings;
|
||||
import org.springframework.jms.support.converter.MessageConverter;
|
||||
import org.springframework.jms.support.destination.DestinationResolver;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Extension of the generic JCA 1.5
|
||||
@@ -144,6 +145,7 @@ public class JmsMessageEndpointManager extends GenericMessageEndpointManager
|
||||
* Return the {@link JmsActivationSpecConfig} object that this endpoint manager
|
||||
* should use for activating its listener. Return {@code null} if none is set.
|
||||
*/
|
||||
@Nullable
|
||||
public JmsActivationSpecConfig getActivationSpecConfig() {
|
||||
return this.activationSpecConfig;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.jms.listener.endpoint;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.Queue;
|
||||
import javax.jms.Session;
|
||||
@@ -29,6 +30,7 @@ import org.springframework.beans.BeanWrapper;
|
||||
import org.springframework.beans.PropertyAccessorFactory;
|
||||
import org.springframework.jms.support.destination.DestinationResolutionException;
|
||||
import org.springframework.jms.support.destination.DestinationResolver;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Standard implementation of the {@link JmsActivationSpecFactory} interface.
|
||||
@@ -124,6 +126,7 @@ public class StandardJmsActivationSpecFactory implements JmsActivationSpecFactor
|
||||
* if not determinable
|
||||
* @see #setActivationSpecClass
|
||||
*/
|
||||
@Nullable
|
||||
protected Class<?> determineActivationSpecClass(ResourceAdapter adapter) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
/**
|
||||
* This package provides JCA-based endpoint management for JMS message listeners.
|
||||
*/
|
||||
@NonNullApi
|
||||
package org.springframework.jms.listener.endpoint;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
|
||||
@@ -3,4 +3,7 @@
|
||||
* It also offers the DefaultMessageListenerContainer and SimpleMessageListenerContainer
|
||||
* implementations, based on the plain JMS client API.
|
||||
*/
|
||||
@NonNullApi
|
||||
package org.springframework.jms.listener;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
|
||||
@@ -2,4 +2,7 @@
|
||||
* This package contains integration classes for JMS,
|
||||
* allowing for Spring-style JMS access.
|
||||
*/
|
||||
@NonNullApi
|
||||
package org.springframework.jms;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.springframework.jms.listener.SessionAwareMessageListener;
|
||||
import org.springframework.jms.support.JmsUtils;
|
||||
import org.springframework.jms.support.converter.MessageConverter;
|
||||
import org.springframework.jms.support.converter.SimpleMessageConverter;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.remoting.support.RemoteInvocation;
|
||||
import org.springframework.remoting.support.RemoteInvocationBasedExporter;
|
||||
import org.springframework.remoting.support.RemoteInvocationResult;
|
||||
@@ -111,6 +112,7 @@ public class JmsInvokerServiceExporter extends RemoteInvocationBasedExporter
|
||||
* in case of an invalid message that will simply be ignored)
|
||||
* @throws javax.jms.JMSException in case of message access failure
|
||||
*/
|
||||
@Nullable
|
||||
protected RemoteInvocation readRemoteInvocation(Message requestMessage) throws JMSException {
|
||||
Object content = this.messageConverter.fromMessage(requestMessage);
|
||||
if (content instanceof RemoteInvocation) {
|
||||
@@ -178,6 +180,7 @@ public class JmsInvokerServiceExporter extends RemoteInvocationBasedExporter
|
||||
* @see #readRemoteInvocation
|
||||
* @see #setIgnoreInvalidRequests
|
||||
*/
|
||||
@Nullable
|
||||
protected RemoteInvocation onInvalidRequest(Message requestMessage) throws JMSException {
|
||||
if (this.ignoreInvalidRequests) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
|
||||
@@ -5,4 +5,7 @@
|
||||
* receivers, and provides a level of indirection between the client and the
|
||||
* service: They only need to agree on a queue name and a service interface.
|
||||
*/
|
||||
@NonNullApi
|
||||
package org.springframework.jms.remoting;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
|
||||
@@ -40,6 +40,7 @@ import org.springframework.jms.ResourceAllocationException;
|
||||
import org.springframework.jms.TransactionInProgressException;
|
||||
import org.springframework.jms.TransactionRolledBackException;
|
||||
import org.springframework.jms.UncategorizedJmsException;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -59,7 +60,7 @@ public abstract class JmsUtils {
|
||||
* This is useful for typical {@code finally} blocks in manual JMS code.
|
||||
* @param con the JMS Connection to close (may be {@code null})
|
||||
*/
|
||||
public static void closeConnection(Connection con) {
|
||||
public static void closeConnection(@Nullable Connection con) {
|
||||
closeConnection(con, false);
|
||||
}
|
||||
|
||||
@@ -69,7 +70,7 @@ public abstract class JmsUtils {
|
||||
* @param con the JMS Connection to close (may be {@code null})
|
||||
* @param stop whether to call {@code stop()} before closing
|
||||
*/
|
||||
public static void closeConnection(Connection con, boolean stop) {
|
||||
public static void closeConnection(@Nullable Connection con, boolean stop) {
|
||||
if (con != null) {
|
||||
try {
|
||||
if (stop) {
|
||||
@@ -102,7 +103,7 @@ public abstract class JmsUtils {
|
||||
* This is useful for typical {@code finally} blocks in manual JMS code.
|
||||
* @param session the JMS Session to close (may be {@code null})
|
||||
*/
|
||||
public static void closeSession(Session session) {
|
||||
public static void closeSession(@Nullable Session session) {
|
||||
if (session != null) {
|
||||
try {
|
||||
session.close();
|
||||
@@ -122,7 +123,7 @@ public abstract class JmsUtils {
|
||||
* This is useful for typical {@code finally} blocks in manual JMS code.
|
||||
* @param producer the JMS MessageProducer to close (may be {@code null})
|
||||
*/
|
||||
public static void closeMessageProducer(MessageProducer producer) {
|
||||
public static void closeMessageProducer(@Nullable MessageProducer producer) {
|
||||
if (producer != null) {
|
||||
try {
|
||||
producer.close();
|
||||
@@ -142,7 +143,7 @@ public abstract class JmsUtils {
|
||||
* This is useful for typical {@code finally} blocks in manual JMS code.
|
||||
* @param consumer the JMS MessageConsumer to close (may be {@code null})
|
||||
*/
|
||||
public static void closeMessageConsumer(MessageConsumer consumer) {
|
||||
public static void closeMessageConsumer(@Nullable MessageConsumer consumer) {
|
||||
if (consumer != null) {
|
||||
// Clear interruptions to ensure that the consumer closes successfully...
|
||||
// (working around misbehaving JMS providers such as ActiveMQ)
|
||||
@@ -171,7 +172,7 @@ public abstract class JmsUtils {
|
||||
* This is useful for typical {@code finally} blocks in manual JMS code.
|
||||
* @param browser the JMS QueueBrowser to close (may be {@code null})
|
||||
*/
|
||||
public static void closeQueueBrowser(QueueBrowser browser) {
|
||||
public static void closeQueueBrowser(@Nullable QueueBrowser browser) {
|
||||
if (browser != null) {
|
||||
try {
|
||||
browser.close();
|
||||
@@ -191,7 +192,7 @@ public abstract class JmsUtils {
|
||||
* This is useful for typical {@code finally} blocks in manual JMS code.
|
||||
* @param requestor the JMS QueueRequestor to close (may be {@code null})
|
||||
*/
|
||||
public static void closeQueueRequestor(QueueRequestor requestor) {
|
||||
public static void closeQueueRequestor(@Nullable QueueRequestor requestor) {
|
||||
if (requestor != null) {
|
||||
try {
|
||||
requestor.close();
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.io.StringWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.jms.BytesMessage;
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.Message;
|
||||
@@ -38,6 +39,7 @@ import com.fasterxml.jackson.databind.ObjectWriter;
|
||||
|
||||
import org.springframework.beans.factory.BeanClassLoaderAware;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
@@ -456,6 +458,7 @@ public class MappingJackson2MessageConverter implements SmartMessageConverter, B
|
||||
* converter for the current conversion attempt
|
||||
* @return the serialization view class, or {@code null} if none
|
||||
*/
|
||||
@Nullable
|
||||
protected Class<?> getSerializationView(Object conversionHint) {
|
||||
if (conversionHint instanceof MethodParameter) {
|
||||
MethodParameter methodParam = (MethodParameter) conversionHint;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.jms.support.converter;
|
||||
|
||||
import org.springframework.jms.JmsException;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Thrown by {@link MessageConverter} implementations when the conversion
|
||||
@@ -42,7 +43,7 @@ public class MessageConversionException extends JmsException {
|
||||
* @param msg the detail message
|
||||
* @param cause the root cause (if any)
|
||||
*/
|
||||
public MessageConversionException(String msg, Throwable cause) {
|
||||
public MessageConversionException(String msg, @Nullable Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@ import javax.jms.JMSException;
|
||||
import javax.jms.Message;
|
||||
import javax.jms.Session;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Strategy interface that specifies a converter between Java objects and JMS messages.
|
||||
*
|
||||
@@ -54,6 +56,7 @@ public interface MessageConverter {
|
||||
* @throws javax.jms.JMSException if thrown by JMS API methods
|
||||
* @throws MessageConversionException in case of conversion failure
|
||||
*/
|
||||
@Nullable
|
||||
Object fromMessage(Message message) throws JMSException, MessageConversionException;
|
||||
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@ import javax.jms.JMSException;
|
||||
import javax.jms.Message;
|
||||
import javax.jms.Session;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* An extended {@link MessageConverter} SPI with conversion hint support.
|
||||
*
|
||||
@@ -45,7 +47,7 @@ public interface SmartMessageConverter extends MessageConverter {
|
||||
* @throws MessageConversionException in case of conversion failure
|
||||
* @see #toMessage(Object, Session)
|
||||
*/
|
||||
Message toMessage(Object object, Session session, Object conversionHint)
|
||||
Message toMessage(Object object, Session session, @Nullable Object conversionHint)
|
||||
throws JMSException, MessageConversionException;
|
||||
|
||||
}
|
||||
|
||||
@@ -2,4 +2,7 @@
|
||||
* Provides a MessageConverter abstraction to convert
|
||||
* between Java objects and JMS messages.
|
||||
*/
|
||||
@NonNullApi
|
||||
package org.springframework.jms.support.converter;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.jms.support.destination;
|
||||
|
||||
import org.springframework.jms.JmsException;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Thrown by a DestinationResolver when it cannot resolve a destination name.
|
||||
@@ -41,7 +42,7 @@ public class DestinationResolutionException extends JmsException {
|
||||
* @param msg the detail message
|
||||
* @param cause the root cause (if any)
|
||||
*/
|
||||
public DestinationResolutionException(String msg, Throwable cause) {
|
||||
public DestinationResolutionException(String msg, @Nullable Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@ import javax.jms.Destination;
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.Session;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Strategy interface for resolving JMS destinations.
|
||||
*
|
||||
@@ -52,7 +54,7 @@ public interface DestinationResolver {
|
||||
* @throws javax.jms.JMSException if the JMS Session failed to resolve the destination
|
||||
* @throws DestinationResolutionException in case of general destination resolution failure
|
||||
*/
|
||||
Destination resolveDestinationName(Session session, String destinationName, boolean pubSubDomain)
|
||||
Destination resolveDestinationName(@Nullable Session session, String destinationName, boolean pubSubDomain)
|
||||
throws JMSException;
|
||||
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import javax.jms.MessageConsumer;
|
||||
import javax.jms.Session;
|
||||
|
||||
import org.springframework.jms.support.JmsAccessor;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -125,6 +126,7 @@ public abstract class JmsDestinationAccessor extends JmsAccessor {
|
||||
* @see #RECEIVE_TIMEOUT_NO_WAIT
|
||||
* @see #RECEIVE_TIMEOUT_INDEFINITE_WAIT
|
||||
*/
|
||||
@Nullable
|
||||
protected Message receiveFromConsumer(MessageConsumer consumer, long timeout) throws JMSException {
|
||||
if (timeout > 0) {
|
||||
return consumer.receive(timeout);
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
/**
|
||||
* Support classes for Spring's JMS framework.
|
||||
*/
|
||||
@NonNullApi
|
||||
package org.springframework.jms.support.destination;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
|
||||
@@ -2,4 +2,7 @@
|
||||
* This package provides generic JMS support classes,
|
||||
* to be used by higher-level classes like JmsTemplate.
|
||||
*/
|
||||
@NonNullApi
|
||||
package org.springframework.jms.support;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
|
||||
Reference in New Issue
Block a user