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/26 17:44:51 UTC

[maven-resolver] branch MRESOLVER-184 created (now 3971fa9)

This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a change to branch MRESOLVER-184
in repository https://gitbox.apache.org/repos/asf/maven-resolver.git.


      at 3971fa9  [MRESOLVER-184] Destroy Redisson semaphores if not used anymore

This branch includes the following new commits:

     new 3971fa9  [MRESOLVER-184] Destroy Redisson semaphores if not used anymore

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[maven-resolver] 01/01: [MRESOLVER-184] Destroy Redisson semaphores if not used anymore

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a commit to branch MRESOLVER-184
in repository https://gitbox.apache.org/repos/asf/maven-resolver.git

commit 3971fa930d12831f28d11707e05b7e28b4ec19d1
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Sun May 16 14:52:26 2021 +0200

    [MRESOLVER-184] Destroy Redisson semaphores if not used anymore
---
 .../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