Skip to content

Commit 9f8117b

Browse files
committed
1.2.2
- CHANGE: Removed explicit `ParameterNameDiscoverer` from `SpelKeyGenerator` which now uses the one provided by the `CachedExpressionEvaluator` - CHANGE: Used `AopUtils` once and passed the evaluated method to `SpelKeyGenerator` so it doesn't have to evaluate the same thing as `LockMethodInterceptor`
1 parent f292688 commit 9f8117b

File tree

10 files changed

+18
-20
lines changed

10 files changed

+18
-20
lines changed

README.adoc

+7
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ public class LockConfiguration {
124124

125125
Started tracking the changes since 1.2.0 so no changelogs available for earlier versions.
126126

127+
==== 1.2.2
128+
- CHANGE: Removed explicit `ParameterNameDiscoverer` from `SpelKeyGenerator` which now uses the one provided by the `CachedExpressionEvaluator`
129+
- CHANGE: Used `AopUtils` once and passed the evaluated method to `SpelKeyGenerator` so it doesn't have to evaluate the same thing as `LockMethodInterceptor`
130+
127131
==== 1.2.1
128132
- FEATURE: Lock refreshing has been added. Check the 'Lock refresh' chapter for more details
129133
- BUGFIX: `@RedisMultiLocked` was using `#executionPath` as prefix instead of an expression
@@ -162,6 +166,9 @@ Started tracking the changes since 1.2.0 so no changelogs available for earlier
162166

163167
|1.2.1
164168
|2.1.0.RELEASE
169+
170+
|1.2.2
171+
|2.1.0.RELEASE
165172
|===
166173

167174
=== Maven

distributed-lock-api/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>com.github.alturkovic</groupId>
99
<artifactId>distributed-lock</artifactId>
10-
<version>1.2.1</version>
10+
<version>1.2.2</version>
1111
</parent>
1212

1313
<artifactId>distributed-lock-api</artifactId>

distributed-lock-core/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>com.github.alturkovic</groupId>
99
<artifactId>distributed-lock</artifactId>
10-
<version>1.2.1</version>
10+
<version>1.2.2</version>
1111
</parent>
1212

1313
<artifactId>distributed-lock-core</artifactId>

distributed-lock-core/src/main/java/com/github/alturkovic/lock/advice/LockMethodInterceptor.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import org.aopalliance.intercept.MethodInterceptor;
4040
import org.aopalliance.intercept.MethodInvocation;
4141
import org.springframework.aop.support.AopUtils;
42-
import org.springframework.core.BridgeMethodResolver;
4342
import org.springframework.core.annotation.AnnotatedElementUtils;
4443
import org.springframework.retry.RetryPolicy;
4544
import org.springframework.retry.backoff.FixedBackOffPolicy;
@@ -48,7 +47,6 @@
4847
import org.springframework.retry.policy.TimeoutRetryPolicy;
4948
import org.springframework.retry.support.RetryTemplate;
5049
import org.springframework.scheduling.TaskScheduler;
51-
import org.springframework.util.ClassUtils;
5250
import org.springframework.util.StringUtils;
5351

5452
@Slf4j
@@ -61,8 +59,7 @@ public class LockMethodInterceptor implements MethodInterceptor {
6159

6260
@Override
6361
public Object invoke(final MethodInvocation invocation) throws Throwable {
64-
// not really sure if all of these util calls are necessary, but they should all return sensible values in case they are not needed
65-
final Method method = BridgeMethodResolver.findBridgedMethod(ClassUtils.getMostSpecificMethod(invocation.getMethod(), AopUtils.getTargetClass(invocation.getThis())));
62+
final Method method = AopUtils.getMostSpecificMethod(invocation.getMethod(), invocation.getThis().getClass());
6663
final Locked locked = AnnotatedElementUtils.findMergedAnnotation(method, Locked.class);
6764

6865
final Lock lock = lockTypeResolver.get(locked.type());
@@ -77,7 +74,7 @@ public Object invoke(final MethodInvocation invocation) throws Throwable {
7774

7875
final List<String> keys;
7976
try {
80-
keys = keyGenerator.resolveKeys(locked.prefix(), locked.expression(), invocation.getThis(), invocation.getMethod(), invocation.getArguments());
77+
keys = keyGenerator.resolveKeys(locked.prefix(), locked.expression(), invocation.getThis(), method, invocation.getArguments());
8178
} catch (final RuntimeException e) {
8279
throw new DistributedLockException("Cannot resolve keys to lock from expression: " + locked.expression(), e);
8380
}

distributed-lock-core/src/main/java/com/github/alturkovic/lock/key/SpelKeyGenerator.java

+2-8
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,9 @@
3535
import java.util.stream.Collectors;
3636
import lombok.Data;
3737
import lombok.EqualsAndHashCode;
38-
import org.springframework.aop.support.AopUtils;
3938
import org.springframework.context.expression.AnnotatedElementKey;
4039
import org.springframework.context.expression.CachedExpressionEvaluator;
4140
import org.springframework.context.expression.MethodBasedEvaluationContext;
42-
import org.springframework.core.DefaultParameterNameDiscoverer;
43-
import org.springframework.core.ParameterNameDiscoverer;
4441
import org.springframework.core.convert.ConversionService;
4542
import org.springframework.core.convert.TypeDescriptor;
4643
import org.springframework.expression.EvaluationContext;
@@ -52,18 +49,15 @@
5249
@EqualsAndHashCode(callSuper = false)
5350
public class SpelKeyGenerator extends CachedExpressionEvaluator implements KeyGenerator {
5451
private final ConversionService conversionService;
55-
private final ParameterNameDiscoverer parameterNameDiscoverer = new DefaultParameterNameDiscoverer();
5652
private final Map<ExpressionKey, Expression> conditionCache = new ConcurrentHashMap<>();
5753
private final Map<AnnotatedElementKey, Method> targetMethodCache = new ConcurrentHashMap<>();
5854

5955
@Override
6056
public List<String> resolveKeys(final String lockKeyPrefix, final String expression, final Object object, final Method method, final Object[] args) {
61-
final AnnotatedElementKey annotatedElementKey = new AnnotatedElementKey(method, object.getClass());
62-
final Method targetMethod = this.targetMethodCache.computeIfAbsent(annotatedElementKey, key -> AopUtils.getMostSpecificMethod(method, object.getClass()));
63-
final EvaluationContext context = new MethodBasedEvaluationContext(object, targetMethod, args, this.parameterNameDiscoverer);
57+
final EvaluationContext context = new MethodBasedEvaluationContext(object, method, args, super.getParameterNameDiscoverer());
6458
context.setVariable("executionPath", object.getClass().getCanonicalName() + "." + method.getName());
6559

66-
final List<String> keys = convertResultToList(getExpression(this.conditionCache, annotatedElementKey, expression).getValue(context));
60+
final List<String> keys = convertResultToList(getExpression(this.conditionCache, new AnnotatedElementKey(method, object.getClass()), expression).getValue(context));
6761

6862
if (keys.stream().anyMatch(Objects::isNull)) {
6963
throw new EvaluationConvertException("null keys are not supported: " + keys);

distributed-lock-example/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>com.github.alturkovic</groupId>
99
<artifactId>distributed-lock</artifactId>
10-
<version>1.2.1</version>
10+
<version>1.2.2</version>
1111
</parent>
1212

1313
<artifactId>distributed-lock-example</artifactId>

distributed-lock-jdbc/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>com.github.alturkovic</groupId>
99
<artifactId>distributed-lock</artifactId>
10-
<version>1.2.1</version>
10+
<version>1.2.2</version>
1111
</parent>
1212

1313
<artifactId>distributed-lock-jdbc</artifactId>

distributed-lock-mongo/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>com.github.alturkovic</groupId>
99
<artifactId>distributed-lock</artifactId>
10-
<version>1.2.1</version>
10+
<version>1.2.2</version>
1111
</parent>
1212

1313
<artifactId>distributed-lock-mongo</artifactId>

distributed-lock-redis/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>com.github.alturkovic</groupId>
99
<artifactId>distributed-lock</artifactId>
10-
<version>1.2.1</version>
10+
<version>1.2.2</version>
1111
</parent>
1212

1313
<artifactId>distributed-lock-redis</artifactId>

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.github.alturkovic</groupId>
88
<artifactId>distributed-lock</artifactId>
9-
<version>1.2.1</version>
9+
<version>1.2.2</version>
1010
<packaging>pom</packaging>
1111

1212
<name>distributed-lock</name>

0 commit comments

Comments
 (0)