From 213b15a713b3576c67d09e3560d4cd81861beac5 Mon Sep 17 00:00:00 2001 From: abilan Date: Wed, 28 Jun 2023 12:06:13 -0400 Subject: [PATCH 1/2] Remove unused ThreadLocal from RedisStoreMSource The `RedisStoreMessageSource` relies on an `IntegrationResourceHolder` for a while already. Its internal `ThreadLocal` is just out of use. * Remove that `resourceHolder` property and related methods to interact with it. * Mention the `IntegrationResourceHolder` and `store` attribute in the `redis.adoc` --- .../inbound/RedisStoreMessageSource.java | 36 ++++++------------- src/reference/asciidoc/redis.adoc | 4 ++- 2 files changed, 13 insertions(+), 27 deletions(-) diff --git a/spring-integration-redis/src/main/java/org/springframework/integration/redis/inbound/RedisStoreMessageSource.java b/spring-integration-redis/src/main/java/org/springframework/integration/redis/inbound/RedisStoreMessageSource.java index 5c0802fe4f5..24f7dcd619a 100644 --- a/spring-integration-redis/src/main/java/org/springframework/integration/redis/inbound/RedisStoreMessageSource.java +++ b/spring-integration-redis/src/main/java/org/springframework/integration/redis/inbound/RedisStoreMessageSource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,18 +46,16 @@ */ public class RedisStoreMessageSource extends AbstractMessageSource { - private final ThreadLocal resourceHolder = new ThreadLocal<>(); - - private volatile StandardEvaluationContext evaluationContext; + private final RedisTemplate redisTemplate; - private volatile Expression keyExpression; + private final Expression keyExpression; - private volatile CollectionType collectionType = CollectionType.LIST; + private StandardEvaluationContext evaluationContext; - private final RedisTemplate redisTemplate; + private CollectionType collectionType = CollectionType.LIST; /** - * Creates an instance with the provided {@link RedisTemplate} and SpEL expression + * Create an instance with the provided {@link RedisTemplate} and SpEL expression * which should resolve to a 'key' name of the collection to be used. * It assumes that {@link RedisTemplate} is fully initialized and ready to be used. * The 'keyExpression' will be evaluated on every call to the {@link #receive()} method. @@ -73,7 +71,7 @@ public RedisStoreMessageSource(RedisTemplate redisTemplate, Expressio } /** - * Creates an instance with the provided {@link RedisConnectionFactory} and SpEL expression + * Create an instance with the provided {@link RedisConnectionFactory} and SpEL expression * which should resolve to a 'key' name of the collection to be used. * It will create and initialize an instance of {@link StringRedisTemplate} that uses * {@link org.springframework.data.redis.serializer.StringRedisSerializer} for all @@ -82,9 +80,7 @@ public RedisStoreMessageSource(RedisTemplate redisTemplate, Expressio * @param connectionFactory The connection factory. * @param keyExpression The key expression. */ - public RedisStoreMessageSource(RedisConnectionFactory connectionFactory, - Expression keyExpression) { - + public RedisStoreMessageSource(RedisConnectionFactory connectionFactory, Expression keyExpression) { Assert.notNull(keyExpression, "'keyExpression' must not be null"); Assert.notNull(connectionFactory, "'connectionFactory' must not be null"); @@ -105,7 +101,7 @@ protected void onInit() { } /** - * Returns a Message with the view into a {@link RedisStore} identified + * Return a Message with the view into a {@link RedisStore} identified * by {@link #keyExpression} */ @Override @@ -113,7 +109,7 @@ protected RedisStore doReceive() { String key = this.keyExpression.getValue(this.evaluationContext, String.class); Assert.hasText(key, "Failed to determine the key for the collection"); - RedisStore store = this.createStoreView(key); + RedisStore store = createStoreView(key); Object holder = TransactionSynchronizationManager.getResource(this); if (holder != null) { @@ -143,16 +139,4 @@ public String getComponentType() { return "redis:store-inbound-channel-adapter"; } - public RedisStore getResource() { - return this.resourceHolder.get(); - } - - public void afterCommit(Object object) { - this.resourceHolder.remove(); - } - - public void afterRollback(Object object) { - this.resourceHolder.remove(); - } - } diff --git a/src/reference/asciidoc/redis.adoc b/src/reference/asciidoc/redis.adoc index 917bdb08919..76d9430dc3b 100644 --- a/src/reference/asciidoc/redis.adoc +++ b/src/reference/asciidoc/redis.adoc @@ -558,6 +558,8 @@ If only the `expression` attribute is present and the result of an expression is If you want the evaluation result to go to a specific channel, add a `channel` attribute. If the result of an expression is null or void, no message is generated. +The `RedisStoreMessageSource` adds a `store` attribute with a produced `RedisStore` instance into bound to the transaction `IntegrationResourceHolder` which can be accessed from a `TransactionSynchronizationProcessor` implementation. + For more information about transaction synchronization, see <<./transactions.adoc#transaction-synchronization,Transaction Synchronization>>. [[redis-store-outbound-channel-adapter]] @@ -895,4 +897,4 @@ Default. - `RedisLockType.PUB_SUB_LOCK` - The lock is acquired by redis pub-sub subscription. The pub-sub is preferred mode - less network chatter between client Redis server, and more performant - the lock is acquired immediately when subscription is notified about unlocking in the other process. -However, the Redis does not support pub-sub in the Master/Replica connections (for example in AWS ElastiCache environment), therefore a busy-spin mode is chosen as a default to make the registry working in any environment. \ No newline at end of file +However, the Redis does not support pub-sub in the Master/Replica connections (for example in AWS ElastiCache environment), therefore a busy-spin mode is chosen as a default to make the registry working in any environment. From 2934ac878c838837c6a5a963537d0659ad0bfcc7 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Wed, 28 Jun 2023 12:31:57 -0400 Subject: [PATCH 2/2] Fix language in Docs Co-authored-by: Gary Russell --- src/reference/asciidoc/redis.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/reference/asciidoc/redis.adoc b/src/reference/asciidoc/redis.adoc index 76d9430dc3b..28a5fa0729f 100644 --- a/src/reference/asciidoc/redis.adoc +++ b/src/reference/asciidoc/redis.adoc @@ -558,7 +558,7 @@ If only the `expression` attribute is present and the result of an expression is If you want the evaluation result to go to a specific channel, add a `channel` attribute. If the result of an expression is null or void, no message is generated. -The `RedisStoreMessageSource` adds a `store` attribute with a produced `RedisStore` instance into bound to the transaction `IntegrationResourceHolder` which can be accessed from a `TransactionSynchronizationProcessor` implementation. +The `RedisStoreMessageSource` adds a `store` attribute with a `RedisStore` instance bound to the transaction `IntegrationResourceHolder`, which can be accessed from a `TransactionSynchronizationProcessor` implementation. For more information about transaction synchronization, see <<./transactions.adoc#transaction-synchronization,Transaction Synchronization>>.