Fix new Sonar smells

Upgrade dependencies for upcoming release
This commit is contained in:
Artem Bilan
2019-04-11 09:20:38 -04:00
parent a49b04e7f6
commit d047d28de8
14 changed files with 93 additions and 76 deletions

View File

@@ -135,11 +135,11 @@ subprojects { subproject ->
servletApiVersion = '4.0.1' servletApiVersion = '4.0.1'
smackVersion = '4.3.1' smackVersion = '4.3.1'
springAmqpVersion = project.hasProperty('springAmqpVersion') ? project.springAmqpVersion : '2.2.0.M1' springAmqpVersion = project.hasProperty('springAmqpVersion') ? project.springAmqpVersion : '2.2.0.M1'
springDataJpaVersion = '2.2.0.BUILD-SNAPSHOT' springDataJpaVersion = '2.2.0.M3'
springDataMongoVersion = '2.2.0.BUILD-SNAPSHOT' springDataMongoVersion = '2.2.0.M3'
springDataRedisVersion = '2.2.0.BUILD-SNAPSHOT' springDataRedisVersion = '2.2.0.M3'
springGemfireVersion = '2.2.0.BUILD-SNAPSHOT' springGemfireVersion = '2.2.0.M3'
springSecurityVersion = '5.2.0.BUILD-SNAPSHOT' springSecurityVersion = '5.2.0.M1'
springRetryVersion = '1.2.4.RELEASE' springRetryVersion = '1.2.4.RELEASE'
springVersion = project.hasProperty('springVersion') ? project.springVersion : '5.2.0.M1' springVersion = project.hasProperty('springVersion') ? project.springVersion : '5.2.0.M1'
springWsVersion = '3.0.7.RELEASE' springWsVersion = '3.0.7.RELEASE'

View File

@@ -18,7 +18,6 @@ package org.springframework.integration.channel;
import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactory;
import org.springframework.integration.support.channel.ChannelResolverUtils; import org.springframework.integration.support.channel.ChannelResolverUtils;
import org.springframework.messaging.core.DestinationResolver;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.ErrorHandler; import org.springframework.util.ErrorHandler;
@@ -27,6 +26,7 @@ import org.springframework.util.ErrorHandler;
* *
* @author Artem Bilan * @author Artem Bilan
* @author Gary Russell * @author Gary Russell
*
* @since 5.2 * @since 5.2
* *
*/ */
@@ -42,7 +42,8 @@ public final class ChannelUtils {
* Obtain an {@link ErrorHandler} registered with the * Obtain an {@link ErrorHandler} registered with the
* {@value MESSAGE_PUBLISHING_ERROR_HANDLER_BEAN_NAME} bean name. * {@value MESSAGE_PUBLISHING_ERROR_HANDLER_BEAN_NAME} bean name.
* By default resolves to the {@link org.springframework.integration.channel.MessagePublishingErrorHandler} * By default resolves to the {@link org.springframework.integration.channel.MessagePublishingErrorHandler}
* with the {@value ChannelResolverUtils#CHANNEL_RESOLVER_BEAN_NAME} {@link DestinationResolver} bean. * with the {@value ChannelResolverUtils#CHANNEL_RESOLVER_BEAN_NAME}
* {@link org.springframework.messaging.core.DestinationResolver} bean.
* @param beanFactory BeanFactory for lookup, must not be null. * @param beanFactory BeanFactory for lookup, must not be null.
* @return the instance of {@link ErrorHandler} bean whose name is * @return the instance of {@link ErrorHandler} bean whose name is
* {@value MESSAGE_PUBLISHING_ERROR_HANDLER_BEAN_NAME}. * {@value MESSAGE_PUBLISHING_ERROR_HANDLER_BEAN_NAME}.

View File

@@ -61,23 +61,23 @@ import org.springframework.util.StringUtils;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public class IntegrationManagementConfigurer public class IntegrationManagementConfigurer
implements SmartInitializingSingleton, ApplicationContextAware, BeanNameAware, implements SmartInitializingSingleton, ApplicationContextAware, BeanNameAware,
DestructionAwareBeanPostProcessor { DestructionAwareBeanPostProcessor {
private static final Log logger = LogFactory.getLog(IntegrationManagementConfigurer.class); private static final Log LOGGER = LogFactory.getLog(IntegrationManagementConfigurer.class);
public static final String MANAGEMENT_CONFIGURER_NAME = "integrationManagementConfigurer"; public static final String MANAGEMENT_CONFIGURER_NAME = "integrationManagementConfigurer";
private final Map<String, org.springframework.integration.support.management.MessageChannelMetrics> private final Map<String, org.springframework.integration.support.management.MessageChannelMetrics>
channelsByName = new HashMap<>(); channelsByName = new HashMap<>();
private final Map<String, org.springframework.integration.support.management.MessageHandlerMetrics> private final Map<String, org.springframework.integration.support.management.MessageHandlerMetrics>
handlersByName = new HashMap<>(); handlersByName = new HashMap<>();
private final Map<String, org.springframework.integration.support.management.MessageSourceMetrics> private final Map<String, org.springframework.integration.support.management.MessageSourceMetrics>
sourcesByName = new HashMap<>(); sourcesByName = new HashMap<>();
private final Map<String, private final Map<String,
org.springframework.integration.support.management.MessageSourceMetricsConfigurer> org.springframework.integration.support.management.MessageSourceMetricsConfigurer>
sourceConfigurers = new HashMap<>(); sourceConfigurers = new HashMap<>();
private ApplicationContext applicationContext; private ApplicationContext applicationContext;
@@ -229,7 +229,7 @@ public class IntegrationManagementConfigurer
* Exception logging (debug or otherwise) is not affected by this setting. * Exception logging (debug or otherwise) is not affected by this setting.
* <p> * <p>
* It has been found that in high-volume messaging environments, calls to methods such as * It has been found that in high-volume messaging environments, calls to methods such as
* {@code logger.isDebuggingEnabled()} can be quite expensive and account for an inordinate amount of CPU * {@link Log#isDebugEnabled()} can be quite expensive and account for an inordinate amount of CPU
* time. * time.
* <p> * <p>
* Set this to false to disable logging by default in all framework components that implement * Set this to false to disable logging by default in all framework components that implement
@@ -263,7 +263,7 @@ public class IntegrationManagementConfigurer
} }
if (this.metricsFactory == null) { if (this.metricsFactory == null) {
Map<String, org.springframework.integration.support.management.MetricsFactory> Map<String, org.springframework.integration.support.management.MetricsFactory>
factories = this.applicationContext factories = this.applicationContext
.getBeansOfType(org.springframework.integration.support.management.MetricsFactory.class); .getBeansOfType(org.springframework.integration.support.management.MetricsFactory.class);
if (factories.size() == 1) { if (factories.size() == 1) {
this.metricsFactory = factories.values().iterator().next(); this.metricsFactory = factories.values().iterator().next();
@@ -327,22 +327,25 @@ public class IntegrationManagementConfigurer
this.handlersByName.remove(nameOfBean + ".handler"); this.handlersByName.remove(nameOfBean + ".handler");
} }
} }
else if (bean instanceof org.springframework.integration.support.management.MessageSourceMetrics) { else if (bean instanceof org.springframework.integration.support.management.MessageSourceMetrics &&
if (this.sourcesByName.remove(nameOfBean) == null) { this.sourcesByName.remove(nameOfBean) == null) {
this.sourcesByName.remove(nameOfBean + ".source");
} this.sourcesByName.remove(nameOfBean + ".source");
} }
} }
private Object doConfigureMetrics(Object bean, String name) { private Object doConfigureMetrics(Object bean, String name) {
if (bean instanceof org.springframework.integration.support.management.MessageChannelMetrics) { if (bean instanceof org.springframework.integration.support.management.MessageChannelMetrics) {
configureChannelMetrics(name, (org.springframework.integration.support.management.MessageChannelMetrics) bean); configureChannelMetrics(name,
(org.springframework.integration.support.management.MessageChannelMetrics) bean);
} }
else if (bean instanceof org.springframework.integration.support.management.MessageHandlerMetrics) { else if (bean instanceof org.springframework.integration.support.management.MessageHandlerMetrics) {
configureHandlerMetrics(name, (org.springframework.integration.support.management.MessageHandlerMetrics) bean); configureHandlerMetrics(name,
(org.springframework.integration.support.management.MessageHandlerMetrics) bean);
} }
else if (bean instanceof org.springframework.integration.support.management.MessageSourceMetrics) { else if (bean instanceof org.springframework.integration.support.management.MessageSourceMetrics) {
configureSourceMetrics(name, (org.springframework.integration.support.management.MessageSourceMetrics) bean); configureSourceMetrics(name,
(org.springframework.integration.support.management.MessageSourceMetrics) bean);
this.sourceConfigurers.values().forEach(c -> c this.sourceConfigurers.values().forEach(c -> c
.configure((org.springframework.integration.support.management.MessageSourceMetrics) bean, name)); .configure((org.springframework.integration.support.management.MessageSourceMetrics) bean, name));
} }
@@ -469,8 +472,8 @@ public class IntegrationManagementConfigurer
if (this.channelsByName.containsKey(name)) { if (this.channelsByName.containsKey(name)) {
return this.channelsByName.get(name); return this.channelsByName.get(name);
} }
if (logger.isDebugEnabled()) { if (LOGGER.isDebugEnabled()) {
logger.debug("No channel found for (" + name + ")"); LOGGER.debug("No channel found for (" + name + ")");
} }
return null; return null;
} }
@@ -483,8 +486,8 @@ public class IntegrationManagementConfigurer
return this.handlersByName.get(name + ".handler"); return this.handlersByName.get(name + ".handler");
} }
if (logger.isDebugEnabled()) { if (LOGGER.isDebugEnabled()) {
logger.debug("No handler found for (" + name + ")"); LOGGER.debug("No handler found for (" + name + ")");
} }
return null; return null;
} }
@@ -497,8 +500,8 @@ public class IntegrationManagementConfigurer
return this.sourcesByName.get(name + ".source"); return this.sourcesByName.get(name + ".source");
} }
if (logger.isDebugEnabled()) { if (LOGGER.isDebugEnabled()) {
logger.debug("No source found for (" + name + ")"); LOGGER.debug("No source found for (" + name + ")");
} }
return null; return null;
} }

