Skip to content

Remove unused ThreadLocal from RedisStoreMSource #8663

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -46,18 +46,16 @@
*/
public class RedisStoreMessageSource extends AbstractMessageSource<RedisStore> {

private final ThreadLocal<RedisStore> resourceHolder = new ThreadLocal<>();

private volatile StandardEvaluationContext evaluationContext;
private final RedisTemplate<String, ?> redisTemplate;

private volatile Expression keyExpression;
private final Expression keyExpression;

private volatile CollectionType collectionType = CollectionType.LIST;
private StandardEvaluationContext evaluationContext;

private final RedisTemplate<String, ?> 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.
Expand All @@ -73,7 +71,7 @@ public RedisStoreMessageSource(RedisTemplate<String, ?> 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
Expand All @@ -82,9 +80,7 @@ public RedisStoreMessageSource(RedisTemplate<String, ?> 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");

Expand All @@ -105,15 +101,15 @@ 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
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) {
Expand Down Expand Up @@ -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();
}

}
4 changes: 3 additions & 1 deletion src/reference/asciidoc/redis.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down Expand Up @@ -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.
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.