You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2021/05/16 12:52:44 UTC
[maven-resolver] 01/01: Destroy RSemaphores explicitly
This is an automated email from the ASF dual-hosted git repository.
michaelo pushed a commit to branch fix-semaphore-redisson
in repository https://gitbox.apache.org/repos/asf/maven-resolver.git
commit e9ed78edb00267212ccd387ac3d79fe0a03f4560
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Sun May 16 14:52:26 2021 +0200
Destroy RSemaphores explicitly
---
.../RedissonSemaphoreNamedLockFactory.java | 27 ++++++++++++++++++++--
1 file changed, 25 insertions(+), 2 deletions(-)
diff --git a/maven-resolver-named-locks-redisson/src/main/java/org/eclipse/aether/named/redisson/RedissonSemaphoreNamedLockFactory.java b/maven-resolver-named-locks-redisson/src/main/java/org/eclipse/aether/named/redisson/RedissonSemaphoreNamedLockFactory.java
index bef84cc..852a050 100644
--- a/maven-resolver-named-locks-redisson/src/main/java/org/eclipse/aether/named/redisson/RedissonSemaphoreNamedLockFactory.java
+++ b/maven-resolver-named-locks-redisson/src/main/java/org/eclipse/aether/named/redisson/RedissonSemaphoreNamedLockFactory.java
@@ -23,8 +23,12 @@ import org.eclipse.aether.named.support.AdaptedSemaphoreNamedLock;
import org.eclipse.aether.named.support.NamedLockSupport;
import org.redisson.api.RSemaphore;
+import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
+
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;
/**
@@ -37,12 +41,31 @@ public class RedissonSemaphoreNamedLockFactory
{
public static final String NAME = "semaphore-redisson";
+ private final ConcurrentMap<String, RSemaphore> semaphores;
+
+ @Inject
+ public RedissonSemaphoreNamedLockFactory()
+ {
+ super();
+ this.semaphores = new ConcurrentHashMap<>();
+ }
+
@Override
protected NamedLockSupport createLock( final String name )
{
+ RSemaphore semaphore = semaphores.computeIfAbsent(
+ name, k -> redissonClient.getSemaphore( NAME_PREFIX + k ) );
+
return new AdaptedSemaphoreNamedLock(
- name, this, new RedissonSemaphore( redissonClient.getSemaphore( NAME_PREFIX + name ) )
- );
+ name, this, new RedissonSemaphore( semaphore )
+ );
+ }
+
+ @Override
+ protected void destroyLock( NamedLockSupport lock )
+ {
+ RSemaphore semaphore = semaphores.remove( lock.name() );
+ semaphore.delete();
}
private static final class RedissonSemaphore implements AdaptedSemaphoreNamedLock.AdaptedSemaphore