[maven-resolver] branch MRESOLVER-123 created (now ebc3a5c)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[maven-resolver] branch MRESOLVER-123 created (now ebc3a5c)

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

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


      at ebc3a5c  [MRESOLVER-123] Concurrency issues

This branch includes the following new commits:

     new ebc3a5c  [MRESOLVER-123] Concurrency issues

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.


Reply | Threaded
Open this post in threaded view
|

[maven-resolver] 01/01: [MRESOLVER-123] Concurrency issues

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

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

commit ebc3a5c7f3c893b6fed178f9345196bbbcf0e282
Author: Michael Osipov <[hidden email]>
AuthorDate: Mon Jun 29 21:17:35 2020 +0200

    [MRESOLVER-123] Concurrency issues
---
 .../internal/impl/DefaultSyncContextFactory.java   | 36 ++++++++++++++++++++--
 1 file changed, 33 insertions(+), 3 deletions(-)

diff --git a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultSyncContextFactory.java b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultSyncContextFactory.java
index 69fdbc6..cf442ed 100644
--- a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultSyncContextFactory.java
+++ b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultSyncContextFactory.java
@@ -8,9 +8,9 @@ package org.eclipse.aether.internal.impl;
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- *
+ *
  *  http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -20,6 +20,8 @@ package org.eclipse.aether.internal.impl;
  */
 
 import java.util.Collection;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
 
 import javax.inject.Named;
 
@@ -28,31 +30,59 @@ import org.eclipse.aether.SyncContext;
 import org.eclipse.aether.artifact.Artifact;
 import org.eclipse.aether.impl.SyncContextFactory;
 import org.eclipse.aether.metadata.Metadata;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.inject.Singleton;
 
 /**
  * A factory to create synchronization contexts. This default implementation actually does not provide any real
  * synchronization but merely completes the repository system.
  */
 @Named
+@Singleton
 public class DefaultSyncContextFactory
     implements SyncContextFactory
 {
+    private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock( true );
 
     public SyncContext newInstance( RepositorySystemSession session, boolean shared )
     {
-        return new DefaultSyncContext();
+        return new DefaultSyncContext( shared ? lock.readLock() : lock.writeLock(), shared );
     }
 
     static class DefaultSyncContext
         implements SyncContext
     {
+        private static final Logger LOGGER = LoggerFactory.getLogger( DefaultSyncContext.class );
+
+        private final Lock lock;
+        private final boolean shared;
+        private int lockHoldCount;
+
+        DefaultSyncContext( Lock lock, boolean shared )
+        {
+            this.lock = lock;
+            this.shared = shared;
+        }
 
         public void acquire( Collection<? extends Artifact> artifact, Collection<? extends Metadata> metadata )
         {
+            LOGGER.debug( "Acquiring global {} lock (currently held: {})",
+                          shared ? "read" : "write", lockHoldCount );
+            lock.lock();
+            lockHoldCount++;
         }
 
         public void close()
         {
+            while ( lockHoldCount != 0 )
+            {
+                LOGGER.debug( "Releasing global {} lock (currently held: {})",
+                              shared ? "read" : "write", lockHoldCount );
+                lock.unlock();
+                lockHoldCount--;
+            }
         }
 
     }