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:43 UTC

[maven-resolver] branch fix-semaphore-redisson created (now e9ed78e)

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

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


      at e9ed78e  Destroy RSemaphores explicitly

This branch includes the following new commits:

     new e9ed78e  Destroy RSemaphores explicitly

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: Destroy RSemaphores explicitly

Posted by mi...@apache.org.
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