View File

@@ -29,9 +29,11 @@ import org.apache.commons.logging.LogFactory;
*/ */
public abstract class AbstractMessageChannelMetrics implements ConfigurableMetrics { public abstract class AbstractMessageChannelMetrics implements ConfigurableMetrics {
protected final Log logger = LogFactory.getLog(getClass()); private static final String DEPRECATION = "deprecation";
protected final String name; protected final Log logger = LogFactory.getLog(getClass()); // NOSONAR - final
protected final String name; // NOSONAR - final
private volatile boolean fullStatsEnabled; private volatile boolean fullStatsEnabled;
@@ -61,7 +63,7 @@ public abstract class AbstractMessageChannelMetrics implements ConfigurableMetri
* @return the context to be used in a subsequent {@link #afterSend(MetricsContext, boolean)} * @return the context to be used in a subsequent {@link #afterSend(MetricsContext, boolean)}
* call. * call.
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings(DEPRECATION)
public abstract MetricsContext beforeSend(); public abstract MetricsContext beforeSend();
/** /**
@@ -71,7 +73,7 @@ public abstract class AbstractMessageChannelMetrics implements ConfigurableMetri
* @param context the context. * @param context the context.
* @param result true for success, false otherwise. * @param result true for success, false otherwise.
*/ */
public abstract void afterSend(@SuppressWarnings("deprecation") MetricsContext context, boolean result); public abstract void afterSend(@SuppressWarnings(DEPRECATION) MetricsContext context, boolean result);
/** /**
* Reset all counters/statistics. * Reset all counters/statistics.
@@ -102,13 +104,13 @@ public abstract class AbstractMessageChannelMetrics implements ConfigurableMetri
public abstract double getStandardDeviationSendDuration(); public abstract double getStandardDeviationSendDuration();
@SuppressWarnings("deprecation") @SuppressWarnings(DEPRECATION)
public abstract Statistics getSendDuration(); public abstract Statistics getSendDuration();
@SuppressWarnings("deprecation") @SuppressWarnings(DEPRECATION)
public abstract Statistics getSendRate(); public abstract Statistics getSendRate();
@SuppressWarnings("deprecation") @SuppressWarnings(DEPRECATION)
public abstract Statistics getErrorRate(); public abstract Statistics getErrorRate();
public abstract void afterReceive(); public abstract void afterReceive();

View File

@@ -27,7 +27,6 @@ package org.springframework.integration.support.management;
* *
*/ */
@Deprecated @Deprecated
@SuppressWarnings("deprecation")
public class AggregatingMetricsFactory implements MetricsFactory { public class AggregatingMetricsFactory implements MetricsFactory {
private final int sampleSize; private final int sampleSize;

View File

@@ -30,7 +30,6 @@ package org.springframework.integration.support.management;
* *
*/ */
@Deprecated @Deprecated
@SuppressWarnings("deprecation")
public class DefaultMetricsFactory implements MetricsFactory { public class DefaultMetricsFactory implements MetricsFactory {
@Override @Override

View File

@@ -41,7 +41,6 @@ import java.util.List;
* @since 2.0 * @since 2.0
*/ */
@Deprecated @Deprecated
@SuppressWarnings("deprecation")
public class ExponentialMovingAverage { public class ExponentialMovingAverage {
private volatile long count; private volatile long count;
@@ -50,7 +49,7 @@ public class ExponentialMovingAverage {
private volatile double max; private volatile double max;
private final Deque<Double> samples = new ArrayDeque<Double>(); private final Deque<Double> samples = new ArrayDeque<>();
private final int retention; private final int retention;

View File

@@ -46,7 +46,6 @@ import java.util.List;
* *
*/ */
@Deprecated @Deprecated
@SuppressWarnings("deprecation")
public class ExponentialMovingAverageRate { public class ExponentialMovingAverageRate {
private volatile double min = Double.MAX_VALUE; private volatile double min = Double.MAX_VALUE;
@@ -61,7 +60,7 @@ public class ExponentialMovingAverageRate {
private final double period; private final double period;
private final Deque<Long> times = new ArrayDeque<Long>(); private final Deque<Long> times = new ArrayDeque<>();
private final int retention; private final int retention;

View File

@@ -47,7 +47,6 @@ import java.util.List;
* @since 2.0 * @since 2.0
*/ */
@Deprecated @Deprecated
@SuppressWarnings("deprecation")
public class ExponentialMovingAverageRatio { public class ExponentialMovingAverageRatio {
private volatile double t0; private volatile double t0;
@@ -60,9 +59,9 @@ public class ExponentialMovingAverageRatio {
private final double lapse; private final double lapse;
private final Deque<Long> times = new ArrayDeque<Long>(); private final Deque<Long> times = new ArrayDeque<>();
private final Deque<Integer> values = new ArrayDeque<Integer>(); private final Deque<Integer> values = new ArrayDeque<>();
private final int retention; private final int retention;

View File

@@ -34,14 +34,13 @@ import org.springframework.jmx.export.annotation.ManagedOperation;
*/ */
@Deprecated @Deprecated
@IntegrationManagedResource @IntegrationManagedResource
@SuppressWarnings("deprecation")
public class LifecycleMessageHandlerMetrics implements public class LifecycleMessageHandlerMetrics implements
org.springframework.integration.support.management.MessageHandlerMetrics, Lifecycle, org.springframework.integration.support.management.MessageHandlerMetrics, Lifecycle,
ConfigurableMetricsAware<AbstractMessageHandlerMetrics> { ConfigurableMetricsAware<AbstractMessageHandlerMetrics> {
private final Lifecycle lifecycle; private final Lifecycle lifecycle;
protected final org.springframework.integration.support.management.MessageHandlerMetrics delegate; protected final org.springframework.integration.support.management.MessageHandlerMetrics delegate; // NOSONAR
public LifecycleMessageHandlerMetrics(Lifecycle lifecycle, public LifecycleMessageHandlerMetrics(Lifecycle lifecycle,

View File

@@ -28,7 +28,6 @@ package org.springframework.integration.support.management;
*/ */
@Deprecated @Deprecated
@FunctionalInterface @FunctionalInterface
@SuppressWarnings("deprecation")
public interface MessageSourceMetricsConfigurer { public interface MessageSourceMetricsConfigurer {
void configure(MessageSourceMetrics metrics, String beanName); void configure(MessageSourceMetrics metrics, String beanName);

View File

@@ -47,7 +47,6 @@ import org.springframework.data.mongodb.core.query.Update;
import org.springframework.integration.mongodb.support.BinaryToMessageConverter; import org.springframework.integration.mongodb.support.BinaryToMessageConverter;
import org.springframework.integration.mongodb.support.MessageToBinaryConverter; import org.springframework.integration.mongodb.support.MessageToBinaryConverter;
import org.springframework.integration.store.AbstractMessageGroupStore; import org.springframework.integration.store.AbstractMessageGroupStore;
import org.springframework.integration.store.BasicMessageGroupStore;
import org.springframework.integration.store.MessageGroup; import org.springframework.integration.store.MessageGroup;
import org.springframework.integration.store.MessageMetadata; import org.springframework.integration.store.MessageMetadata;
import org.springframework.integration.support.DefaultMessageBuilderFactory; import org.springframework.integration.support.DefaultMessageBuilderFactory;
@@ -57,7 +56,7 @@ import org.springframework.messaging.Message;
import org.springframework.util.Assert; import org.springframework.util.Assert;
/** /**
* The abstract MongoDB {@link BasicMessageGroupStore} implementation to provide configuration for common options * The abstract MongoDB {@link AbstractMessageGroupStore} implementation to provide configuration for common options
* for implementations of this class. * for implementations of this class.
* *
* @author Artem Bilan * @author Artem Bilan
@@ -85,19 +84,22 @@ public abstract class AbstractConfigurableMongoDbMessageStore extends AbstractMe
@Deprecated @Deprecated
public static final String CREATED_DATE_KEY = "MongoDbMessageStore.CREATED_DATE"; public static final String CREATED_DATE_KEY = "MongoDbMessageStore.CREATED_DATE";
protected final Log logger = LogFactory.getLog(this.getClass()); protected final Log logger = LogFactory.getLog(getClass()); // NOSONAR - final
protected final String collectionName; private RuntimeException NOT_IMPLEMENTED =
new UnsupportedOperationException("The operation isn't implemented for this class.");
protected final MongoDbFactory mongoDbFactory; protected final String collectionName; // NOSONAR - final
protected final MongoDbFactory mongoDbFactory; // NOSONAR - final
protected MongoTemplate mongoTemplate; protected MongoTemplate mongoTemplate;
protected MappingMongoConverter mappingMongoConverter; private MappingMongoConverter mappingMongoConverter;
protected ApplicationContext applicationContext; private ApplicationContext applicationContext;
protected MessageBuilderFactory messageBuilderFactory = new DefaultMessageBuilderFactory(); private MessageBuilderFactory messageBuilderFactory = new DefaultMessageBuilderFactory();
public AbstractConfigurableMongoDbMessageStore(MongoTemplate mongoTemplate, String collectionName) { public AbstractConfigurableMongoDbMessageStore(MongoTemplate mongoTemplate, String collectionName) {
Assert.notNull(mongoTemplate, "'mongoTemplate' must not be null"); Assert.notNull(mongoTemplate, "'mongoTemplate' must not be null");
@@ -125,6 +127,22 @@ public abstract class AbstractConfigurableMongoDbMessageStore extends AbstractMe
this.applicationContext = applicationContext; this.applicationContext = applicationContext;
} }
protected MongoTemplate getMongoTemplate() {
return this.mongoTemplate;
}
protected MappingMongoConverter getMappingMongoConverter() {
return this.mappingMongoConverter;
}
protected ApplicationContext getApplicationContext() {
return this.applicationContext;
}
protected MessageBuilderFactory getMessageBuilderFactory() {
return this.messageBuilderFactory;
}
@Override @Override
public void afterPropertiesSet() { public void afterPropertiesSet() {
if (this.mongoTemplate == null) { if (this.mongoTemplate == null) {
@@ -132,7 +150,7 @@ public abstract class AbstractConfigurableMongoDbMessageStore extends AbstractMe
this.mappingMongoConverter = new MappingMongoConverter(new DefaultDbRefResolver(this.mongoDbFactory), this.mappingMongoConverter = new MappingMongoConverter(new DefaultDbRefResolver(this.mongoDbFactory),
new MongoMappingContext()); new MongoMappingContext());
this.mappingMongoConverter.setApplicationContext(this.applicationContext); this.mappingMongoConverter.setApplicationContext(this.applicationContext);
List<Object> customConverters = new ArrayList<Object>(); List<Object> customConverters = new ArrayList<>();
customConverters.add(new MessageToBinaryConverter()); customConverters.add(new MessageToBinaryConverter());
customConverters.add(new BinaryToMessageConverter()); customConverters.add(new BinaryToMessageConverter());
this.mappingMongoConverter.setCustomConversions(new MongoCustomConversions(customConverters)); this.mappingMongoConverter.setCustomConversions(new MongoCustomConversions(customConverters));
@@ -202,7 +220,7 @@ public abstract class AbstractConfigurableMongoDbMessageStore extends AbstractMe
new Update().inc(MessageDocumentFields.SEQUENCE, 1), new Update().inc(MessageDocumentFields.SEQUENCE, 1),
FindAndModifyOptions.options().returnNew(true).upsert(true), FindAndModifyOptions.options().returnNew(true).upsert(true),
Map.class, this.collectionName) Map.class, this.collectionName)
.get(MessageDocumentFields.SEQUENCE); // NOSONAR - never returns null .get(MessageDocumentFields.SEQUENCE); // NOSONAR - never returns null
} }
protected void addMessageDocument(final MessageDocument document) { protected void addMessageDocument(final MessageDocument document) {
@@ -227,37 +245,37 @@ public abstract class AbstractConfigurableMongoDbMessageStore extends AbstractMe
@Override @Override
public void removeMessagesFromGroup(Object key, Collection<Message<?>> messages) { public void removeMessagesFromGroup(Object key, Collection<Message<?>> messages) {
throw new UnsupportedOperationException("The operation isn't implemented for this class."); throw NOT_IMPLEMENTED;
} }
@Override @Override
public void setLastReleasedSequenceNumberForGroup(Object groupId, int sequenceNumber) { public void setLastReleasedSequenceNumberForGroup(Object groupId, int sequenceNumber) {
throw new UnsupportedOperationException("The operation isn't implemented for this class."); throw NOT_IMPLEMENTED;
} }
@Override @Override
public Iterator<MessageGroup> iterator() { public Iterator<MessageGroup> iterator() {
throw new UnsupportedOperationException("The operation isn't implemented for this class."); throw NOT_IMPLEMENTED;
} }
@Override @Override
public void completeGroup(Object groupId) { public void completeGroup(Object groupId) {
throw new UnsupportedOperationException("The operation isn't implemented for this class."); throw NOT_IMPLEMENTED;
} }
@Override @Override
public Message<?> getOneMessageFromGroup(Object groupId) { public Message<?> getOneMessageFromGroup(Object groupId) {
throw new UnsupportedOperationException("The operation isn't implemented for this class."); throw NOT_IMPLEMENTED;
} }
@Override @Override
public void addMessagesToGroup(Object groupId, Message<?>... messages) { public void addMessagesToGroup(Object groupId, Message<?>... messages) {
throw new UnsupportedOperationException("The operation isn't implemented for this class."); throw NOT_IMPLEMENTED;
} }
@Override @Override
public Collection<Message<?>> getMessagesForGroup(Object groupId) { public Collection<Message<?>> getMessagesForGroup(Object groupId) {
throw new UnsupportedOperationException("The operation isn't implemented for this class."); throw NOT_IMPLEMENTED;
} }
} }

View File

@@ -95,7 +95,7 @@ public class ConfigurableMongoDbMessageStore extends AbstractConfigurableMongoDb
public Message<?> removeMessage(UUID id) { public Message<?> removeMessage(UUID id) {
Assert.notNull(id, "'id' must not be null"); Assert.notNull(id, "'id' must not be null");
Query query = Query.query(Criteria.where(MessageDocumentFields.MESSAGE_ID).is(id)); Query query = Query.query(Criteria.where(MessageDocumentFields.MESSAGE_ID).is(id));
MessageDocument document = this.mongoTemplate.findAndRemove(query, MessageDocument.class, this.collectionName); MessageDocument document = getMongoTemplate().findAndRemove(query, MessageDocument.class, this.collectionName);
return (document != null) ? document.getMessage() : null; return (document != null) ? document.getMessage() : null;
} }
@@ -103,7 +103,7 @@ public class ConfigurableMongoDbMessageStore extends AbstractConfigurableMongoDb
public long getMessageCount() { public long getMessageCount() {
Query query = Query.query(Criteria.where(MessageDocumentFields.MESSAGE_ID).exists(true) Query query = Query.query(Criteria.where(MessageDocumentFields.MESSAGE_ID).exists(true)
.and(MessageDocumentFields.GROUP_ID).exists(false)); .and(MessageDocumentFields.GROUP_ID).exists(false));
return this.mongoTemplate.getCollection(this.collectionName).countDocuments(query.getQueryObject()); return getMongoTemplate().getCollection(this.collectionName).countDocuments(query.getQueryObject());
} }
@@ -112,7 +112,7 @@ public class ConfigurableMongoDbMessageStore extends AbstractConfigurableMongoDb
Assert.notNull(groupId, "'groupId' must not be null"); Assert.notNull(groupId, "'groupId' must not be null");
Query query = groupOrderQuery(groupId); Query query = groupOrderQuery(groupId);
MessageDocument messageDocument = this.mongoTemplate.findOne(query, MessageDocument.class, this.collectionName); MessageDocument messageDocument = getMongoTemplate().findOne(query, MessageDocument.class, this.collectionName);
if (messageDocument != null) { if (messageDocument != null) {
long createdTime = messageDocument.getGroupCreatedTime(); long createdTime = messageDocument.getGroupCreatedTime();
@@ -144,7 +144,7 @@ public class ConfigurableMongoDbMessageStore extends AbstractConfigurableMongoDb
Assert.notNull(messages, "'message' must not be null"); Assert.notNull(messages, "'message' must not be null");
Query query = groupOrderQuery(groupId); Query query = groupOrderQuery(groupId);
MessageDocument messageDocument = this.mongoTemplate.findOne(query, MessageDocument.class, this.collectionName); MessageDocument messageDocument = getMongoTemplate().findOne(query, MessageDocument.class, this.collectionName);
long createdTime = System.currentTimeMillis(); long createdTime = System.currentTimeMillis();
int lastReleasedSequence = 0; int lastReleasedSequence = 0;
@@ -191,7 +191,7 @@ public class ConfigurableMongoDbMessageStore extends AbstractConfigurableMongoDb
private void removeMessages(Object groupId, Collection<UUID> ids) { private void removeMessages(Object groupId, Collection<UUID> ids) {
Query query = groupIdQuery(groupId) Query query = groupIdQuery(groupId)
.addCriteria(Criteria.where(MessageDocumentFields.MESSAGE_ID).in(ids.toArray())); .addCriteria(Criteria.where(MessageDocumentFields.MESSAGE_ID).in(ids.toArray()));
this.mongoTemplate.remove(query, this.collectionName); getMongoTemplate().remove(query, this.collectionName);
} }
@Override @Override
@@ -236,7 +236,7 @@ public class ConfigurableMongoDbMessageStore extends AbstractConfigurableMongoDb
public int getMessageCountForAllMessageGroups() { public int getMessageCountForAllMessageGroups() {
Query query = Query.query(Criteria.where(MessageDocumentFields.MESSAGE_ID).exists(true) Query query = Query.query(Criteria.where(MessageDocumentFields.MESSAGE_ID).exists(true)
.and(MessageDocumentFields.GROUP_ID).exists(true)); .and(MessageDocumentFields.GROUP_ID).exists(true));
long count = this.mongoTemplate.count(query, this.collectionName); long count = getMongoTemplate().count(query, this.collectionName);
Assert.isTrue(count <= Integer.MAX_VALUE, "Message count is out of Integer's range"); Assert.isTrue(count <= Integer.MAX_VALUE, "Message count is out of Integer's range");
return (int) count; return (int) count;
} }
@@ -245,7 +245,7 @@ public class ConfigurableMongoDbMessageStore extends AbstractConfigurableMongoDb
@ManagedAttribute @ManagedAttribute
public int getMessageGroupCount() { public int getMessageGroupCount() {
Query query = Query.query(Criteria.where(MessageDocumentFields.GROUP_ID).exists(true)); Query query = Query.query(Criteria.where(MessageDocumentFields.GROUP_ID).exists(true));
return this.mongoTemplate.getCollection(this.collectionName) return getMongoTemplate().getCollection(this.collectionName)
.distinct(MessageDocumentFields.GROUP_ID, query.getQueryObject(), Object.class) .distinct(MessageDocumentFields.GROUP_ID, query.getQueryObject(), Object.class)
.into(new ArrayList<>()) .into(new ArrayList<>())
.size(); .size();
@@ -255,7 +255,7 @@ public class ConfigurableMongoDbMessageStore extends AbstractConfigurableMongoDb
public Message<?> getOneMessageFromGroup(Object groupId) { public Message<?> getOneMessageFromGroup(Object groupId) {
Assert.notNull(groupId, "'groupId' must not be null"); Assert.notNull(groupId, "'groupId' must not be null");
Query query = groupOrderQuery(groupId); Query query = groupOrderQuery(groupId);
MessageDocument messageDocument = this.mongoTemplate.findOne(query, MessageDocument.class, this.collectionName); MessageDocument messageDocument = getMongoTemplate().findOne(query, MessageDocument.class, this.collectionName);
if (messageDocument != null) { if (messageDocument != null) {
return messageDocument.getMessage(); return messageDocument.getMessage();
} }
@@ -268,7 +268,7 @@ public class ConfigurableMongoDbMessageStore extends AbstractConfigurableMongoDb
public Collection<Message<?>> getMessagesForGroup(Object groupId) { public Collection<Message<?>> getMessagesForGroup(Object groupId) {
Assert.notNull(groupId, "'groupId' must not be null"); Assert.notNull(groupId, "'groupId' must not be null");
Query query = groupOrderQuery(groupId); Query query = groupOrderQuery(groupId);
List<MessageDocument> documents = this.mongoTemplate.find(query, MessageDocument.class, this.collectionName); List<MessageDocument> documents = getMongoTemplate().find(query, MessageDocument.class, this.collectionName);
return documents.stream() return documents.stream()
.map(MessageDocument::getMessage) .map(MessageDocument::getMessage)
@@ -276,7 +276,7 @@ public class ConfigurableMongoDbMessageStore extends AbstractConfigurableMongoDb
} }
private void updateGroup(Object groupId, Update update) { private void updateGroup(Object groupId, Update update) {
this.mongoTemplate.updateFirst(groupOrderQuery(groupId), update, this.collectionName); getMongoTemplate().updateFirst(groupOrderQuery(groupId), update, this.collectionName);
} }
private static Update lastModifiedUpdate() { private static Update lastModifiedUpdate() {

View File

@@ -90,7 +90,7 @@ public class MongoDbChannelMessageStore extends AbstractConfigurableMongoDbMessa
@Override @Override
public void afterPropertiesSet() { public void afterPropertiesSet() {
super.afterPropertiesSet(); super.afterPropertiesSet();
this.mongoTemplate.indexOps(this.collectionName) getMongoTemplate().indexOps(this.collectionName)
.ensureIndex(new Index(MessageDocumentFields.GROUP_ID, Sort.Direction.ASC) .ensureIndex(new Index(MessageDocumentFields.GROUP_ID, Sort.Direction.ASC)
.on(MessageDocumentFields.PRIORITY, Sort.Direction.DESC) .on(MessageDocumentFields.PRIORITY, Sort.Direction.DESC)
.on(MessageDocumentFields.LAST_MODIFIED_TIME, Sort.Direction.ASC) .on(MessageDocumentFields.LAST_MODIFIED_TIME, Sort.Direction.ASC)
@@ -132,7 +132,7 @@ public class MongoDbChannelMessageStore extends AbstractConfigurableMongoDbMessa
sort = Sort.by(Sort.Direction.DESC, MessageDocumentFields.PRIORITY).and(sort); sort = Sort.by(Sort.Direction.DESC, MessageDocumentFields.PRIORITY).and(sort);
} }
Query query = groupIdQuery(groupId).with(sort); Query query = groupIdQuery(groupId).with(sort);
MessageDocument document = this.mongoTemplate.findAndRemove(query, MessageDocument.class, this.collectionName); MessageDocument document = getMongoTemplate().findAndRemove(query, MessageDocument.class, this.collectionName);
Message<?> message = null; Message<?> message = null;
if (document != null) { if (document != null) {
message = document.getMessage(); message = document.getMessage();