Skip to content

Commit 4347383

Browse files
Remove unused ThreadLocal from RedisStoreMSource (#8663)
* 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` * Fix language in Docs Co-authored-by: Gary Russell <[email protected]> --------- Co-authored-by: Gary Russell <[email protected]>
1 parent 229e3cc commit 4347383

File tree

2 files changed

+13
-27
lines changed

2 files changed

+13
-27
lines changed

spring-integration-redis/src/main/java/org/springframework/integration/redis/inbound/RedisStoreMessageSource.java

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -46,18 +46,16 @@
4646
*/
4747
public class RedisStoreMessageSource extends AbstractMessageSource<RedisStore> {
4848

49-
private final ThreadLocal<RedisStore> resourceHolder = new ThreadLocal<>();
50-
51-
private volatile StandardEvaluationContext evaluationContext;
49+
private final RedisTemplate<String, ?> redisTemplate;
5250

53-
private volatile Expression keyExpression;
51+
private final Expression keyExpression;
5452

55-
private volatile CollectionType collectionType = CollectionType.LIST;
53+
private StandardEvaluationContext evaluationContext;
5654

57-
private final RedisTemplate<String, ?> redisTemplate;
55+
private CollectionType collectionType = CollectionType.LIST;
5856

5957
/**
60-
* Creates an instance with the provided {@link RedisTemplate} and SpEL expression
58+
* Create an instance with the provided {@link RedisTemplate} and SpEL expression
6159
* which should resolve to a 'key' name of the collection to be used.
6260
* It assumes that {@link RedisTemplate} is fully initialized and ready to be used.
6361
* The 'keyExpression' will be evaluated on every call to the {@link #receive()} method.
@@ -73,7 +71,7 @@ public RedisStoreMessageSource(RedisTemplate<String, ?> redisTemplate, Expressio
7371
}
7472

7573
/**
76-
* Creates an instance with the provided {@link RedisConnectionFactory} and SpEL expression
74+
* Create an instance with the provided {@link RedisConnectionFactory} and SpEL expression
7775
* which should resolve to a 'key' name of the collection to be used.
7876
* It will create and initialize an instance of {@link StringRedisTemplate} that uses
7977
* {@link org.springframework.data.redis.serializer.StringRedisSerializer} for all
@@ -82,9 +80,7 @@ public RedisStoreMessageSource(RedisTemplate<String, ?> redisTemplate, Expressio
8280
* @param connectionFactory The connection factory.
8381
* @param keyExpression The key expression.
8482
*/
85-
public RedisStoreMessageSource(RedisConnectionFactory connectionFactory,
86-
Expression keyExpression) {
87-
83+
public RedisStoreMessageSource(RedisConnectionFactory connectionFactory, Expression keyExpression) {
8884
Assert.notNull(keyExpression, "'keyExpression' must not be null");
8985
Assert.notNull(connectionFactory, "'connectionFactory' must not be null");
9086

@@ -105,15 +101,15 @@ protected void onInit() {
105101
}
106102

107103
/**
108-
* Returns a Message with the view into a {@link RedisStore} identified
104+
* Return a Message with the view into a {@link RedisStore} identified
109105
* by {@link #keyExpression}
110106
*/
111107
@Override
112108
protected RedisStore doReceive() {
113109
String key = this.keyExpression.getValue(this.evaluationContext, String.class);
114110
Assert.hasText(key, "Failed to determine the key for the collection");
115111

116-
RedisStore store = this.createStoreView(key);
112+
RedisStore store = createStoreView(key);
117113

118114
Object holder = TransactionSynchronizationManager.getResource(this);
119115
if (holder != null) {
@@ -143,16 +139,4 @@ public String getComponentType() {
143139
return "redis:store-inbound-channel-adapter";
144140
}
145141

146-
public RedisStore getResource() {
147-
return this.resourceHolder.get();
148-
}
149-
150-
public void afterCommit(Object object) {
151-
this.resourceHolder.remove();
152-
}
153-
154-
public void afterRollback(Object object) {
155-
this.resourceHolder.remove();
156-
}
157-
158142
}

src/reference/asciidoc/redis.adoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,8 @@ If only the `expression` attribute is present and the result of an expression is
558558
If you want the evaluation result to go to a specific channel, add a `channel` attribute.
559559
If the result of an expression is null or void, no message is generated.
560560

561+
The `RedisStoreMessageSource` adds a `store` attribute with a `RedisStore` instance bound to the transaction `IntegrationResourceHolder`, which can be accessed from a `TransactionSynchronizationProcessor` implementation.
562+
561563
For more information about transaction synchronization, see <<./transactions.adoc#transaction-synchronization,Transaction Synchronization>>.
562564

563565
[[redis-store-outbound-channel-adapter]]
@@ -895,4 +897,4 @@ Default.
895897
- `RedisLockType.PUB_SUB_LOCK` - The lock is acquired by redis pub-sub subscription.
896898

897899
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.
898-
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.
900+
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.

0 commit comments

Comments
 (0)