diff --git a/spring-integration-cassandra/src/main/java/org/springframework/integration/cassandra/outbound/CassandraMessageHandler.java b/spring-integration-cassandra/src/main/java/org/springframework/integration/cassandra/outbound/CassandraMessageHandler.java index fd0c03addf..1cda760693 100644 --- a/spring-integration-cassandra/src/main/java/org/springframework/integration/cassandra/outbound/CassandraMessageHandler.java +++ b/spring-integration-cassandra/src/main/java/org/springframework/integration/cassandra/outbound/CassandraMessageHandler.java @@ -346,7 +346,7 @@ public class CassandraMessageHandler extends AbstractReplyProducingMessageHandle } - private final class ReactiveWriteResult extends WriteResult { + private static final class ReactiveWriteResult extends WriteResult { ReactiveWriteResult(ReactiveResultSet reactiveResultSet) { super(reactiveResultSet.getAllExecutionInfo(), diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AnnotationConfigParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AnnotationConfigParser.java index 2839d45839..a414111d38 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AnnotationConfigParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AnnotationConfigParser.java @@ -89,7 +89,7 @@ public class AnnotationConfigParser implements BeanDefinitionParser { @Override public Set getDeclaredMethods() { - return null; + throw new UnsupportedOperationException("The class doesn't support this operation"); } } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/MessageHistoryParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/MessageHistoryParser.java index d28ff87994..21fac2a914 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/MessageHistoryParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/MessageHistoryParser.java @@ -55,7 +55,7 @@ public class MessageHistoryParser implements BeanDefinitionParser { @Override public Set getDeclaredMethods() { - return null; + throw new UnsupportedOperationException("The class doesn't support this operation"); } }, parserContext.getRegistry()); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/support/MessagingMethodInvokerHelper.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/support/MessagingMethodInvokerHelper.java index 47e375e3ab..07d106c833 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/handler/support/MessagingMethodInvokerHelper.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/support/MessagingMethodInvokerHelper.java @@ -161,8 +161,6 @@ public class MessagingMethodInvokerHelper extends AbstractExpressionEvaluator im SPEL_COMPILERS.put(SpelCompilerMode.MIXED, EXPRESSION_PARSER_MIXED); } - private MessageHandlerMethodFactory messageHandlerMethodFactory; - private final Object targetObject; private final JsonObjectMapper jsonObjectMapper; @@ -197,6 +195,8 @@ public class MessagingMethodInvokerHelper extends AbstractExpressionEvaluator im private boolean useSpelInvoker; + private volatile MessageHandlerMethodFactory messageHandlerMethodFactory; + private volatile boolean initialized; public MessagingMethodInvokerHelper(Object targetObject, Method method, Class expectedType, @@ -515,10 +515,26 @@ public class MessagingMethodInvokerHelper extends AbstractExpressionEvaluator im : IntegrationContextUtils.MESSAGE_HANDLER_FACTORY_BEAN_NAME); } + private void configureLocalMessageHandlerFactory() { + BeanFactory beanFactory = getBeanFactory(); + + ConfigurableCompositeMessageConverter messageConverter = new ConfigurableCompositeMessageConverter(); + messageConverter.setBeanFactory(beanFactory); + messageConverter.afterPropertiesSet(); + + IntegrationMessageHandlerMethodFactory localHandlerMethodFactory = + new IntegrationMessageHandlerMethodFactory(this.canProcessMessageList); + localHandlerMethodFactory.setMessageConverter(messageConverter); + localHandlerMethodFactory.setBeanFactory(beanFactory); + localHandlerMethodFactory.afterPropertiesSet(); + + this.messageHandlerMethodFactory = localHandlerMethodFactory; + } /* - * This should not be needed in production but we have many tests + * This should not be needed in production, but we have many tests * that don't run in an application context. */ + private void initializeHandler(HandlerMethod candidate) { ExpressionParser parser; if (candidate.useSpelInvoker == null) { @@ -537,22 +553,6 @@ public class MessagingMethodInvokerHelper extends AbstractExpressionEvaluator im candidate.initialized = true; } - private void configureLocalMessageHandlerFactory() { - BeanFactory beanFactory = getBeanFactory(); - - ConfigurableCompositeMessageConverter messageConverter = new ConfigurableCompositeMessageConverter(); - messageConverter.setBeanFactory(beanFactory); - messageConverter.afterPropertiesSet(); - - IntegrationMessageHandlerMethodFactory localHandlerMethodFactory = - new IntegrationMessageHandlerMethodFactory(this.canProcessMessageList); - localHandlerMethodFactory.setMessageConverter(messageConverter); - localHandlerMethodFactory.setBeanFactory(beanFactory); - localHandlerMethodFactory.afterPropertiesSet(); - - this.messageHandlerMethodFactory = localHandlerMethodFactory; - } - @Nullable private Object invokeHandlerMethod(HandlerMethod handlerMethod, ParametersWrapper parameters) { try { diff --git a/spring-integration-http/src/main/java/org/springframework/integration/http/config/IntegrationGraphControllerParser.java b/spring-integration-http/src/main/java/org/springframework/integration/http/config/IntegrationGraphControllerParser.java index 05ef3509ab..4556d66ee6 100644 --- a/spring-integration-http/src/main/java/org/springframework/integration/http/config/IntegrationGraphControllerParser.java +++ b/spring-integration-http/src/main/java/org/springframework/integration/http/config/IntegrationGraphControllerParser.java @@ -52,7 +52,7 @@ public class IntegrationGraphControllerParser implements BeanDefinitionParser { @Override public Set getDeclaredMethods() { - return null; + throw new UnsupportedOperationException("The class doesn't support this operation"); } }, parserContext.getRegistry()); diff --git a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/channel/PostgresChannelMessageTableSubscriber.java b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/channel/PostgresChannelMessageTableSubscriber.java index f8f5b29623..e6ad7c6ca2 100644 --- a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/channel/PostgresChannelMessageTableSubscriber.java +++ b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/channel/PostgresChannelMessageTableSubscriber.java @@ -108,7 +108,7 @@ public final class PostgresChannelMessageTableSubscriber implements SmartLifecyc * while running. * @param executor The executor to use or {@code null} if an executor should be created by this class. */ - public void setExecutor(@Nullable ExecutorService executor) { + public synchronized void setExecutor(@Nullable ExecutorService executor) { this.executor = executor; } diff --git a/spring-integration-zookeeper/src/main/java/org/springframework/integration/zookeeper/metadata/ZookeeperMetadataStore.java b/spring-integration-zookeeper/src/main/java/org/springframework/integration/zookeeper/metadata/ZookeeperMetadataStore.java index d9fb0a8fe2..23a0e93be1 100644 --- a/spring-integration-zookeeper/src/main/java/org/springframework/integration/zookeeper/metadata/ZookeeperMetadataStore.java +++ b/spring-integration-zookeeper/src/main/java/org/springframework/integration/zookeeper/metadata/ZookeeperMetadataStore.java @@ -110,46 +110,42 @@ public class ZookeeperMetadataStore implements ListenableMetadataStore, SmartLif } @Override - public String putIfAbsent(String key, String value) { + public synchronized String putIfAbsent(String key, String value) { Assert.notNull(key, KEY_MUST_NOT_BE_NULL); Assert.notNull(value, "'value' must not be null."); - synchronized (this.updateMap) { - try { - createNode(key, value); - return null; - } - catch (KeeperException.NodeExistsException ex) { - // so the data actually exists, we can read it - return get(key); - } - catch (Exception ex) { - throw new ZookeeperMetadataStoreException("Error while trying to set '" + key + "':", ex); - } + try { + createNode(key, value); + return null; + } + catch (KeeperException.NodeExistsException ex) { + // so the data actually exists, we can read it + return get(key); + } + catch (Exception ex) { + throw new ZookeeperMetadataStoreException("Error while trying to set '" + key + "':", ex); } } @Override - public boolean replace(String key, String oldValue, String newValue) { + public synchronized boolean replace(String key, String oldValue, String newValue) { Assert.notNull(key, KEY_MUST_NOT_BE_NULL); Assert.notNull(oldValue, "'oldValue' must not be null."); Assert.notNull(newValue, "'newValue' must not be null."); - synchronized (this.updateMap) { - Stat currentStat = new Stat(); - try { - byte[] bytes = this.client.getData().storingStatIn(currentStat).forPath(getPath(key)); - if (oldValue.equals(IntegrationUtils.bytesToString(bytes, this.encoding))) { - updateNode(key, newValue, currentStat.getVersion()); - } - return true; - } - catch (KeeperException.NoNodeException | KeeperException.BadVersionException ex) { - // ignore, the node doesn't exist there's nothing to replace - return false; - } - // ignore - catch (Exception ex) { - throw new ZookeeperMetadataStoreException("Cannot replace value", ex); + Stat currentStat = new Stat(); + try { + byte[] bytes = this.client.getData().storingStatIn(currentStat).forPath(getPath(key)); + if (oldValue.equals(IntegrationUtils.bytesToString(bytes, this.encoding))) { + updateNode(key, newValue, currentStat.getVersion()); } + return true; + } + catch (KeeperException.NoNodeException | KeeperException.BadVersionException ex) { + // ignore, the node doesn't exist there's nothing to replace + return false; + } + // ignore + catch (Exception ex) { + throw new ZookeeperMetadataStoreException("Cannot replace value", ex); } } @@ -165,77 +161,71 @@ public class ZookeeperMetadataStore implements ListenableMetadataStore, SmartLif } @Override - public void put(String key, String value) { + public synchronized void put(String key, String value) { Assert.notNull(key, KEY_MUST_NOT_BE_NULL); Assert.notNull(value, "'value' must not be null."); - synchronized (this.updateMap) { - try { - Stat currentNode = this.client.checkExists().forPath(getPath(key)); - if (currentNode == null) { - try { - createNode(key, value); - } - catch (KeeperException.NodeExistsException e) { - updateNode(key, value, -1); - } + try { + Stat currentNode = this.client.checkExists().forPath(getPath(key)); + if (currentNode == null) { + try { + createNode(key, value); } - else { + catch (KeeperException.NodeExistsException e) { updateNode(key, value, -1); } } - catch (Exception ex) { - throw new ZookeeperMetadataStoreException("Error while setting value for key '" + key + "':", ex); + else { + updateNode(key, value, -1); } } + catch (Exception ex) { + throw new ZookeeperMetadataStoreException("Error while setting value for key '" + key + "':", ex); + } } @Override - public String get(String key) { + public synchronized String get(String key) { Assert.notNull(key, KEY_MUST_NOT_BE_NULL); Assert.state(isRunning(), "ZookeeperMetadataStore has to be started before using."); - synchronized (this.updateMap) { - return this.cache.get(getPath(key)) - .map(currentData -> { - // our version is more recent than the cache - if (this.updateMap.containsKey(key) && - this.updateMap.get(key).version() >= currentData.getStat().getVersion()) { + return this.cache.get(getPath(key)) + .map(currentData -> { + // our version is more recent than the cache + if (this.updateMap.containsKey(key) && + this.updateMap.get(key).version() >= currentData.getStat().getVersion()) { - return this.updateMap.get(key).value(); - } - return IntegrationUtils.bytesToString(currentData.getData(), this.encoding); - }) - .orElseGet(() -> { - if (this.updateMap.containsKey(key)) { - // we have saved the value, but the cache hasn't updated yet - // if the value had changed via replication, we would have been notified by the listener - return this.updateMap.get(key).value(); - } - else { - // the value just doesn't exist - return null; - } - }); - } + return this.updateMap.get(key).value(); + } + return IntegrationUtils.bytesToString(currentData.getData(), this.encoding); + }) + .orElseGet(() -> { + if (this.updateMap.containsKey(key)) { + // we have saved the value, but the cache hasn't updated yet + // if the value had changed via replication, we would have been notified by the listener + return this.updateMap.get(key).value(); + } + else { + // the value just doesn't exist + return null; + } + }); } @Override - public String remove(String key) { + public synchronized String remove(String key) { Assert.notNull(key, KEY_MUST_NOT_BE_NULL); - synchronized (this.updateMap) { - try { - byte[] bytes = this.client.getData().forPath(getPath(key)); - this.client.delete().forPath(getPath(key)); - // we guarantee that the deletion will supersede the existing data - this.updateMap.put(key, new LocalChildData(null, Integer.MAX_VALUE)); - return IntegrationUtils.bytesToString(bytes, this.encoding); - } - catch (KeeperException.NoNodeException ex) { - // ignore - the node doesn't exist - return null; - } - catch (Exception ex) { - throw new ZookeeperMetadataStoreException("Exception while deleting key '" + key + "'", ex); - } + try { + byte[] bytes = this.client.getData().forPath(getPath(key)); + this.client.delete().forPath(getPath(key)); + // we guarantee that the deletion will supersede the existing data + this.updateMap.put(key, new LocalChildData(null, Integer.MAX_VALUE)); + return IntegrationUtils.bytesToString(bytes, this.encoding); + } + catch (KeeperException.NoNodeException ex) { + // ignore - the node doesn't exist + return null; + } + catch (Exception ex) { + throw new ZookeeperMetadataStoreException("Exception while deleting key '" + key + "'", ex); } }