You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by GitBox <gi...@apache.org> on 2020/11/05 11:17:32 UTC

[GitHub] [maven-resolver] cstamas opened a new pull request #77: SyncContext implementations

cstamas opened a new pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77


   Just some scratches for synccontext, and added few implementations and an intermittent layer NamedLock that implements ref counting, for those implementations that needs it.
   
   So "global" synccontext is bad as it is too "coarse", and there is "redisson" synccontext. This PR adds "fine grained" local synccontexts as alternative to global, and Hazelcast ones (and copies redisson as well).
   
   Implemented:
   - JVM ReentrantReadWriteLock using, usable for MT builds
   - JVM Semaphore using, usable for MT builds
   - Hazelcast and Hazelcast client ISemaphore using, usable for MT and MP builds
   - Copy+Pasted Redisson based as well (but no tests), should be usable for MT and MP builds
   
   Note about Hazelcast: currently using _deprecated_ API as well, as HZ itself is in quite flux (in HZ3.x CP subsystem is usable only with 3+ nodes, in HZ4.0.x CP got "unsafe" operation so is usable with less than 3 nodes, but CP objects remains in heap forever as destroyed... so upgrade to latest HZ could be possible when some alternate CP structure is implemented, and code changed to use that maybe, or just avoiding to destroy DOs). Still, same code modified to use CP works if one creates a dedicated HZ cluster with CP enabled and uses hazelcast-client to connect to it.
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] Tibor17 edited a comment on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
Tibor17 edited a comment on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-817381029


   I think no lock is needed if you use the thread pool because there you say that the fixed number of threads is e.g. 5.
   Deadlock happens if you use multiple lock objects. Why we need to have multiple locks?
   If we want to block the business method until `Collection<Artifact>` is processed completely then we can do it via listeners notified by the thread pool and we can use `CountdownLatch` but the `CountdownLatch` would be only one in business-method stack and the size of the countdown would be equal to the size of the input collection.
   The basic principle of the deadlock using the mutex is this:
   
   **T1**:
   ```
   synchronized(lock1) {
       synchronized(lock2) {
          // job here
       }
   }
   ```
   
   **T2**:
   ```
   synchronized(lock2) {
       synchronized(lock1) {
          // another job here
       }
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-822196779


   > 
   > 
   > I spotted this (refCount was not final), but will run your test tomorrow and try to reproduce.
   
   Can you explain why `final` should fix this?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-822066953


   I spotted this (refCount was not final), but will run your test tomorrow and try to reproduce.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r611857217



##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/named/NameMapper.java
##########
@@ -0,0 +1,41 @@
+package org.eclipse.aether.internal.impl.synccontext.named;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Collection;
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+
+/**
+ * Component mapping lock names to passed in artifacts and metadata as required.
+ */
+public interface NameMapper
+{
+  /**
+   * Creates (opaque) names for passed in artifacts and metadata. Returned collection has max size of sum of the passed
+   * in artifacts and metadata collections, or less. If empty collection returned, there will be no locking happening.
+   * Never returns {@code null}.
+   */
+  Collection<String> nameLocks( RepositorySystemSession session,

Review comment:
       I don't think that `TreeSet` is necessary, at most `SortedSet`, but since you perfectly documented the contract in the interface, a `Collection` is fine. If the output is not stable, the behavior will be *undefined*.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-764929160


   I need to go through another iteration because I wasn't really happy with some things last time, plus I need test myself too. I am currently on a short leash, but will try to go through this month.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r611775008



##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/NamedSyncContextFactory.java
##########
@@ -0,0 +1,128 @@
+package org.eclipse.aether.internal.impl.synccontext;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.internal.impl.synccontext.named.DiscriminatingNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.GAVNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.NameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.NamedLockFactoryAdapter;
+import org.eclipse.aether.internal.impl.synccontext.named.StaticNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.takari.TakariNamedLockFactory;
+import org.eclipse.aether.internal.impl.synccontext.named.takari.TakariNameMapper;
+import org.eclipse.aether.named.NamedLockFactory;
+import org.eclipse.aether.named.providers.LocalReadWriteLockNamedLockFactory;
+import org.eclipse.aether.named.providers.LocalSemaphoreNamedLockFactory;
+
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Named {@link SyncContextFactoryDelegate} implementation that selects underlying {@link NamedLockFactory}
+ * implementation at creation.
+ */
+@Singleton
+@Named( NamedSyncContextFactory.NAME )
+public final class NamedSyncContextFactory
+        implements SyncContextFactoryDelegate
+{
+    public static final String NAME = "named";
+
+    private static final String FACTORY_NAME = System.getProperty(
+            "aether.syncContext.named.factory", LocalReadWriteLockNamedLockFactory.NAME
+    );
+
+    private static final String NAME_MAPPING = System.getProperty(
+        "aether.syncContext.named.nameMapping", DiscriminatingNameMapper.NAME
+    );
+
+    private static final long TIME_OUT = Long.getLong(
+            "aether.syncContext.named.timeout", 30L
+    );
+
+    private static final TimeUnit TIME_UNIT = TimeUnit.valueOf( System.getProperty(

Review comment:
       Fixed




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r568875978



##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/NoLockSyncContextFactory.java
##########
@@ -22,39 +22,42 @@
 import java.util.Collection;
 
 import javax.inject.Named;
+import javax.inject.Singleton;
 
 import org.eclipse.aether.RepositorySystemSession;
 import org.eclipse.aether.SyncContext;
 import org.eclipse.aether.artifact.Artifact;
-import org.eclipse.aether.spi.synccontext.SyncContextFactory;
 import org.eclipse.aether.metadata.Metadata;
 
 /**
  * A factory to create synchronization contexts. This default implementation does not provide any real
  * synchronization but merely completes the repository system.
  */
-@Named
-public class DefaultSyncContextFactory
-    implements SyncContextFactory, org.eclipse.aether.impl.SyncContextFactory
+@Singleton
+@Named( NoLockSyncContextFactory.NAME )
+public class NoLockSyncContextFactory

Review comment:
       That is absolutely correct, but shouldn't it remain for testing purposes and proof that real code works? 

##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/NoLockSyncContextFactory.java
##########
@@ -22,39 +22,42 @@
 import java.util.Collection;
 
 import javax.inject.Named;
+import javax.inject.Singleton;
 
 import org.eclipse.aether.RepositorySystemSession;
 import org.eclipse.aether.SyncContext;
 import org.eclipse.aether.artifact.Artifact;
-import org.eclipse.aether.spi.synccontext.SyncContextFactory;
 import org.eclipse.aether.metadata.Metadata;
 
 /**
  * A factory to create synchronization contexts. This default implementation does not provide any real
  * synchronization but merely completes the repository system.
  */
-@Named
-public class DefaultSyncContextFactory
-    implements SyncContextFactory, org.eclipse.aether.impl.SyncContextFactory
+@Singleton
+@Named( NoLockSyncContextFactory.NAME )
+public class NoLockSyncContextFactory

Review comment:
       If you really want to drop, just do, but I think it has its usecases. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r605522828



##########
File path: maven-resolver-named-locks/src/main/java/org/eclipse/aether/named/support/NamedLockFactorySupport.java
##########
@@ -0,0 +1,88 @@
+package org.eclipse.aether.named.support;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.eclipse.aether.named.NamedLockFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Support class for {@link NamedLockFactory} implementations providing reference counting.
+ *
+ * @param <L> the actual implementation, subclass of {@link NamedLockSupport}.
+ */
+public abstract class NamedLockFactorySupport<L extends NamedLockSupport>
+    implements NamedLockFactory
+{
+  protected final Logger log = LoggerFactory.getLogger( getClass() );
+
+  private final ConcurrentHashMap<String, L> locks;

Review comment:
       This is a local variable.

##########
File path: maven-resolver-named-locks/src/main/java/org/eclipse/aether/named/providers/FileLockNamedLock.java
##########
@@ -0,0 +1,171 @@
+package org.eclipse.aether.named.providers;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.nio.channels.FileChannel;
+import java.nio.channels.FileLock;
+import java.util.ArrayDeque;
+import java.util.Collection;
+import java.util.Deque;
+import java.util.HashMap;
+import java.util.concurrent.TimeUnit;
+
+import org.eclipse.aether.named.support.NamedLockSupport;
+
+/**
+ * Named lock that uses {@link FileLock}.
+ */
+public final class FileLockNamedLock
+    extends NamedLockSupport
+{
+    private static final long LOCK_POSITION = 0L;
+
+    private static final long LOCK_SIZE = 1L;
+
+    private final HashMap<Thread, Deque<FileLock>> threadSteps;

Review comment:
       This is a local variable.

##########
File path: maven-resolver-named-locks-redisson/src/main/java/org/eclipse/aether/named/redisson/RedissonSemaphoreNamedLockFactory.java
##########
@@ -0,0 +1,69 @@
+package org.eclipse.aether.named.redisson;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.named.support.AdaptedSemaphoreNamedLock;
+import org.redisson.api.RSemaphore;
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Provider of {@link RedissonSemaphoreNamedLockFactory} using Redisson and {@link org.redisson.api.RSemaphore}.
+ */
+@Singleton
+@Named( RedissonSemaphoreNamedLockFactory.NAME )
+public class RedissonSemaphoreNamedLockFactory
+    extends RedissonNamedLockFactorySupport<AdaptedSemaphoreNamedLock>
+{
+  public static final String NAME = "semaphore-redisson";
+
+  @Override
+  protected AdaptedSemaphoreNamedLock createLock( final String name )
+  {
+    return new AdaptedSemaphoreNamedLock(
+            name, this, new RedissonSemaphore( redissonClient.getSemaphore( NAME_PREFIX + name ) )
+    );
+  }
+
+  private static final class RedissonSemaphore implements AdaptedSemaphoreNamedLock.AdaptedSemaphore
+  {
+    private final RSemaphore semaphore;
+
+    private RedissonSemaphore( final RSemaphore semaphore )
+    {
+      semaphore.addPermits( Integer.MAX_VALUE );
+      this.semaphore = semaphore;
+    }
+
+    @Override
+    public boolean tryAcquire( final int perms, final long time, final TimeUnit unit ) throws InterruptedException

Review comment:
       fixed

##########
File path: maven-resolver-named-locks-redisson/src/main/java/org/eclipse/aether/named/redisson/RedissonReadWriteLockNamedLockFactory.java
##########
@@ -0,0 +1,50 @@
+package org.eclipse.aether.named.redisson;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.named.support.AdaptedReadWriteLockNamedLock;
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+/**
+ * Provider of {@link RedissonReadWriteLockNamedLockFactory} using Redisson and {@link org.redisson.api.RReadWriteLock}.
+ */
+@Singleton
+@Named( RedissonReadWriteLockNamedLockFactory.NAME )
+public class RedissonReadWriteLockNamedLockFactory
+    extends RedissonNamedLockFactorySupport<AdaptedReadWriteLockNamedLock>
+{
+  public static final String NAME = "rwlock-redisson";
+
+  private static final String NAME_PREFIX = "maven:resolver:";

Review comment:
       fixed, this was a mistake.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r605555998



##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/NamedSyncContextFactory.java
##########
@@ -0,0 +1,128 @@
+package org.eclipse.aether.internal.impl.synccontext;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.internal.impl.synccontext.named.DiscriminatingNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.GAVNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.NameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.NamedLockFactoryAdapter;
+import org.eclipse.aether.internal.impl.synccontext.named.StaticNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.takari.TakariNamedLockFactory;
+import org.eclipse.aether.internal.impl.synccontext.named.takari.TakariNameMapper;
+import org.eclipse.aether.named.NamedLockFactory;
+import org.eclipse.aether.named.providers.LocalReadWriteLockNamedLockFactory;
+import org.eclipse.aether.named.providers.LocalSemaphoreNamedLockFactory;
+
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Named {@link SyncContextFactoryDelegate} implementation that selects underlying {@link NamedLockFactory}
+ * implementation at creation.
+ */
+@Singleton
+@Named( NamedSyncContextFactory.NAME )
+public final class NamedSyncContextFactory
+        implements SyncContextFactoryDelegate
+{
+    public static final String NAME = "named";
+
+    private static final String FACTORY_NAME = System.getProperty(
+            "aether.syncContext.named.factory", LocalReadWriteLockNamedLockFactory.NAME
+    );
+
+    private static final String NAME_MAPPING = System.getProperty(
+        "aether.syncContext.named.nameMapping", DiscriminatingNameMapper.NAME
+    );
+
+    private static final long TIME_OUT = Long.getLong(
+            "aether.syncContext.named.timeOut", 30L
+    );
+
+    private static final TimeUnit TIME_UNIT = TimeUnit.valueOf( System.getProperty(
+            "aether.syncContext.named.timeUnit", TimeUnit.SECONDS.name()
+    ) );
+
+    private final NamedLockFactoryAdapter namedLockFactoryAdapter;
+
+    /**
+     * Constructor used with DI, where factories are injected and selected based on key.
+     */
+    @Inject
+    public NamedSyncContextFactory( final Map<String, NameMapper> nameMappers,
+                                    final Map<String, NamedLockFactory> factories )
+    {
+        this.namedLockFactoryAdapter = selectAndAdapt( nameMappers, factories );
+    }
+
+    /**
+     * Default constructor.
+     */
+    public NamedSyncContextFactory()
+    {
+        HashMap<String, NameMapper> nameMappers = new HashMap<>();

Review comment:
       This is a local variable.

##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/NamedSyncContextFactory.java
##########
@@ -0,0 +1,128 @@
+package org.eclipse.aether.internal.impl.synccontext;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.internal.impl.synccontext.named.DiscriminatingNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.GAVNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.NameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.NamedLockFactoryAdapter;
+import org.eclipse.aether.internal.impl.synccontext.named.StaticNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.takari.TakariNamedLockFactory;
+import org.eclipse.aether.internal.impl.synccontext.named.takari.TakariNameMapper;
+import org.eclipse.aether.named.NamedLockFactory;
+import org.eclipse.aether.named.providers.LocalReadWriteLockNamedLockFactory;
+import org.eclipse.aether.named.providers.LocalSemaphoreNamedLockFactory;
+
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Named {@link SyncContextFactoryDelegate} implementation that selects underlying {@link NamedLockFactory}
+ * implementation at creation.
+ */
+@Singleton
+@Named( NamedSyncContextFactory.NAME )
+public final class NamedSyncContextFactory
+        implements SyncContextFactoryDelegate
+{
+    public static final String NAME = "named";
+
+    private static final String FACTORY_NAME = System.getProperty(
+            "aether.syncContext.named.factory", LocalReadWriteLockNamedLockFactory.NAME
+    );
+
+    private static final String NAME_MAPPING = System.getProperty(
+        "aether.syncContext.named.nameMapping", DiscriminatingNameMapper.NAME
+    );
+
+    private static final long TIME_OUT = Long.getLong(
+            "aether.syncContext.named.timeOut", 30L
+    );
+
+    private static final TimeUnit TIME_UNIT = TimeUnit.valueOf( System.getProperty(
+            "aether.syncContext.named.timeUnit", TimeUnit.SECONDS.name()
+    ) );
+
+    private final NamedLockFactoryAdapter namedLockFactoryAdapter;
+
+    /**
+     * Constructor used with DI, where factories are injected and selected based on key.
+     */
+    @Inject
+    public NamedSyncContextFactory( final Map<String, NameMapper> nameMappers,
+                                    final Map<String, NamedLockFactory> factories )
+    {
+        this.namedLockFactoryAdapter = selectAndAdapt( nameMappers, factories );
+    }
+
+    /**
+     * Default constructor.
+     */
+    public NamedSyncContextFactory()
+    {
+        HashMap<String, NameMapper> nameMappers = new HashMap<>();
+        nameMappers.put( StaticNameMapper.NAME, new StaticNameMapper() );
+        nameMappers.put( GAVNameMapper.NAME, new GAVNameMapper() );
+        nameMappers.put( DiscriminatingNameMapper.NAME, new DiscriminatingNameMapper( new GAVNameMapper() ) );
+        nameMappers.put( TakariNameMapper.NAME, new TakariNameMapper() );
+        HashMap<String, NamedLockFactory> factories = new HashMap<>();

Review comment:
       This is a local variable.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r549457200



##########
File path: maven-resolver-impl/pom.xml
##########
@@ -49,6 +49,10 @@
       <groupId>org.apache.maven.resolver</groupId>
       <artifactId>maven-resolver-spi</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.maven.resolver</groupId>
+      <artifactId>maven-resolver-named</artifactId>

Review comment:
       "synccontext" exists in resolver-api (SyncContext) and resolver-spi (SyncContextFactory). While I agree that name maven-resolver-named is misleading, it has none of those two contained. What about maven-resolver-named-locks? It was my initial idea, but abstained as then maven-resolver-named-locks-redisson would be unusually long artifact ID...




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-811916624


   @Tibor17 agreed, the use of atomic move in resolver is out of scope for this PR.
   
   Re atomic move, it was used throughout Proximity/Nexus/1/2 since Java7 came out with it just fine. Re "no need for locking" -- YES, if you are on POSIX OS/FS (where OS guarantees that a reader can read once opened file fully even if other process overwrites/deletes it). So pretty much locking is still needed if on Windows.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-811824284


   > A left a few comments, please go through.
   > 
   > * I have a few more homework to do because I do not fully understand all involved layers with `AdaptedReadWriteLockNamedLock` and `NamedLockFactorySupport`. I am bit worried that (Redisson) lock objects will be cached in memory although it is absolutely not always necessary because the Redission client will retrieve them anyway from the Redis instance when a lock operation is performed.
   > * What is gone is the map with key lock and value integer. It has been replaced with a deque. From a technical point of view it is fine because it will retain reverse order lock release to avoid deadlocks. Though,  I intentionally have created the map because I wanted to print the reentrant lock count for debugging/analysis purposes.
   > * After I will have established better understanding I will run tests.
   > * What I do not understand is why bind name mappers and factories, but still assemble them manually instead of having a map injects with a provider/map with name key and object value?! Isn't this duplicate work/brittle?
   
   * Yes, they will be cached, for as long as the lock is in use. As we implement reference counting, they will be removed once the last lock using thread releases it.
   * we can add some debugging/analysis helpers around, if needed, but IMHO we did not lost too much here. What specifics you have on mind?
   * OK
   * :smile: ServiceLocator: as long it is present, we need these "loops and hoops", make objects work with default ctor, "constant-looking params" and other trickeries... once ServiceLocator is gone, and only DI (SISU more specifically) is used, these things will get explicit and much more cleaner.
   
   Waiting for response.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] Tibor17 commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
Tibor17 commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-812088775


   You have a plenty of commits in here and I saw a lock for file. My goal was to avoid the lock.
   -- for explaining why it was related.
   Cheers
   Tibor


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r605555586



##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/DefaultSyncContextFactory.java
##########
@@ -0,0 +1,86 @@
+package org.eclipse.aether.internal.impl.synccontext;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.spi.synccontext.SyncContextFactory;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * Default {@link SyncContextFactory} implementation that delegates to some {@link SyncContextFactoryDelegate}
+ * implementation.
+ */
+@Singleton
+@Named
+public final class DefaultSyncContextFactory
+        implements SyncContextFactory, org.eclipse.aether.impl.SyncContextFactory
+{
+    private static final String SYNC_CONTEXT_FACTORY_NAME = System.getProperty(
+            "aether.syncContext.impl", NamedSyncContextFactory.NAME
+    );
+
+    private final SyncContextFactoryDelegate delegate;
+
+    /**
+     * Constructor used with DI, where factories are injected and selected based on key.
+     */
+    @Inject
+    public DefaultSyncContextFactory( final Map<String, SyncContextFactoryDelegate> delegates )
+    {
+        Objects.requireNonNull( delegates );
+        this.delegate = selectDelegate( delegates );
+    }
+
+    /**
+     * Default constructor.
+     */
+    public DefaultSyncContextFactory()
+    {
+        HashMap<String, SyncContextFactoryDelegate> delegates = new HashMap<>( 3 );
+        delegates.put( NoLockSyncContextFactory.NAME, new NoLockSyncContextFactory() );
+        delegates.put( GlobalSyncContextFactory.NAME, new GlobalSyncContextFactory() );
+        delegates.put( NamedSyncContextFactory.NAME, new NamedSyncContextFactory() );
+        this.delegate = selectDelegate( delegates );
+    }
+
+    private SyncContextFactoryDelegate selectDelegate( final Map<String, SyncContextFactoryDelegate> delegates )
+    {
+        SyncContextFactoryDelegate delegate = delegates.get( SYNC_CONTEXT_FACTORY_NAME );
+        if ( delegate == null )
+        {
+            throw new IllegalArgumentException( "Unknown SyncContextFactory impl: " + SYNC_CONTEXT_FACTORY_NAME

Review comment:
       um, matter of taste IMHO: the factory name is really a "parameter" (as user may override default value), now, that given name is available or unavailable, may depend on many other factors, like badly set up (missing) dependency for example, that is again, user issue.... am really neutral on this question: state vs argument here.
   
   Just as a side-note: all this would be more clearly visible, once ServiceLocator is gone, so ctor injection would be explicit, but again, we are not yet there.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas edited a comment on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas edited a comment on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-811824284


   > A left a few comments, please go through.
   > 
   > * I have a few more homework to do because I do not fully understand all involved layers with `AdaptedReadWriteLockNamedLock` and `NamedLockFactorySupport`. I am bit worried that (Redisson) lock objects will be cached in memory although it is absolutely not always necessary because the Redission client will retrieve them anyway from the Redis instance when a lock operation is performed.
   > * What is gone is the map with key lock and value integer. It has been replaced with a deque. From a technical point of view it is fine because it will retain reverse order lock release to avoid deadlocks. Though,  I intentionally have created the map because I wanted to print the reentrant lock count for debugging/analysis purposes.
   > * After I will have established better understanding I will run tests.
   > * What I do not understand is why bind name mappers and factories, but still assemble them manually instead of having a map injects with a provider/map with name key and object value?! Isn't this duplicate work/brittle?
   
   * Yes, they will be cached, for as long as the lock is in use. As we implement reference counting, they will be removed once the last lock using thread releases it.
   * we can add some debugging/analysis helpers around, if needed, but IMHO we did not lost too much here. What specifics you have on mind?
   * OK
   * :smile: ServiceLocator: as long it is present, we need these "loops and hoops", make objects work with default ctor, "constant-looking params" and other trickeries... once ServiceLocator is gone, and only DI (SISU more specifically) is used, these things will get explicit and much more cleaner and use ctor injection purely.
   
   Waiting for response.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r568863257



##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/NoLockSyncContextFactory.java
##########
@@ -22,39 +22,42 @@
 import java.util.Collection;
 
 import javax.inject.Named;
+import javax.inject.Singleton;
 
 import org.eclipse.aether.RepositorySystemSession;
 import org.eclipse.aether.SyncContext;
 import org.eclipse.aether.artifact.Artifact;
-import org.eclipse.aether.spi.synccontext.SyncContextFactory;
 import org.eclipse.aether.metadata.Metadata;
 
 /**
  * A factory to create synchronization contexts. This default implementation does not provide any real
  * synchronization but merely completes the repository system.
  */
-@Named
-public class DefaultSyncContextFactory
-    implements SyncContextFactory, org.eclipse.aether.impl.SyncContextFactory
+@Singleton
+@Named( NoLockSyncContextFactory.NAME )
+public class NoLockSyncContextFactory

Review comment:
       Frankly, I'd drop this class, as current master (and 1.6.x as for that matter) suffers from MRESOVER-153, so this class is really an implementation "we know to cause problems".




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r611747420



##########
File path: maven-resolver-named-locks/src/main/java/org/eclipse/aether/named/support/AdaptedSemaphoreNamedLock.java
##########
@@ -0,0 +1,112 @@
+package org.eclipse.aether.named.support;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayDeque;
+import java.util.Deque;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Named lock support implementation that is using "adapted" semaphore (to be able to use semaphores not sharing common
+ * API).
+ */
+public class AdaptedSemaphoreNamedLock
+    extends NamedLockSupport
+{
+    /**
+     * Wrapper for semaphore-like stuff, that do not share common ancestor. Semaphore must be created to support
+     * {@link Integer#MAX_VALUE} permissions.
+     */
+    public interface AdaptedSemaphore
+    {
+        boolean tryAcquire( int perms, long timeout, TimeUnit unit ) throws InterruptedException;
+
+        void release( int perms );
+    }
+
+    private final ThreadLocal<Deque<Integer>> threadPerms;
+
+    private final AdaptedSemaphore semaphore;
+
+    public AdaptedSemaphoreNamedLock( final String name,
+                                      final NamedLockFactorySupport factory,

Review comment:
       I'd rather get rid of generic use, it does not bring anything to it.

##########
File path: maven-resolver-named-locks/src/main/java/org/eclipse/aether/named/support/NamedLockSupport.java
##########
@@ -0,0 +1,87 @@
+package org.eclipse.aether.named.support;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.eclipse.aether.named.NamedLock;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Support class for {@link NamedLock} implementations providing reference counting.
+ */
+public abstract class NamedLockSupport
+    implements NamedLock
+{
+  protected final Logger log = LoggerFactory.getLogger( getClass() );
+
+  private final String name;
+
+  private final NamedLockFactorySupport factory;
+
+  private final AtomicInteger refCount;
+
+  public NamedLockSupport( final String name, final NamedLockFactorySupport factory )

Review comment:
       I'd rather get rid of generic use, it does not bring anything to it.

##########
File path: maven-resolver-named-locks/src/main/java/org/eclipse/aether/named/support/NamedLockSupport.java
##########
@@ -0,0 +1,87 @@
+package org.eclipse.aether.named.support;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.eclipse.aether.named.NamedLock;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Support class for {@link NamedLock} implementations providing reference counting.
+ */
+public abstract class NamedLockSupport
+    implements NamedLock
+{
+  protected final Logger log = LoggerFactory.getLogger( getClass() );
+
+  private final String name;
+
+  private final NamedLockFactorySupport factory;

Review comment:
       I'd rather get rid of generic use, it does not bring anything to it.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r549461325



##########
File path: maven-resolver-named-hazelcast/src/test/resources/hazelcast-client.xml
##########
@@ -0,0 +1,39 @@
+<?xml version="1.0"?>
+
+<!--
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file 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 KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+-->
+
+<hazelcast-client xmlns="http://www.hazelcast.com/schema/client-config"
+                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+                  xsi:schemaLocation="http://www.hazelcast.com/schema/client-config
+                  http://www.hazelcast.com/schema/client-config/hazelcast-client-config-3.12.xsd">
+
+    <group>
+        <name>maven-resolved-named</name>
+    </group>
+    <instance-name>client</instance-name>
+    <properties>
+        <property name="hazelcast.logging.type">slf4j</property>
+    </properties>
+    <network>
+        <cluster-members>
+            <address>127.0.0.1</address>

Review comment:
       Fixed




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-817367241


   There is one more thing I do not understand and think that this undermines reentrancy: While I understand that you maintain a concurrent map in `NamedLockFactorySupport` to manage locks (counts) between threads in one JVM to properly obtain and release them, but I fail to understand why both `AdaptedReadWriteLockNamedLock` and `AdaptedSemaphoreNamedLock` use thread locals to manage these locks. Looking at how lock and unlock is done, I don't see how underlying locks are used when reentrancy happens. Thus, the internal lock count is not increased, but you turn reentrancy into a `NOOP` and the end. Each call to `lockShared()`/`lockExclusively()` should be delegated to the underlying lock , no matter what. Please explain!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-754170465


   Will pick up by Wednesday.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r550303466



##########
File path: maven-resolver-impl/pom.xml
##########
@@ -49,6 +49,10 @@
       <groupId>org.apache.maven.resolver</groupId>
       <artifactId>maven-resolver-spi</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.maven.resolver</groupId>
+      <artifactId>maven-resolver-named</artifactId>

Review comment:
       renamed "named"->"named-locks"




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas edited a comment on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas edited a comment on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-811791981


   General remark: my personal preference for local variables is to declare them as they are, so `Type variable = new Type()`, in cases when the variable is strictly local scoped. I really see no value in doing `Supertype variable = new Type()` when the `variable` is used in local scope only. Is not only more logical to me, but lessens import count as well (Type vs Supertype in example above).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r524477115



##########
File path: maven-resolver-synccontext-named/src/main/java/org/eclipse/aether/internal/named/SyncContextFactoryAdapter.java
##########
@@ -0,0 +1,300 @@
+package org.eclipse.aether.internal.named;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+import org.eclipse.aether.util.ChecksumUtils;
+import org.eclipse.aether.util.ConfigUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.nio.charset.StandardCharsets;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Deque;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.TreeSet;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Adapter to adapt {@link NamedLockFactory} and {@link NamedLock} to {@link SyncContext}.
+ */
+public final class SyncContextFactoryAdapter
+{
+    private static final String DEFAULT_DISCRIMINATOR_DIGEST = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
+
+    private static final String DEFAULT_HOSTNAME = "localhost";
+
+    private static final Logger LOGGER = LoggerFactory.getLogger( SyncContextFactoryAdapter.class );
+
+    private static final long TIME = Long.getLong(
+        SyncContextFactoryAdapter.class.getName() + ".time", 10L
+    );
+
+    private static final TimeUnit TIME_UNIT = TimeUnit.valueOf( System.getProperty(
+        SyncContextFactoryAdapter.class.getName() + ".timeunit", TimeUnit.SECONDS.name()
+    ) );
+
+    private final NamedLockFactory namedLockFactory;
+
+    private final long time;
+
+    private final TimeUnit timeUnit;
+
+    private final String hostname;
+
+    public SyncContextFactoryAdapter( final NamedLockFactory namedLockFactory )
+    {
+        this( namedLockFactory, TIME, TIME_UNIT );
+    }
+
+    public SyncContextFactoryAdapter( final NamedLockFactory namedLockFactory,
+                                      final long time,
+                                      final TimeUnit timeUnit )
+    {
+        this.namedLockFactory = namedLockFactory;
+        this.time = time;
+        this.timeUnit = timeUnit;
+        this.hostname = getHostname();
+    }
+
+    private String getHostname()
+    {
+        try
+        {
+            return InetAddress.getLocalHost().getHostName();
+        }
+        catch ( UnknownHostException e )
+        {
+            LOGGER.warn( "Failed to get hostname, using '{}'", DEFAULT_HOSTNAME, e );
+            return DEFAULT_HOSTNAME;
+        }
+    }
+
+    public SyncContext newInstance( final RepositorySystemSession session, final boolean shared )
+    {
+        return new AdaptedLockSyncContext( session, hostname, namedLockFactory, time, timeUnit, shared );
+    }
+
+    public void shutdown()
+    {
+        namedLockFactory.shutdown();
+    }
+
+    private static class AdaptedLockSyncContext
+            implements SyncContext
+    {
+        private static final String CONFIG_PROP_DISCRIMINATOR = "aether.syncContext.named.discriminator";
+
+        private static final String KEY_PREFIX = "mvn:resolver:";
+
+        private static final Logger LOGGER = LoggerFactory.getLogger( AdaptedLockSyncContext.class );
+
+        private final RepositorySystemSession session;
+
+        private final String hostname;
+
+        private final NamedLockFactory namedLockFactory;
+
+        private final long time;
+
+        private final TimeUnit timeUnit;
+
+        private final boolean shared;
+
+        private final Map<String, NamedLock> locks = new LinkedHashMap<>();
+
+        private AdaptedLockSyncContext( final RepositorySystemSession session,
+                                        final String hostname,
+                                        final NamedLockFactory namedLockFactory,
+                                        final long time,
+                                        final TimeUnit timeUnit,
+                                        final boolean shared )
+        {
+            this.session = session;
+            this.hostname = hostname;
+            this.namedLockFactory = namedLockFactory;
+            this.time = time;
+            this.timeUnit = timeUnit;
+            this.shared = shared;
+        }
+
+        @Override
+        public void acquire( Collection<? extends Artifact> artifacts,
+                             Collection<? extends Metadata> metadatas )
+        {
+            // Deadlock prevention: https://stackoverflow.com/a/16780988/696632
+            // We must acquire multiple locks always in the same order!
+            Collection<String> keys = new TreeSet<>();
+            if ( artifacts != null )
+            {
+                for ( Artifact artifact : artifacts )
+                {
+                    // TODO Should we include extension and classifier too?
+                    String key = "artifact:" + artifact.getGroupId() + ":"
+                            + artifact.getArtifactId() + ":" + artifact.getBaseVersion();
+                    keys.add( key );
+                }
+            }
+
+            if ( metadatas != null )
+            {
+                for ( Metadata metadata : metadatas )
+                {
+                    StringBuilder key = new StringBuilder( "metadata:" );
+                    if ( !metadata.getGroupId().isEmpty() )
+                    {
+                        key.append( metadata.getGroupId() );
+                        if ( !metadata.getArtifactId().isEmpty() )
+                        {
+                            key.append( ':' ).append( metadata.getArtifactId() );
+                            if ( !metadata.getVersion().isEmpty() )
+                            {
+                                key.append( ':' ).append( metadata.getVersion() );
+                            }
+                        }
+                    }
+                    keys.add( key.toString() );
+                }
+            }
+
+            if ( keys.isEmpty() )
+            {
+                return;
+            }
+
+            String discriminator = createDiscriminator();
+            LOGGER.trace( "Using key discriminator '{}' during this session", discriminator );
+
+            LOGGER.trace( "Need {} {} lock(s) for {}", keys.size(), shared ? "read" : "write", keys );
+            int acquiredLockCount = 0;
+            int reacquiredLockCount = 0;
+            boolean doLock;
+            for ( String key : keys )
+            {
+                NamedLock namedLock = locks.get( key );
+                if ( namedLock == null )
+                {
+                    namedLock = namedLockFactory.getLock( KEY_PREFIX + discriminator + ":" + key );
+                    locks.put( key, namedLock );
+                    acquiredLockCount++;
+                    doLock = true;
+                }
+                else
+                {
+                    reacquiredLockCount++;
+                    doLock = false;
+                }
+
+                if ( doLock )
+                {
+                    try
+                    {
+                        boolean locked;
+                        if ( shared )
+                        {
+                            locked = namedLock.lockShared( time, timeUnit );
+                        }
+                        else
+                        {
+                            locked = namedLock.lockExclusively( time, timeUnit );
+                        }
+
+                        if ( !locked )
+                        {
+                            throw new IllegalStateException( "Could not lock "
+                                    + namedLock.name() + " (shared=" + shared + ")" );
+                        }
+                    }
+                    catch ( InterruptedException e )
+                    {
+                        Thread.currentThread().interrupt();
+                        throw new RuntimeException( e );
+                    }
+                }
+            }
+            LOGGER.trace( "Total new locks acquired: {}, total existing locks reacquired: {}",

Review comment:
       See the documentation: https://maven.apache.org/resolver/apidocs/org/eclipse/aether/SyncContext.html It requires reentrancy.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] rmannibucau commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
rmannibucau commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-751685353


   @michael-o everything can be shaded but a few can be "hard". For properties what about supporting in the resolver.properties something like "configuration.external=path-to-conf-in-maven-base" (ex: configuration.external=conf/redisson.yaml) + if not set a minimal set of properties (host, port, ...). Kind of default simple mode and advanced mode through an external file. On the shading point, I would avoid it to keep the pluggability capabilities of external libs but I would isolate it from maven classpath (requires minimum reflection if well split, just a factory which returns a maven spi).
   
   @cstamas guess for hz we can focus on v4, nobody uses the v3 so let's not make it more complicated than needed to start as you mentionned. For redisson we can have testcontainers tests (with a flag to enable them in run-its probably since it requires docker locally and we don't want to force all dev to have it even if it is common these days). Will be easier than using a ProcessBuilder for redis and stay portable (the test can assume the OS env which is good for such simple cases). I also agree we have to focus on nolock/jvmlock/locallock (file) cases but if we consider hz/redisson as experimental then we should not put them in this repo (or enable the module for releases) IMHO.
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-751690622


   @rmannibucau I would not exclude them from the delivery, but mark as experimental. I want people to test them. If we don't make it publically available it won't be usable for most.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-818667466


   > There is one more thing I do not understand and think that this undermines reentrancy: While I understand that you maintain a concurrent map in `NamedLockFactorySupport` to manage locks (counts) between threads in one JVM to properly obtain and release them, but I fail to understand why both `AdaptedReadWriteLockNamedLock` and `AdaptedSemaphoreNamedLock` use thread locals to manage these locks. Looking at how lock and unlock are done, I don't see how underlying locks are used when reentrancy happens. Thus, the internal lock count is not increased, but you turn reentrancy into a `NOOP` and the end. Each call to `lockShared()`/`lockExclusively()` should be delegated to the underlying lock , no matter what. Please explain!
   
   So, while `NamedLock` is re-entrant, the underlying constructs are not always. For example, all the "semaphore-like" things are not re-entrant: each lock requires permissions to be taken from it (shared: ONE, exclusive: ALL). So, re-entrant capability with semaphores is implemented here by tracking "history" and avoiding doing steps not necessary (the condition is already met, then noop step is performed). On the other hand, with "lock-like" things same thing is done, but here it could be considered as "optimization", as none of these actually change anything on semantic. BUT, in both cases (semaphore and lock) when using some remote construct (like Hazelcast or Redisson constructs, or who knows what else may be used) all the lock/unlock calls performs remote calls, that require serialization, orchestration and all the things you really want to avoid, especially in case when the outcome would really not change anything (the condition you need, the lock level you want is already in
  your pocket).
   
   PS: intentionally write "semaphore-like" and "lock-like" things, as underlying constructs usually do not share common interface or ancestor, so we "adapt" them, but the term is more to express their "nature", or simpler, what is they principle how they work.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-811833880


   > 
   > 
   > @hboutemy
   > @cstamas
   > @michael-o
   > Some long time ago I was talking about the following isea in our Slack.
   > It was about atomic move for the artifact. Maybe the lock file as well.
   > Can we utilize this?
   > `java.nio.file.Files.move(Path source, Path target, CopyOption... options)` where option would be `StandardCopyOption.ATOMIC_MOVE`
   > This means that we would download the artifact file apart. After it is done, move it or fail. I don't know if the lock file is necessary but I guess it is not in this case. Pls check it out.
   
   I would like to discuss this is a separate issue unless it is tightly coupled with this PR.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-731601299


   @cstamas Do you want to perform a final review yourself before I go over again?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r611802378



##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/named/NameMapper.java
##########
@@ -0,0 +1,41 @@
+package org.eclipse.aether.internal.impl.synccontext.named;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Collection;
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+
+/**
+ * Component mapping lock names to passed in artifacts and metadata as required.
+ */
+public interface NameMapper
+{
+  /**
+   * Creates (opaque) names for passed in artifacts and metadata. Returned collection has max size of sum of the passed
+   * in artifacts and metadata collections, or less. If empty collection returned, there will be no locking happening.
+   * Never returns {@code null}.
+   */
+  Collection<String> nameLocks( RepositorySystemSession session,

Review comment:
       pls look at 63f708fd0b9ecc295c8bde7a439577088acf2929




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas edited a comment on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas edited a comment on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-811791981


   General remark: my personal preference for local variables is to declare them as `T variable = new T()`, in cases when the variable is strictly local scoped. I really see no value in doing `Map aMap = new HashMap()` when the `aMap` is used in local scope only. Is not only more logical to me, but lessens import count as well (Map vs HashMap in example above).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-818103092


   > I guess these lines should be written in every of our implementation where a `TreeSet` is used otherwise this gets out of sight, out of mind.
   
   I think Javadoc does pretty good job explaining it, even without referencing the SO... 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r611781922



##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/NamedSyncContextFactory.java
##########
@@ -0,0 +1,128 @@
+package org.eclipse.aether.internal.impl.synccontext;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.internal.impl.synccontext.named.DiscriminatingNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.GAVNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.NameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.NamedLockFactoryAdapter;
+import org.eclipse.aether.internal.impl.synccontext.named.StaticNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.takari.TakariNamedLockFactory;
+import org.eclipse.aether.internal.impl.synccontext.named.takari.TakariNameMapper;
+import org.eclipse.aether.named.NamedLockFactory;
+import org.eclipse.aether.named.providers.LocalReadWriteLockNamedLockFactory;
+import org.eclipse.aether.named.providers.LocalSemaphoreNamedLockFactory;
+
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Named {@link SyncContextFactoryDelegate} implementation that selects underlying {@link NamedLockFactory}
+ * implementation at creation.
+ */
+@Singleton
+@Named( NamedSyncContextFactory.NAME )
+public final class NamedSyncContextFactory
+        implements SyncContextFactoryDelegate
+{
+    public static final String NAME = "named";
+
+    private static final String FACTORY_NAME = System.getProperty(
+            "aether.syncContext.named.factory", LocalReadWriteLockNamedLockFactory.NAME
+    );
+
+    private static final String NAME_MAPPING = System.getProperty(
+        "aether.syncContext.named.nameMapping", DiscriminatingNameMapper.NAME

Review comment:
       Fixed




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-822004920


   Working on the PR now...


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-818908950


   > 
   > 
   > K, merged the "mini PR", I hope this addresses all your concerns.
   
   I guess so. I will test with the few projects I know to fail. You can already squash all changes meanwhile...


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r612335700



##########
File path: maven-resolver-named-locks/src/main/java/org/eclipse/aether/named/NamedLock.java
##########
@@ -0,0 +1,71 @@
+package org.eclipse.aether.named;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * A named lock, functionally similar to existing JVM and other implementations. Must support boxing (reentrancy), but
+ * no lock upgrade is supported. Usual pattern to use this lock:
+ * <pre>
+ *   try (NamedLock lock = factory.getLock("resourceName")) {
+ *     if (lock.lockExclusively(10L, Timeunit.SECONDS)) {
+ *       try {
+ *         ... exclusive access to "resourceName" resource gained here
+ *       }
+ *       finally {
+ *         lock.unlock();
+ *       }
+ *     }
+ *     else {
+ *       ... failed to gain access within specified time, handle it
+ *     }
+ *   }
+ * </pre>
+ */
+public interface NamedLock
+    extends AutoCloseable
+{
+  /**
+   * Returns this instance name, never null.
+   */
+  String name();
+
+  /**
+   * Tries to lock shared, may block for given time. If successful, returns {@code true}.
+   */
+  boolean lockShared( long time, TimeUnit unit ) throws InterruptedException;
+
+  /**
+   * Tries to lock exclusively, may block for given time. If successful, returns {@code true}.
+   */
+  boolean lockExclusively( long time, TimeUnit unit ) throws InterruptedException;
+
+  /**
+   * Unlocks the lock.
+   */
+  void unlock();
+
+  /**
+   * Closes the lock.
+   */
+  @Override
+  void close();

Review comment:
       Accepted.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] Tibor17 commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
Tibor17 commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-817385696


   yes but the problem is that the lock is at the same level as the collection. It should be at the level of individual file and the JVM together with OS would lock it by itself within the process.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r605525340



##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/named/StaticNameMapper.java
##########
@@ -0,0 +1,78 @@
+package org.eclipse.aether.internal.impl.synccontext.named;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Objects;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+import org.eclipse.aether.util.ConfigUtils;
+
+/**
+ * Static {@link NameMapper}, always assigns one same name, effectively becoming equivalent to "global" sync context.
+ */
+@Singleton
+@Named( StaticNameMapper.NAME )
+public class StaticNameMapper
+    implements NameMapper
+{
+  public static final String NAME = "static";
+
+  /**
+   * Configuration property to pass in static name.
+   */
+  private static final String CONFIG_PROP_NAME = "aether.syncContext.named.static.name";
+
+  private final String globalName;
+
+  /**
+   * Uses string {@code "global"} for the static name.

Review comment:
       fixed

##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/named/StaticNameMapper.java
##########
@@ -0,0 +1,78 @@
+package org.eclipse.aether.internal.impl.synccontext.named;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Objects;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+import org.eclipse.aether.util.ConfigUtils;
+
+/**
+ * Static {@link NameMapper}, always assigns one same name, effectively becoming equivalent to "global" sync context.
+ */
+@Singleton
+@Named( StaticNameMapper.NAME )
+public class StaticNameMapper
+    implements NameMapper
+{
+  public static final String NAME = "static";
+
+  /**
+   * Configuration property to pass in static name.
+   */
+  private static final String CONFIG_PROP_NAME = "aether.syncContext.named.static.name";
+
+  private final String globalName;

Review comment:
       fixed




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-811828377


   Let me go through this today/tomorrow. Thanks for the elaborate response!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r549166502



##########
File path: maven-resolver-synccontext-named/pom.xml
##########
@@ -59,7 +59,13 @@
     </dependency>
     <dependency>
       <groupId>org.apache.maven.resolver</groupId>
-      <artifactId>maven-resolver-impl</artifactId>
+      <artifactId>maven-resolver-spi</artifactId>
+      <scope>provided</scope>
+      <optional>true</optional>

Review comment:
       Why is it optional if it is provided?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-751685099


   As for testing Redis, I would not rely on tools like Docker because it is too OS specific. One could probe whether the redis daemon is in `PATH`. If yes, start it. Run tests, shut it down. This won't work on Windows of course, because Redis requires a POSIX-like OS.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] Tibor17 edited a comment on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
Tibor17 edited a comment on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-817372645


   Hey guys,
   
   I did not want to participate because the impl and API is too complicated.
   We all have experiences but this PR is a signal for me that when I start implementing my own Lock then there must be something wrong with me. I did it with Java's `LockSupport` parking and unparking the Threads and it was somehow working but rather used Java's lock. Here it is similar and I think it is due to the API. The concept starts with the `Collection` passed to the method `acquire`:
   
   ```
    try {
        syncContext.acquire( artifacts, metadatas );
        // work with the artifacts and metadatas
    } finally {
        syncContext.close();
    }
   ```
   
   It would be more simple to use make the parallelism at one layer below, this means the collection may become a stream but the lock would be in the thread pool. It may be so simple that you create the Artifact and push it to the queue of `ThreadPoolExecutor`.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r611892765



##########
File path: maven-resolver-named-locks/src/main/java/org/eclipse/aether/named/NamedLock.java
##########
@@ -0,0 +1,71 @@
+package org.eclipse.aether.named;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * A named lock, functionally similar to existing JVM and other implementations. Must support boxing (reentrancy), but
+ * no lock upgrade is supported. Usual pattern to use this lock:
+ * <pre>
+ *   try (NamedLock lock = factory.getLock("resourceName")) {
+ *     if (lock.lockExclusively(10L, Timeunit.SECONDS)) {
+ *       try {
+ *         ... exclusive access to "resourceName" resource gained here
+ *       }
+ *       finally {
+ *         lock.unlock();
+ *       }
+ *     }
+ *     else {
+ *       ... failed to gain access within specified time, handle it
+ *     }
+ *   }
+ * </pre>
+ */
+public interface NamedLock
+    extends AutoCloseable
+{
+  /**
+   * Returns this instance name, never null.
+   */
+  String name();
+
+  /**
+   * Tries to lock shared, may block for given time. If successful, returns {@code true}.
+   */
+  boolean lockShared( long time, TimeUnit unit ) throws InterruptedException;
+
+  /**
+   * Tries to lock exclusively, may block for given time. If successful, returns {@code true}.
+   */
+  boolean lockExclusively( long time, TimeUnit unit ) throws InterruptedException;
+
+  /**
+   * Unlocks the lock.
+   */
+  void unlock();
+
+  /**
+   * Closes the lock.
+   */
+  @Override
+  void close();

Review comment:
       I think this is pretty much clear: "should be used as resource, best in try-with-resource", so IMHO this pretty much explains the order. Also added c6e3487871ed73b8840ac5c5027a54f04390fc93




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r611797238



##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/named/NameMapper.java
##########
@@ -0,0 +1,41 @@
+package org.eclipse.aether.internal.impl.synccontext.named;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Collection;
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+
+/**
+ * Component mapping lock names to passed in artifacts and metadata as required.
+ */
+public interface NameMapper
+{
+  /**
+   * Creates (opaque) names for passed in artifacts and metadata. Returned collection has max size of sum of the passed
+   * in artifacts and metadata collections, or less. If empty collection returned, there will be no locking happening.
+   * Never returns {@code null}.
+   */
+  Collection<String> nameLocks( RepositorySystemSession session,

Review comment:
       Right, and not only that: just figured that `TakariNameMapper` lacks sorting....




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas edited a comment on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas edited a comment on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-751683148


   Howdy @rmannibucau 
   For now I consider both HZ and Redisson as "lab" implementation still, due these:
   * for HZ to work we either must use deprecated HZ 3.x call (HazelcastInstance#getSemaphore), or have a remote CP cluster set up (here, setup is somewhat similar to Redisson: you must have some remote "thing", server, cluster set up beforehand)
   * for Redisson, no clue how to set up tests (any ideas?)
   
   So for start, I'd focus on local (JVM local) locks and the two "extra" (again, for testing purposes: global and nolock) implementations. As they are pretty much in place. Given this PR does not include any of HZ or Redisson code into resolver (they are separate modules, it leaves it to integrator), I think we still have time to solve both questions, that IMO are valid and actually sounds useful (generic props for configuration).


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r568863257



##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/NoLockSyncContextFactory.java
##########
@@ -22,39 +22,42 @@
 import java.util.Collection;
 
 import javax.inject.Named;
+import javax.inject.Singleton;
 
 import org.eclipse.aether.RepositorySystemSession;
 import org.eclipse.aether.SyncContext;
 import org.eclipse.aether.artifact.Artifact;
-import org.eclipse.aether.spi.synccontext.SyncContextFactory;
 import org.eclipse.aether.metadata.Metadata;
 
 /**
  * A factory to create synchronization contexts. This default implementation does not provide any real
  * synchronization but merely completes the repository system.
  */
-@Named
-public class DefaultSyncContextFactory
-    implements SyncContextFactory, org.eclipse.aether.impl.SyncContextFactory
+@Singleton
+@Named( NoLockSyncContextFactory.NAME )
+public class NoLockSyncContextFactory

Review comment:
       Frankly, I'd drop this class, as current master (and 1.6.x as for that matter) suffers from MRESOVER-153, so this class is really an implementation "we know to cause problems".




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r607138805



##########
File path: maven-resolver-named-locks/src/main/java/org/eclipse/aether/named/support/NamedLockFactorySupport.java
##########
@@ -0,0 +1,88 @@
+package org.eclipse.aether.named.support;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.eclipse.aether.named.NamedLockFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Support class for {@link NamedLockFactory} implementations providing reference counting.
+ *
+ * @param <L> the actual implementation, subclass of {@link NamedLockSupport}.
+ */
+public abstract class NamedLockFactorySupport<L extends NamedLockSupport>
+    implements NamedLockFactory
+{
+  protected final Logger log = LoggerFactory.getLogger( getClass() );
+
+  private final ConcurrentHashMap<String, L> locks;

Review comment:
       Indeed, accepted.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] Tibor17 commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
Tibor17 commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-817381029


   I think no lock is needed if you use the thread pool because there you say that the fixed number of threads is e.g. 5.
   Deadlock happens if you use multiple lock objects. Why we need to have multiple locks?
   If we want to block the business method until `Collection<Artifact>` is processes then we can do it via listeners notified by the thread pool and we can use `CountdownLatch` but the `CountdownLatch` would be only one in business-method stack and the size of the countdown would be equal to the size of the input collection.
   The basic principle of the deadlock using the mutex is this:
   
   **T1**:
   ```
   synchronized(lock1) {
       synchronized(lock2) {
          // job here
       }
   }
   ```
   
   **T2**:
   ```
   synchronized(lock2) {
       synchronized(lock1) {
          // another job here
       }
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o edited a comment on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o edited a comment on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-817367241


   There is one more thing I do not understand and think that this undermines reentrancy: While I understand that you maintain a concurrent map in `NamedLockFactorySupport` to manage locks (counts) between threads in one JVM to properly obtain and release them, but I fail to understand why both `AdaptedReadWriteLockNamedLock` and `AdaptedSemaphoreNamedLock` use thread locals to manage these locks. Looking at how lock and unlock are done, I don't see how underlying locks are used when reentrancy happens. Thus, the internal lock count is not increased, but you turn reentrancy into a `NOOP` and the end. Each call to `lockShared()`/`lockExclusively()` should be delegated to the underlying lock , no matter what. Please explain!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r549461341



##########
File path: maven-resolver-named-hazelcast/src/test/resources/hazelcast.xml
##########
@@ -0,0 +1,42 @@
+<?xml version="1.0"?>
+
+<!--
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file 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 KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+-->
+
+<hazelcast xmlns="http://www.hazelcast.com/schema/config"
+           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+           xsi:schemaLocation="http://www.hazelcast.com/schema/config
+           http://www.hazelcast.com/schema/config/hazelcast-config-3.12.xsd">
+
+    <group>
+        <name>maven-resolved-named</name>
+    </group>
+    <instance-name>server</instance-name>
+    <properties>
+        <property name="hazelcast.logging.type">slf4j</property>
+    </properties>
+    <network>
+        <join>
+            <multicast enabled="false"/>
+            <tcp-ip>
+                <interface>127.0.0.1</interface>

Review comment:
       Fixed




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r524471892



##########
File path: maven-resolver-synccontext-named/src/main/java/org/eclipse/aether/internal/named/SyncContextFactoryAdapter.java
##########
@@ -0,0 +1,300 @@
+package org.eclipse.aether.internal.named;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+import org.eclipse.aether.util.ChecksumUtils;
+import org.eclipse.aether.util.ConfigUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.nio.charset.StandardCharsets;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Deque;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.TreeSet;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Adapter to adapt {@link NamedLockFactory} and {@link NamedLock} to {@link SyncContext}.
+ */
+public final class SyncContextFactoryAdapter
+{
+    private static final String DEFAULT_DISCRIMINATOR_DIGEST = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
+
+    private static final String DEFAULT_HOSTNAME = "localhost";
+
+    private static final Logger LOGGER = LoggerFactory.getLogger( SyncContextFactoryAdapter.class );
+
+    private static final long TIME = Long.getLong(
+        SyncContextFactoryAdapter.class.getName() + ".time", 10L
+    );
+
+    private static final TimeUnit TIME_UNIT = TimeUnit.valueOf( System.getProperty(
+        SyncContextFactoryAdapter.class.getName() + ".timeunit", TimeUnit.SECONDS.name()
+    ) );
+
+    private final NamedLockFactory namedLockFactory;
+
+    private final long time;
+
+    private final TimeUnit timeUnit;
+
+    private final String hostname;
+
+    public SyncContextFactoryAdapter( final NamedLockFactory namedLockFactory )
+    {
+        this( namedLockFactory, TIME, TIME_UNIT );
+    }
+
+    public SyncContextFactoryAdapter( final NamedLockFactory namedLockFactory,
+                                      final long time,
+                                      final TimeUnit timeUnit )
+    {
+        this.namedLockFactory = namedLockFactory;
+        this.time = time;
+        this.timeUnit = timeUnit;
+        this.hostname = getHostname();
+    }
+
+    private String getHostname()
+    {
+        try
+        {
+            return InetAddress.getLocalHost().getHostName();
+        }
+        catch ( UnknownHostException e )
+        {
+            LOGGER.warn( "Failed to get hostname, using '{}'", DEFAULT_HOSTNAME, e );
+            return DEFAULT_HOSTNAME;
+        }
+    }
+
+    public SyncContext newInstance( final RepositorySystemSession session, final boolean shared )
+    {
+        return new AdaptedLockSyncContext( session, hostname, namedLockFactory, time, timeUnit, shared );
+    }
+
+    public void shutdown()
+    {
+        namedLockFactory.shutdown();
+    }
+
+    private static class AdaptedLockSyncContext
+            implements SyncContext
+    {
+        private static final String CONFIG_PROP_DISCRIMINATOR = "aether.syncContext.named.discriminator";
+
+        private static final String KEY_PREFIX = "mvn:resolver:";
+
+        private static final Logger LOGGER = LoggerFactory.getLogger( AdaptedLockSyncContext.class );
+
+        private final RepositorySystemSession session;
+
+        private final String hostname;
+
+        private final NamedLockFactory namedLockFactory;
+
+        private final long time;
+
+        private final TimeUnit timeUnit;
+
+        private final boolean shared;
+
+        private final Map<String, NamedLock> locks = new LinkedHashMap<>();
+
+        private AdaptedLockSyncContext( final RepositorySystemSession session,
+                                        final String hostname,
+                                        final NamedLockFactory namedLockFactory,
+                                        final long time,
+                                        final TimeUnit timeUnit,
+                                        final boolean shared )
+        {
+            this.session = session;
+            this.hostname = hostname;
+            this.namedLockFactory = namedLockFactory;
+            this.time = time;
+            this.timeUnit = timeUnit;
+            this.shared = shared;
+        }
+
+        @Override
+        public void acquire( Collection<? extends Artifact> artifacts,
+                             Collection<? extends Metadata> metadatas )
+        {
+            // Deadlock prevention: https://stackoverflow.com/a/16780988/696632
+            // We must acquire multiple locks always in the same order!
+            Collection<String> keys = new TreeSet<>();
+            if ( artifacts != null )
+            {
+                for ( Artifact artifact : artifacts )
+                {
+                    // TODO Should we include extension and classifier too?
+                    String key = "artifact:" + artifact.getGroupId() + ":"
+                            + artifact.getArtifactId() + ":" + artifact.getBaseVersion();
+                    keys.add( key );
+                }
+            }
+
+            if ( metadatas != null )
+            {
+                for ( Metadata metadata : metadatas )
+                {
+                    StringBuilder key = new StringBuilder( "metadata:" );
+                    if ( !metadata.getGroupId().isEmpty() )
+                    {
+                        key.append( metadata.getGroupId() );
+                        if ( !metadata.getArtifactId().isEmpty() )
+                        {
+                            key.append( ':' ).append( metadata.getArtifactId() );
+                            if ( !metadata.getVersion().isEmpty() )
+                            {
+                                key.append( ':' ).append( metadata.getVersion() );
+                            }
+                        }
+                    }
+                    keys.add( key.toString() );
+                }
+            }
+
+            if ( keys.isEmpty() )
+            {
+                return;
+            }
+
+            String discriminator = createDiscriminator();
+            LOGGER.trace( "Using key discriminator '{}' during this session", discriminator );
+
+            LOGGER.trace( "Need {} {} lock(s) for {}", keys.size(), shared ? "read" : "write", keys );
+            int acquiredLockCount = 0;
+            int reacquiredLockCount = 0;
+            boolean doLock;
+            for ( String key : keys )
+            {
+                NamedLock namedLock = locks.get( key );
+                if ( namedLock == null )
+                {
+                    namedLock = namedLockFactory.getLock( KEY_PREFIX + discriminator + ":" + key );
+                    locks.put( key, namedLock );
+                    acquiredLockCount++;
+                    doLock = true;
+                }
+                else
+                {
+                    reacquiredLockCount++;
+                    doLock = false;
+                }
+
+                if ( doLock )
+                {
+                    try
+                    {
+                        boolean locked;
+                        if ( shared )
+                        {
+                            locked = namedLock.lockShared( time, timeUnit );
+                        }
+                        else
+                        {
+                            locked = namedLock.lockExclusively( time, timeUnit );
+                        }
+
+                        if ( !locked )
+                        {
+                            throw new IllegalStateException( "Could not lock "
+                                    + namedLock.name() + " (shared=" + shared + ")" );
+                        }
+                    }
+                    catch ( InterruptedException e )
+                    {
+                        Thread.currentThread().interrupt();
+                        throw new RuntimeException( e );
+                    }
+                }
+            }
+            LOGGER.trace( "Total new locks acquired: {}, total existing locks reacquired: {}",

Review comment:
       What do you mean by "decent lock"? And why this matters, as you said above reentrancy is not used anymore? (unless I misunderstood you). Is this only about the logger message "reacquired"? Will remove it...




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on pull request #77: SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-722327873


   Wow, this is insane. What was the motivation for this?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r524470046



##########
File path: maven-resolver-synccontext-named/src/main/java/org/eclipse/aether/synccontext/NamedSyncContextFactory.java
##########
@@ -0,0 +1,84 @@
+package org.eclipse.aether.synccontext;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Map;
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.impl.SyncContextFactory;
+import org.eclipse.aether.internal.named.NamedLockFactory;
+import org.eclipse.aether.internal.named.SyncContextFactoryAdapter;
+
+import javax.annotation.PreDestroy;
+import javax.annotation.Priority;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Provider;
+import javax.inject.Singleton;
+
+/**
+ * Named {@link SyncContextFactory} implementation that selects underlying {@link NamedLockFactory} implementation
+ * at creation. Known factory names are:
+ * <ul>
+ *   <li>rwlock-local - uses JVM ReentrantReadWriteLock, suitable for MT builds</li>
+ *   <li>rwlock-redisson - uses JVM ReentrantReadWriteLock, suitable for MT builds</li>
+ *   <li>semaphore-local - uses JVM Semaphore, suitable for MT builds</li>
+ *   <li>semaphore-hazelcast - uses Hazelcast (that would form cluster with other discovered instances),
+ *   suitable for MT and MP builds</li>
+ *   <li>semaphore-hazelcast-client - uses Hazelcast Client (that would connect to some existing cluster),
+ *   suitable for MT and MP builds</li>
+ *   <li>semaphore-cp-hazelcast-client - uses Hazelcast Client (that would connect to some existing cluster),
+ *   suitable for MT and MP builds. Uses CP subsystem to get semaphore and does NOT destroy them.</li>
+ * </ul>
+ * Read Hazelcast documentation how to configure it, but tests does provide some examples.
+ */
+@Named
+@Priority( Integer.MAX_VALUE )
+@Singleton
+public final class NamedSyncContextFactory
+        implements SyncContextFactory
+{
+    private final SyncContextFactoryAdapter syncContextFactoryAdapter;
+
+    @Inject
+    public NamedSyncContextFactory( final Map<String, Provider<NamedLockFactory>> factories )
+    {
+        String name = System.getProperty( "synccontext.named,factory", "local" );

Review comment:
       Fixing

##########
File path: maven-resolver-synccontext-named/src/main/java/org/eclipse/aether/synccontext/NamedSyncContextFactory.java
##########
@@ -0,0 +1,84 @@
+package org.eclipse.aether.synccontext;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Map;
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.impl.SyncContextFactory;
+import org.eclipse.aether.internal.named.NamedLockFactory;
+import org.eclipse.aether.internal.named.SyncContextFactoryAdapter;
+
+import javax.annotation.PreDestroy;
+import javax.annotation.Priority;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Provider;
+import javax.inject.Singleton;
+
+/**
+ * Named {@link SyncContextFactory} implementation that selects underlying {@link NamedLockFactory} implementation
+ * at creation. Known factory names are:
+ * <ul>
+ *   <li>rwlock-local - uses JVM ReentrantReadWriteLock, suitable for MT builds</li>
+ *   <li>rwlock-redisson - uses JVM ReentrantReadWriteLock, suitable for MT builds</li>

Review comment:
       Fixing




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas edited a comment on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas edited a comment on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-818693664


   > I understand this now, but am not happy with for the following reasons: We have a hard requirement on reentrancy, it is up to the lock to implement that properly. If some lock does not support it, you can employ your history for that (granted), but why impose it on locks which support it out of the box? Java's locks do perfectly fine, so does Redisson. I ran Redisson builds hundreds of times and the overhead was very little. I don't see a reason to impose another layer of emulation if the underlying lock just can be used passthrough. In fact, this can even cause bugs/weird behavior if we don't use the locks as intended.
   
   See https://github.com/cstamas/maven-resolver/pull/1 (locally passes test, let's see CI)
   
   But in general, I cannot emphasize enough: we use JVM iface ReadWriteLock (that is implemented by both ReentrantReadWriteLock and RedissonReadWriteLock) and that iface **state nothing** about required re-entrant capability of lock implementation. Anytway, the PR above removes questioned bits, pls review.
   
   Also, I don't quite understand the "We have a hard requirement on reentrancy", as `NamedLock` implementation are re-entrant. And for sure we do NOT have requirement on underlying constructs to be re-entrant (see semaphore case).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r524505861



##########
File path: maven-resolver-synccontext-named/src/main/java/org/eclipse/aether/internal/named/SyncContextFactoryAdapter.java
##########
@@ -0,0 +1,300 @@
+package org.eclipse.aether.internal.named;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+import org.eclipse.aether.util.ChecksumUtils;
+import org.eclipse.aether.util.ConfigUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.nio.charset.StandardCharsets;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Deque;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.TreeSet;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Adapter to adapt {@link NamedLockFactory} and {@link NamedLock} to {@link SyncContext}.
+ */
+public final class SyncContextFactoryAdapter
+{
+    private static final String DEFAULT_DISCRIMINATOR_DIGEST = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
+
+    private static final String DEFAULT_HOSTNAME = "localhost";
+
+    private static final Logger LOGGER = LoggerFactory.getLogger( SyncContextFactoryAdapter.class );
+
+    private static final long TIME = Long.getLong(
+        SyncContextFactoryAdapter.class.getName() + ".time", 10L
+    );
+
+    private static final TimeUnit TIME_UNIT = TimeUnit.valueOf( System.getProperty(
+        SyncContextFactoryAdapter.class.getName() + ".timeunit", TimeUnit.SECONDS.name()
+    ) );
+
+    private final NamedLockFactory namedLockFactory;
+
+    private final long time;
+
+    private final TimeUnit timeUnit;
+
+    private final String hostname;
+
+    public SyncContextFactoryAdapter( final NamedLockFactory namedLockFactory )
+    {
+        this( namedLockFactory, TIME, TIME_UNIT );
+    }
+
+    public SyncContextFactoryAdapter( final NamedLockFactory namedLockFactory,
+                                      final long time,
+                                      final TimeUnit timeUnit )
+    {
+        this.namedLockFactory = namedLockFactory;
+        this.time = time;
+        this.timeUnit = timeUnit;
+        this.hostname = getHostname();
+    }
+
+    private String getHostname()
+    {
+        try
+        {
+            return InetAddress.getLocalHost().getHostName();
+        }
+        catch ( UnknownHostException e )
+        {
+            LOGGER.warn( "Failed to get hostname, using '{}'", DEFAULT_HOSTNAME, e );
+            return DEFAULT_HOSTNAME;
+        }
+    }
+
+    public SyncContext newInstance( final RepositorySystemSession session, final boolean shared )
+    {
+        return new AdaptedLockSyncContext( session, hostname, namedLockFactory, time, timeUnit, shared );
+    }
+
+    public void shutdown()
+    {
+        namedLockFactory.shutdown();
+    }
+
+    private static class AdaptedLockSyncContext
+            implements SyncContext
+    {
+        private static final String CONFIG_PROP_DISCRIMINATOR = "aether.syncContext.named.discriminator";
+
+        private static final String KEY_PREFIX = "mvn:resolver:";
+
+        private static final Logger LOGGER = LoggerFactory.getLogger( AdaptedLockSyncContext.class );
+
+        private final RepositorySystemSession session;
+
+        private final String hostname;
+
+        private final NamedLockFactory namedLockFactory;
+
+        private final long time;
+
+        private final TimeUnit timeUnit;
+
+        private final boolean shared;
+
+        private final Map<String, NamedLock> locks = new LinkedHashMap<>();
+
+        private AdaptedLockSyncContext( final RepositorySystemSession session,
+                                        final String hostname,
+                                        final NamedLockFactory namedLockFactory,
+                                        final long time,
+                                        final TimeUnit timeUnit,
+                                        final boolean shared )
+        {
+            this.session = session;
+            this.hostname = hostname;
+            this.namedLockFactory = namedLockFactory;
+            this.time = time;
+            this.timeUnit = timeUnit;
+            this.shared = shared;
+        }
+
+        @Override
+        public void acquire( Collection<? extends Artifact> artifacts,
+                             Collection<? extends Metadata> metadatas )
+        {
+            // Deadlock prevention: https://stackoverflow.com/a/16780988/696632
+            // We must acquire multiple locks always in the same order!
+            Collection<String> keys = new TreeSet<>();
+            if ( artifacts != null )
+            {
+                for ( Artifact artifact : artifacts )
+                {
+                    // TODO Should we include extension and classifier too?
+                    String key = "artifact:" + artifact.getGroupId() + ":"
+                            + artifact.getArtifactId() + ":" + artifact.getBaseVersion();
+                    keys.add( key );
+                }
+            }
+
+            if ( metadatas != null )
+            {
+                for ( Metadata metadata : metadatas )
+                {
+                    StringBuilder key = new StringBuilder( "metadata:" );
+                    if ( !metadata.getGroupId().isEmpty() )
+                    {
+                        key.append( metadata.getGroupId() );
+                        if ( !metadata.getArtifactId().isEmpty() )
+                        {
+                            key.append( ':' ).append( metadata.getArtifactId() );
+                            if ( !metadata.getVersion().isEmpty() )
+                            {
+                                key.append( ':' ).append( metadata.getVersion() );
+                            }
+                        }
+                    }
+                    keys.add( key.toString() );
+                }
+            }
+
+            if ( keys.isEmpty() )
+            {
+                return;
+            }
+
+            String discriminator = createDiscriminator();
+            LOGGER.trace( "Using key discriminator '{}' during this session", discriminator );
+
+            LOGGER.trace( "Need {} {} lock(s) for {}", keys.size(), shared ? "read" : "write", keys );
+            int acquiredLockCount = 0;
+            int reacquiredLockCount = 0;
+            boolean doLock;
+            for ( String key : keys )
+            {
+                NamedLock namedLock = locks.get( key );
+                if ( namedLock == null )
+                {
+                    namedLock = namedLockFactory.getLock( KEY_PREFIX + discriminator + ":" + key );
+                    locks.put( key, namedLock );
+                    acquiredLockCount++;
+                    doLock = true;
+                }
+                else
+                {
+                    reacquiredLockCount++;
+                    doLock = false;
+                }
+
+                if ( doLock )
+                {
+                    try
+                    {
+                        boolean locked;
+                        if ( shared )
+                        {
+                            locked = namedLock.lockShared( time, timeUnit );
+                        }
+                        else
+                        {
+                            locked = namedLock.lockExclusively( time, timeUnit );
+                        }
+
+                        if ( !locked )
+                        {
+                            throw new IllegalStateException( "Could not lock "
+                                    + namedLock.name() + " (shared=" + shared + ")" );
+                        }
+                    }
+                    catch ( InterruptedException e )
+                    {
+                        Thread.currentThread().interrupt();
+                        throw new RuntimeException( e );
+                    }
+                }
+            }
+            LOGGER.trace( "Total new locks acquired: {}, total existing locks reacquired: {}",

Review comment:
       OK, I don't expect lock upgrade nor does `SyncContext`.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r568876466



##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/NoLockSyncContextFactory.java
##########
@@ -22,39 +22,42 @@
 import java.util.Collection;
 
 import javax.inject.Named;
+import javax.inject.Singleton;
 
 import org.eclipse.aether.RepositorySystemSession;
 import org.eclipse.aether.SyncContext;
 import org.eclipse.aether.artifact.Artifact;
-import org.eclipse.aether.spi.synccontext.SyncContextFactory;
 import org.eclipse.aether.metadata.Metadata;
 
 /**
  * A factory to create synchronization contexts. This default implementation does not provide any real
  * synchronization but merely completes the repository system.
  */
-@Named
-public class DefaultSyncContextFactory
-    implements SyncContextFactory, org.eclipse.aether.impl.SyncContextFactory
+@Singleton
+@Named( NoLockSyncContextFactory.NAME )
+public class NoLockSyncContextFactory

Review comment:
       If you really want to drop, just do, but I think it has its usecases. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] asfgit closed pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
asfgit closed pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-784020330


   Thanks for the ping. Will pick up again during this week.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-808807986


   I forgot to mention. I do really like the idea of the name mappers. I have used a similar approach in a completely different area years ago, but that code serves me daily thousands of times.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r549460800



##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/SyncContextFactoryAdapter.java
##########
@@ -0,0 +1,272 @@
+package org.eclipse.aether.internal.impl.synccontext;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+import org.eclipse.aether.named.NamedLock;
+import org.eclipse.aether.named.NamedLockFactory;
+import org.eclipse.aether.util.ChecksumUtils;
+import org.eclipse.aether.util.ConfigUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayDeque;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.TreeSet;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Adapter to adapt {@link NamedLockFactory} and {@link NamedLock} to {@link SyncContext}.
+ */
+public final class SyncContextFactoryAdapter
+{
+    private static final String DEFAULT_DISCRIMINATOR_DIGEST = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
+
+    private static final String DEFAULT_HOSTNAME = "localhost";
+
+    private static final Logger LOGGER = LoggerFactory.getLogger( SyncContextFactoryAdapter.class );
+
+    private final NamedLockFactory namedLockFactory;
+
+    private final long time;
+
+    private final TimeUnit timeUnit;
+
+    private final String hostname;
+
+    public SyncContextFactoryAdapter( final NamedLockFactory namedLockFactory,
+                                      final long time,
+                                      final TimeUnit timeUnit )
+    {
+        this.namedLockFactory = namedLockFactory;
+        this.time = time;
+        this.timeUnit = timeUnit;
+        this.hostname = getHostname();
+    }
+
+    private String getHostname()
+    {
+        try
+        {
+            return InetAddress.getLocalHost().getHostName();
+        }
+        catch ( UnknownHostException e )
+        {
+            LOGGER.warn( "Failed to get hostname, using '{}'", DEFAULT_HOSTNAME, e );
+            return DEFAULT_HOSTNAME;
+        }
+    }
+
+    public SyncContext newInstance( final RepositorySystemSession session, final boolean shared )
+    {
+        return new AdaptedLockSyncContext( session, hostname, namedLockFactory, time, timeUnit, shared );
+    }
+
+    public void shutdown()
+    {
+        namedLockFactory.shutdown();
+    }
+
+    private static class AdaptedLockSyncContext
+            implements SyncContext
+    {
+        private static final String CONFIG_PROP_DISCRIMINATOR = "aether.syncContext.named.discriminator";
+
+        private static final String KEY_PREFIX = "mvn:resolver:";
+
+        private static final Logger LOGGER = LoggerFactory.getLogger( AdaptedLockSyncContext.class );
+
+        private final RepositorySystemSession session;
+
+        private final String hostname;
+
+        private final NamedLockFactory namedLockFactory;
+
+        private final long time;
+
+        private final TimeUnit timeUnit;
+
+        private final boolean shared;
+
+        private final ArrayDeque<NamedLock> locks;
+
+        private AdaptedLockSyncContext( final RepositorySystemSession session,
+                                        final String hostname,
+                                        final NamedLockFactory namedLockFactory,
+                                        final long time,
+                                        final TimeUnit timeUnit,
+                                        final boolean shared )
+        {
+            this.session = session;
+            this.hostname = hostname;
+            this.namedLockFactory = namedLockFactory;
+            this.time = time;
+            this.timeUnit = timeUnit;
+            this.shared = shared;
+            this.locks = new ArrayDeque<>();
+        }
+
+        @Override
+        public void acquire( Collection<? extends Artifact> artifacts,
+                             Collection<? extends Metadata> metadatas )
+        {
+            // Deadlock prevention: https://stackoverflow.com/a/16780988/696632
+            // We must acquire multiple locks always in the same order!
+            Collection<String> keys = new TreeSet<>();
+            if ( artifacts != null )
+            {
+                for ( Artifact artifact : artifacts )
+                {
+                    // TODO Should we include extension and classifier too?
+                    String key = "artifact:" + artifact.getGroupId() + ":"
+                            + artifact.getArtifactId() + ":" + artifact.getBaseVersion();
+                    keys.add( key );
+                }
+            }
+
+            if ( metadatas != null )
+            {
+                for ( Metadata metadata : metadatas )
+                {
+                    StringBuilder key = new StringBuilder( "metadata:" );
+                    if ( !metadata.getGroupId().isEmpty() )
+                    {
+                        key.append( metadata.getGroupId() );
+                        if ( !metadata.getArtifactId().isEmpty() )
+                        {
+                            key.append( ':' ).append( metadata.getArtifactId() );
+                            if ( !metadata.getVersion().isEmpty() )
+                            {
+                                key.append( ':' ).append( metadata.getVersion() );
+                            }
+                        }
+                    }
+                    keys.add( key.toString() );
+                }
+            }
+
+            if ( keys.isEmpty() )
+            {
+                return;
+            }
+
+            String discriminator = createDiscriminator();
+            LOGGER.trace( "Using key discriminator '{}' during this session", discriminator );
+
+            LOGGER.trace( "Need {} {} lock(s) for {}", keys.size(), shared ? "read" : "write", keys );
+            int acquiredLockCount = 0;
+            for ( String key : keys )
+            {
+                NamedLock namedLock = namedLockFactory.getLock( KEY_PREFIX + discriminator + ":" + key );
+                try
+                {
+                    boolean locked;
+                    if ( shared )
+                    {
+                        locked = namedLock.lockShared( time, timeUnit );

Review comment:
       Fixed both: renamed and upped to 30s




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r570874900



##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/NoLockSyncContextFactory.java
##########
@@ -22,39 +22,42 @@
 import java.util.Collection;
 
 import javax.inject.Named;
+import javax.inject.Singleton;
 
 import org.eclipse.aether.RepositorySystemSession;
 import org.eclipse.aether.SyncContext;
 import org.eclipse.aether.artifact.Artifact;
-import org.eclipse.aether.spi.synccontext.SyncContextFactory;
 import org.eclipse.aether.metadata.Metadata;
 
 /**
  * A factory to create synchronization contexts. This default implementation does not provide any real
  * synchronization but merely completes the repository system.
  */
-@Named
-public class DefaultSyncContextFactory
-    implements SyncContextFactory, org.eclipse.aether.impl.SyncContextFactory
+@Singleton
+@Named( NoLockSyncContextFactory.NAME )
+public class NoLockSyncContextFactory

Review comment:
       kk, will leave it as is




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r524413810



##########
File path: maven-resolver-synccontext-named/src/main/java/org/eclipse/aether/internal/named/SyncContextFactoryAdapter.java
##########
@@ -0,0 +1,300 @@
+package org.eclipse.aether.internal.named;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+import org.eclipse.aether.util.ChecksumUtils;
+import org.eclipse.aether.util.ConfigUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.nio.charset.StandardCharsets;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Deque;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.TreeSet;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Adapter to adapt {@link NamedLockFactory} and {@link NamedLock} to {@link SyncContext}.
+ */
+public final class SyncContextFactoryAdapter
+{
+    private static final String DEFAULT_DISCRIMINATOR_DIGEST = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
+
+    private static final String DEFAULT_HOSTNAME = "localhost";
+
+    private static final Logger LOGGER = LoggerFactory.getLogger( SyncContextFactoryAdapter.class );
+
+    private static final long TIME = Long.getLong(
+        SyncContextFactoryAdapter.class.getName() + ".time", 10L
+    );
+
+    private static final TimeUnit TIME_UNIT = TimeUnit.valueOf( System.getProperty(
+        SyncContextFactoryAdapter.class.getName() + ".timeunit", TimeUnit.SECONDS.name()
+    ) );
+
+    private final NamedLockFactory namedLockFactory;
+
+    private final long time;
+
+    private final TimeUnit timeUnit;
+
+    private final String hostname;
+
+    public SyncContextFactoryAdapter( final NamedLockFactory namedLockFactory )
+    {
+        this( namedLockFactory, TIME, TIME_UNIT );
+    }
+
+    public SyncContextFactoryAdapter( final NamedLockFactory namedLockFactory,
+                                      final long time,
+                                      final TimeUnit timeUnit )
+    {
+        this.namedLockFactory = namedLockFactory;
+        this.time = time;
+        this.timeUnit = timeUnit;
+        this.hostname = getHostname();
+    }
+
+    private String getHostname()
+    {
+        try
+        {
+            return InetAddress.getLocalHost().getHostName();
+        }
+        catch ( UnknownHostException e )
+        {
+            LOGGER.warn( "Failed to get hostname, using '{}'", DEFAULT_HOSTNAME, e );
+            return DEFAULT_HOSTNAME;
+        }
+    }
+
+    public SyncContext newInstance( final RepositorySystemSession session, final boolean shared )
+    {
+        return new AdaptedLockSyncContext( session, hostname, namedLockFactory, time, timeUnit, shared );
+    }
+
+    public void shutdown()
+    {
+        namedLockFactory.shutdown();
+    }
+
+    private static class AdaptedLockSyncContext
+            implements SyncContext
+    {
+        private static final String CONFIG_PROP_DISCRIMINATOR = "aether.syncContext.named.discriminator";
+
+        private static final String KEY_PREFIX = "mvn:resolver:";
+
+        private static final Logger LOGGER = LoggerFactory.getLogger( AdaptedLockSyncContext.class );
+
+        private final RepositorySystemSession session;
+
+        private final String hostname;
+
+        private final NamedLockFactory namedLockFactory;
+
+        private final long time;
+
+        private final TimeUnit timeUnit;
+
+        private final boolean shared;
+
+        private final Map<String, NamedLock> locks = new LinkedHashMap<>();
+
+        private AdaptedLockSyncContext( final RepositorySystemSession session,
+                                        final String hostname,
+                                        final NamedLockFactory namedLockFactory,
+                                        final long time,
+                                        final TimeUnit timeUnit,
+                                        final boolean shared )
+        {
+            this.session = session;
+            this.hostname = hostname;
+            this.namedLockFactory = namedLockFactory;
+            this.time = time;
+            this.timeUnit = timeUnit;
+            this.shared = shared;
+        }
+
+        @Override
+        public void acquire( Collection<? extends Artifact> artifacts,
+                             Collection<? extends Metadata> metadatas )
+        {
+            // Deadlock prevention: https://stackoverflow.com/a/16780988/696632
+            // We must acquire multiple locks always in the same order!
+            Collection<String> keys = new TreeSet<>();
+            if ( artifacts != null )
+            {
+                for ( Artifact artifact : artifacts )
+                {
+                    // TODO Should we include extension and classifier too?
+                    String key = "artifact:" + artifact.getGroupId() + ":"
+                            + artifact.getArtifactId() + ":" + artifact.getBaseVersion();
+                    keys.add( key );
+                }
+            }
+
+            if ( metadatas != null )
+            {
+                for ( Metadata metadata : metadatas )
+                {
+                    StringBuilder key = new StringBuilder( "metadata:" );
+                    if ( !metadata.getGroupId().isEmpty() )
+                    {
+                        key.append( metadata.getGroupId() );
+                        if ( !metadata.getArtifactId().isEmpty() )
+                        {
+                            key.append( ':' ).append( metadata.getArtifactId() );
+                            if ( !metadata.getVersion().isEmpty() )
+                            {
+                                key.append( ':' ).append( metadata.getVersion() );
+                            }
+                        }
+                    }
+                    keys.add( key.toString() );
+                }
+            }
+
+            if ( keys.isEmpty() )
+            {
+                return;
+            }
+
+            String discriminator = createDiscriminator();
+            LOGGER.trace( "Using key discriminator '{}' during this session", discriminator );
+
+            LOGGER.trace( "Need {} {} lock(s) for {}", keys.size(), shared ? "read" : "write", keys );
+            int acquiredLockCount = 0;
+            int reacquiredLockCount = 0;
+            boolean doLock;
+            for ( String key : keys )
+            {
+                NamedLock namedLock = locks.get( key );
+                if ( namedLock == null )
+                {
+                    namedLock = namedLockFactory.getLock( KEY_PREFIX + discriminator + ":" + key );
+                    locks.put( key, namedLock );
+                    acquiredLockCount++;
+                    doLock = true;
+                }
+                else
+                {
+                    reacquiredLockCount++;

Review comment:
       There is no reacquisition anymore because there is no reentrancy used.

##########
File path: maven-resolver-synccontext-named/src/main/java/org/eclipse/aether/synccontext/NamedSyncContextFactory.java
##########
@@ -0,0 +1,84 @@
+package org.eclipse.aether.synccontext;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Map;
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.impl.SyncContextFactory;
+import org.eclipse.aether.internal.named.NamedLockFactory;
+import org.eclipse.aether.internal.named.SyncContextFactoryAdapter;
+
+import javax.annotation.PreDestroy;
+import javax.annotation.Priority;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Provider;
+import javax.inject.Singleton;
+
+/**
+ * Named {@link SyncContextFactory} implementation that selects underlying {@link NamedLockFactory} implementation
+ * at creation. Known factory names are:
+ * <ul>
+ *   <li>rwlock-local - uses JVM ReentrantReadWriteLock, suitable for MT builds</li>
+ *   <li>rwlock-redisson - uses JVM ReentrantReadWriteLock, suitable for MT builds</li>

Review comment:
       This documentation seems wrong

##########
File path: maven-resolver-synccontext-named/src/main/java/org/eclipse/aether/synccontext/NamedSyncContextFactory.java
##########
@@ -0,0 +1,84 @@
+package org.eclipse.aether.synccontext;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Map;
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.impl.SyncContextFactory;
+import org.eclipse.aether.internal.named.NamedLockFactory;
+import org.eclipse.aether.internal.named.SyncContextFactoryAdapter;
+
+import javax.annotation.PreDestroy;
+import javax.annotation.Priority;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Provider;
+import javax.inject.Singleton;
+
+/**
+ * Named {@link SyncContextFactory} implementation that selects underlying {@link NamedLockFactory} implementation
+ * at creation. Known factory names are:
+ * <ul>
+ *   <li>rwlock-local - uses JVM ReentrantReadWriteLock, suitable for MT builds</li>
+ *   <li>rwlock-redisson - uses JVM ReentrantReadWriteLock, suitable for MT builds</li>
+ *   <li>semaphore-local - uses JVM Semaphore, suitable for MT builds</li>
+ *   <li>semaphore-hazelcast - uses Hazelcast (that would form cluster with other discovered instances),
+ *   suitable for MT and MP builds</li>
+ *   <li>semaphore-hazelcast-client - uses Hazelcast Client (that would connect to some existing cluster),
+ *   suitable for MT and MP builds</li>
+ *   <li>semaphore-cp-hazelcast-client - uses Hazelcast Client (that would connect to some existing cluster),
+ *   suitable for MT and MP builds. Uses CP subsystem to get semaphore and does NOT destroy them.</li>
+ * </ul>
+ * Read Hazelcast documentation how to configure it, but tests does provide some examples.
+ */
+@Named
+@Priority( Integer.MAX_VALUE )
+@Singleton
+public final class NamedSyncContextFactory
+        implements SyncContextFactory
+{
+    private final SyncContextFactoryAdapter syncContextFactoryAdapter;
+
+    @Inject
+    public NamedSyncContextFactory( final Map<String, Provider<NamedLockFactory>> factories )
+    {
+        String name = System.getProperty( "synccontext.named,factory", "local" );

Review comment:
       Here is a typo

##########
File path: maven-resolver-synccontext-named/src/main/java/org/eclipse/aether/internal/named/impl/AdaptedSemaphoreNamedLock.java
##########
@@ -0,0 +1,115 @@
+package org.eclipse.aether.internal.named.impl;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.internal.named.NamedLockFactorySupport;
+import org.eclipse.aether.internal.named.NamedLockSupport;
+
+import java.util.ArrayDeque;
+import java.util.Deque;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Named lock support implementation that is using "adapted" semaphore (to be able to use semaphores not sharing common
+ * API).
+ */
+public class AdaptedSemaphoreNamedLock
+        extends NamedLockSupport
+{
+    /**
+     * Wrapper for semaphore-like stuff, that do not share common ancestor. Semaphore must be created to support
+     * {@link Integer#MAX_VALUE} permissions.
+     */
+    protected interface AdaptedSemaphore
+    {
+        boolean tryAcquire( int perms, long time, TimeUnit unit ) throws InterruptedException;
+
+        void release( int perms );
+    }
+
+    private final ThreadLocal<Deque<Integer>> threadPerms;
+
+    private final AdaptedSemaphore semaphore;
+
+    public AdaptedSemaphoreNamedLock( final String name,
+                                      final NamedLockFactorySupport factory,
+                                      final AdaptedSemaphore semaphore )
+    {
+        super( name, factory );
+        this.threadPerms = ThreadLocal.withInitial( ArrayDeque::new );
+        this.semaphore = semaphore;
+    }
+
+    @Override
+    public boolean lockShared( final long time, final TimeUnit unit ) throws InterruptedException
+    {
+        Deque<Integer> perms = threadPerms.get();

Review comment:
       How is is locking based on a name?

##########
File path: maven-resolver-synccontext-named/src/main/java/org/eclipse/aether/internal/named/SyncContextFactoryAdapter.java
##########
@@ -0,0 +1,300 @@
+package org.eclipse.aether.internal.named;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+import org.eclipse.aether.util.ChecksumUtils;
+import org.eclipse.aether.util.ConfigUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.nio.charset.StandardCharsets;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Deque;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.TreeSet;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Adapter to adapt {@link NamedLockFactory} and {@link NamedLock} to {@link SyncContext}.
+ */
+public final class SyncContextFactoryAdapter
+{
+    private static final String DEFAULT_DISCRIMINATOR_DIGEST = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
+
+    private static final String DEFAULT_HOSTNAME = "localhost";
+
+    private static final Logger LOGGER = LoggerFactory.getLogger( SyncContextFactoryAdapter.class );
+
+    private static final long TIME = Long.getLong(
+        SyncContextFactoryAdapter.class.getName() + ".time", 10L
+    );
+
+    private static final TimeUnit TIME_UNIT = TimeUnit.valueOf( System.getProperty(
+        SyncContextFactoryAdapter.class.getName() + ".timeunit", TimeUnit.SECONDS.name()
+    ) );
+
+    private final NamedLockFactory namedLockFactory;
+
+    private final long time;
+
+    private final TimeUnit timeUnit;
+
+    private final String hostname;
+
+    public SyncContextFactoryAdapter( final NamedLockFactory namedLockFactory )
+    {
+        this( namedLockFactory, TIME, TIME_UNIT );
+    }
+
+    public SyncContextFactoryAdapter( final NamedLockFactory namedLockFactory,
+                                      final long time,
+                                      final TimeUnit timeUnit )
+    {
+        this.namedLockFactory = namedLockFactory;
+        this.time = time;
+        this.timeUnit = timeUnit;
+        this.hostname = getHostname();
+    }
+
+    private String getHostname()
+    {
+        try
+        {
+            return InetAddress.getLocalHost().getHostName();
+        }
+        catch ( UnknownHostException e )
+        {
+            LOGGER.warn( "Failed to get hostname, using '{}'", DEFAULT_HOSTNAME, e );
+            return DEFAULT_HOSTNAME;
+        }
+    }
+
+    public SyncContext newInstance( final RepositorySystemSession session, final boolean shared )
+    {
+        return new AdaptedLockSyncContext( session, hostname, namedLockFactory, time, timeUnit, shared );
+    }
+
+    public void shutdown()
+    {
+        namedLockFactory.shutdown();
+    }
+
+    private static class AdaptedLockSyncContext
+            implements SyncContext
+    {
+        private static final String CONFIG_PROP_DISCRIMINATOR = "aether.syncContext.named.discriminator";
+
+        private static final String KEY_PREFIX = "mvn:resolver:";
+
+        private static final Logger LOGGER = LoggerFactory.getLogger( AdaptedLockSyncContext.class );
+
+        private final RepositorySystemSession session;
+
+        private final String hostname;
+
+        private final NamedLockFactory namedLockFactory;
+
+        private final long time;
+
+        private final TimeUnit timeUnit;
+
+        private final boolean shared;
+
+        private final Map<String, NamedLock> locks = new LinkedHashMap<>();
+
+        private AdaptedLockSyncContext( final RepositorySystemSession session,
+                                        final String hostname,
+                                        final NamedLockFactory namedLockFactory,
+                                        final long time,
+                                        final TimeUnit timeUnit,
+                                        final boolean shared )
+        {
+            this.session = session;
+            this.hostname = hostname;
+            this.namedLockFactory = namedLockFactory;
+            this.time = time;
+            this.timeUnit = timeUnit;
+            this.shared = shared;
+        }
+
+        @Override
+        public void acquire( Collection<? extends Artifact> artifacts,
+                             Collection<? extends Metadata> metadatas )
+        {
+            // Deadlock prevention: https://stackoverflow.com/a/16780988/696632
+            // We must acquire multiple locks always in the same order!
+            Collection<String> keys = new TreeSet<>();
+            if ( artifacts != null )
+            {
+                for ( Artifact artifact : artifacts )
+                {
+                    // TODO Should we include extension and classifier too?
+                    String key = "artifact:" + artifact.getGroupId() + ":"
+                            + artifact.getArtifactId() + ":" + artifact.getBaseVersion();
+                    keys.add( key );
+                }
+            }
+
+            if ( metadatas != null )
+            {
+                for ( Metadata metadata : metadatas )
+                {
+                    StringBuilder key = new StringBuilder( "metadata:" );
+                    if ( !metadata.getGroupId().isEmpty() )
+                    {
+                        key.append( metadata.getGroupId() );
+                        if ( !metadata.getArtifactId().isEmpty() )
+                        {
+                            key.append( ':' ).append( metadata.getArtifactId() );
+                            if ( !metadata.getVersion().isEmpty() )
+                            {
+                                key.append( ':' ).append( metadata.getVersion() );
+                            }
+                        }
+                    }
+                    keys.add( key.toString() );
+                }
+            }
+
+            if ( keys.isEmpty() )
+            {
+                return;
+            }
+
+            String discriminator = createDiscriminator();
+            LOGGER.trace( "Using key discriminator '{}' during this session", discriminator );
+
+            LOGGER.trace( "Need {} {} lock(s) for {}", keys.size(), shared ? "read" : "write", keys );
+            int acquiredLockCount = 0;
+            int reacquiredLockCount = 0;
+            boolean doLock;
+            for ( String key : keys )
+            {
+                NamedLock namedLock = locks.get( key );
+                if ( namedLock == null )
+                {
+                    namedLock = namedLockFactory.getLock( KEY_PREFIX + discriminator + ":" + key );
+                    locks.put( key, namedLock );
+                    acquiredLockCount++;
+                    doLock = true;
+                }
+                else
+                {
+                    reacquiredLockCount++;
+                    doLock = false;
+                }
+
+                if ( doLock )
+                {
+                    try
+                    {
+                        boolean locked;
+                        if ( shared )
+                        {
+                            locked = namedLock.lockShared( time, timeUnit );
+                        }
+                        else
+                        {
+                            locked = namedLock.lockExclusively( time, timeUnit );
+                        }
+
+                        if ( !locked )
+                        {
+                            throw new IllegalStateException( "Could not lock "
+                                    + namedLock.name() + " (shared=" + shared + ")" );
+                        }
+                    }
+                    catch ( InterruptedException e )
+                    {
+                        Thread.currentThread().interrupt();
+                        throw new RuntimeException( e );
+                    }
+                }
+            }
+            LOGGER.trace( "Total new locks acquired: {}, total existing locks reacquired: {}",

Review comment:
       This is now misleading. I expect a decent lock to be reentrant.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r607136529



##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/DefaultSyncContextFactory.java
##########
@@ -0,0 +1,86 @@
+package org.eclipse.aether.internal.impl.synccontext;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.spi.synccontext.SyncContextFactory;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * Default {@link SyncContextFactory} implementation that delegates to some {@link SyncContextFactoryDelegate}
+ * implementation.
+ */
+@Singleton
+@Named
+public final class DefaultSyncContextFactory
+        implements SyncContextFactory, org.eclipse.aether.impl.SyncContextFactory
+{
+    private static final String SYNC_CONTEXT_FACTORY_NAME = System.getProperty(
+            "aether.syncContext.impl", NamedSyncContextFactory.NAME
+    );
+
+    private final SyncContextFactoryDelegate delegate;
+
+    /**
+     * Constructor used with DI, where factories are injected and selected based on key.
+     */
+    @Inject
+    public DefaultSyncContextFactory( final Map<String, SyncContextFactoryDelegate> delegates )
+    {
+        Objects.requireNonNull( delegates );
+        this.delegate = selectDelegate( delegates );
+    }
+
+    /**
+     * Default constructor.
+     */
+    public DefaultSyncContextFactory()
+    {
+        HashMap<String, SyncContextFactoryDelegate> delegates = new HashMap<>( 3 );
+        delegates.put( NoLockSyncContextFactory.NAME, new NoLockSyncContextFactory() );
+        delegates.put( GlobalSyncContextFactory.NAME, new GlobalSyncContextFactory() );
+        delegates.put( NamedSyncContextFactory.NAME, new NamedSyncContextFactory() );
+        this.delegate = selectDelegate( delegates );
+    }
+
+    private SyncContextFactoryDelegate selectDelegate( final Map<String, SyncContextFactoryDelegate> delegates )
+    {
+        SyncContextFactoryDelegate delegate = delegates.get( SYNC_CONTEXT_FACTORY_NAME );
+        if ( delegate == null )
+        {
+            throw new IllegalArgumentException( "Unknown SyncContextFactory impl: " + SYNC_CONTEXT_FACTORY_NAME

Review comment:
       Accepted.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-813444925


   > 
   > 
   > > A left a few comments, please go through.
   > > 
   > > * I have a few more homework to do because I do not fully understand all involved layers with `AdaptedReadWriteLockNamedLock` and `NamedLockFactorySupport`. I am bit worried that (Redisson) lock objects will be cached in memory although it is absolutely not always necessary because the Redission client will retrieve them anyway from the Redis instance when a lock operation is performed.
   > > * What is gone is the map with key lock and value integer. It has been replaced with a deque. From a technical point of view it is fine because it will retain reverse order lock release to avoid deadlocks. Though,  I intentionally have created the map because I wanted to print the reentrant lock count for debugging/analysis purposes.
   > > * After I will have established better understanding I will run tests.
   > > * What I do not understand is why bind name mappers and factories, but still assemble them manually instead of having a map injects with a provider/map with name key and object value?! Isn't this duplicate work/brittle?
   > 
   >     * Yes, they will be cached, for as long as the lock is in use. As we implement reference counting, they will be removed once the last lock using thread releases it.
   
   Looks sound!
   
   >     * we can add some debugging/analysis helpers around, if needed, but IMHO we did not lost too much here. What specifics you have on mind?
   
   What helps me a lot is that not only a lock is acquired, but how it is has been reacquired (if any) and that it has been released correctly. During my tests with Redisson I have noticed that debugging solely relying on logs is hard and it has to be good. Morever, as you know, debugging concurrent issues is almost not possible. So I prefer more log statements than less.
   Let me have a look at my current Redisson impl and get back to you.
   
   >     * OK
   
   +1
   
   >     * 😄 ServiceLocator: as long it is present, we need these "loops and hoops", make objects work with default ctor, "constant-looking params" and other trickeries... once ServiceLocator is gone, and only DI (SISU more specifically) is used, these things will get explicit and much more cleaner and use ctor injection purely.
   
   Makes sense.
   
   Will now go over to understand your code better.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r611909927



##########
File path: maven-resolver-named-locks/src/main/java/org/eclipse/aether/named/support/NamedLockSupport.java
##########
@@ -0,0 +1,87 @@
+package org.eclipse.aether.named.support;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.eclipse.aether.named.NamedLock;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Support class for {@link NamedLock} implementations providing reference counting.
+ */
+public abstract class NamedLockSupport
+    implements NamedLock
+{
+  protected final Logger log = LoggerFactory.getLogger( getClass() );
+
+  private final String name;
+
+  private final NamedLockFactorySupport factory;
+
+  private final AtomicInteger refCount;
+
+  public NamedLockSupport( final String name, final NamedLockFactorySupport factory )
+  {
+    this.name = name;
+    this.factory = factory;
+    this.refCount = new AtomicInteger( 0 );
+  }
+
+  public int incRef()
+  {
+    return refCount.incrementAndGet();
+  }
+
+  public int decRef()
+  {
+    return refCount.decrementAndGet();
+  }

Review comment:
       moved ref counting to factory, lock itself is unaware of it, see a1d5966e3ede80fc28a22675d2657723f1a061eb




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas edited a comment on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas edited a comment on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-818667466


   > There is one more thing I do not understand and think that this undermines reentrancy: While I understand that you maintain a concurrent map in `NamedLockFactorySupport` to manage locks (counts) between threads in one JVM to properly obtain and release them, but I fail to understand why both `AdaptedReadWriteLockNamedLock` and `AdaptedSemaphoreNamedLock` use thread locals to manage these locks. Looking at how lock and unlock are done, I don't see how underlying locks are used when reentrancy happens. Thus, the internal lock count is not increased, but you turn reentrancy into a `NOOP` and the end. Each call to `lockShared()`/`lockExclusively()` should be delegated to the underlying lock , no matter what. Please explain!
   
   So, while `NamedLock` is re-entrant, the underlying constructs are not always. For example, all the "semaphore-like" things are not re-entrant: each lock requires permissions to be taken from it (shared: ONE, exclusive: ALL). So, re-entrant capability with semaphores is implemented here by tracking "history" and avoiding doing steps not necessary (the condition is already met, then noop step is performed). On the other hand, with "lock-like" things same thing is done, as used `ReadWriteLock` does not state anything about re-entrant capability (is left to implementations), but here it could be considered as "optimization" as well, as none of these actually change anything on semantic. BUT, in both cases (semaphore and lock) when using some remote construct (like Hazelcast or Redisson constructs, or who knows what else may be used) all the lock/unlock calls performs remote calls, that require serialization, orchestration and all the things you really want to avoid, especially in cas
 e when the outcome would really not change anything (the condition you need, the lock level you want is already in your pocket).
   
   PS: intentionally write "semaphore-like" and "lock-like" things, as underlying constructs usually do not share common interface or ancestor, so we "adapt" them, but the term is more to express their "nature", or simpler, what is they principle how they work.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r611794011



##########
File path: maven-resolver-named-locks/src/main/java/org/eclipse/aether/named/support/AdaptedSemaphoreNamedLock.java
##########
@@ -0,0 +1,112 @@
+package org.eclipse.aether.named.support;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayDeque;
+import java.util.Deque;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Named lock support implementation that is using "adapted" semaphore (to be able to use semaphores not sharing common
+ * API).
+ */
+public class AdaptedSemaphoreNamedLock

Review comment:
       introduced static finals and documented in both classes them, review a2928ef8b68f030fe7ece882f197dce088cbe240 (and there is +1 commit for typo)




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-751682400


   @rmannibucau 
   1) This makes sense, but I don't want to create a mapping from properties to the object ob Redisson. The YAML configuration is so vast that I want to leave it to the user. As you can see in my code I tried to keep it as simple as possible.
   2) That's a good question. I thougt about providing a shaded über JAR for this, but don't know whether everything can be shaded or not.
   
   If you have ideas for 1), please provide.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-802992676


   Scheduled for this weekend...


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-813441893


   > 
   > 
   > General remark: my personal preference for local variables is to declare them as they are, so `Type variable = new Type()`, in cases when the variable is strictly local scoped. I really see no value in doing `Supertype variable = new Type()` when the `variable` is used in local scope only. Is not only more logical to me, but lessens import count as well (Type vs Supertype in example above).
   
   I understand your position, but have you looked how the overall code looks like? It is using supertypes (interfaces) only. I'd like to keep the codebase consistent.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-818891595


   K, merged the "mini PR", I hope this addresses all your concerns.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-731606060


   That's right


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r568875978



##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/NoLockSyncContextFactory.java
##########
@@ -22,39 +22,42 @@
 import java.util.Collection;
 
 import javax.inject.Named;
+import javax.inject.Singleton;
 
 import org.eclipse.aether.RepositorySystemSession;
 import org.eclipse.aether.SyncContext;
 import org.eclipse.aether.artifact.Artifact;
-import org.eclipse.aether.spi.synccontext.SyncContextFactory;
 import org.eclipse.aether.metadata.Metadata;
 
 /**
  * A factory to create synchronization contexts. This default implementation does not provide any real
  * synchronization but merely completes the repository system.
  */
-@Named
-public class DefaultSyncContextFactory
-    implements SyncContextFactory, org.eclipse.aether.impl.SyncContextFactory
+@Singleton
+@Named( NoLockSyncContextFactory.NAME )
+public class NoLockSyncContextFactory

Review comment:
       That is absolutely correct, but shouldn't it remain for testing purposes and proof that real code works? 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-731602192


   3 nodes are required for CP only w/ Hazelcast 3.x cluster (RAFT consensus backed structures), and yes, is overkill (but someone may choose to run a "dedicated cluster" on CI nodes anyway). For non-CP stuff, single "node" that is started by provider itself is completely okay.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-822059795


   @cstamas Ran the first tests with:
   ```
   for run in {1..5}; do echo "Testing run #$run"; rm -rf repo; ~/apache-maven-4.0.0-alpha-1-SNAPSHOT/bin/mvn clean install -Prun-its,embedded -Dmaven.repo.local=`pwd`/repo -B -Daether.syncContext.impl=named -l rwlock-local-log-$run ; done
   
   for run in {1..5}; do echo "Testing run #$run"; rm -rf repo; ~/apache-maven-4.0.0-alpha-1-SNAPSHOT/bin/mvn clean install -Prun-its,embedded -Dmaven.repo.local=`pwd`/repo -B -Daether.syncContext.impl=nolock -l nolock-log-$run ; done
   ```
   
   Had to add more logging and noticed this:
   ```
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Need 31 write lock(s) for [artifact:commons-io:commons-io:2.5, artifact:org.apache.commons:commons-compress:1.14, artifact:org.apache.maven.plugins:maven-jar-plugin:3.1.0, artifact:org.apache.maven.shared:maven-shared-utils:3.2.0, artifact:org.apache.maven:maven-aether-provider:3.0, artifact:org.apache.maven:maven-archiver:3.2.0, artifact:org.apache.maven:maven-artifact:3.0, artifact:org.apache.maven:maven-core:3.0, artifact:org.apache.maven:maven-model-builder:3.0, artifact:org.apache.maven:maven-model:3.0, artifact:org.apache.maven:maven-plugin-api:3.0, artifact:org.apache.maven:maven-repository-metadata:3.0, artifact:org.apache.maven:maven-settings-builder:3.0, artifact:org.apache.maven:maven-settings:3.0, artifact:org.codehaus.plexus:plexus-archiver:3.5, artifact:org.codehaus.plexus:plexus-classworlds:2.2.3, artifact:org.codehaus.plexus:plexus-component-annotations:1.7.1, artifact:org.codehaus.plexus:plexus-interp
 olation:1.14, artifact:org.codehaus.plexus:plexus-io:3.0.0, artifact:org.codehaus.plexus:plexus-utils:3.1.0, artifact:org.iq80.snappy:snappy:0.4, artifact:org.sonatype.aether:aether-api:1.7, artifact:org.sonatype.aether:aether-impl:1.7, artifact:org.sonatype.aether:aether-spi:1.7, artifact:org.sonatype.aether:aether-util:1.7, artifact:org.sonatype.plexus:plexus-cipher:1.4, artifact:org.sonatype.plexus:plexus-sec-dispatcher:1.3, artifact:org.sonatype.sisu:sisu-guice:2.1.7, artifact:org.sonatype.sisu:sisu-inject-bean:1.4.2, artifact:org.sonatype.sisu:sisu-inject-plexus:1.4.2, artifact:org.tukaani:xz:1.6]
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Acquiring write lock for 'artifact:commons-io:commons-io:2.5'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Acquiring write lock for 'artifact:org.apache.commons:commons-compress:1.14'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Acquiring write lock for 'artifact:org.apache.maven.plugins:maven-jar-plugin:3.1.0'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Acquiring write lock for 'artifact:org.apache.maven.shared:maven-shared-utils:3.2.0'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Acquiring write lock for 'artifact:org.apache.maven:maven-aether-provider:3.0'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Acquiring write lock for 'artifact:org.apache.maven:maven-archiver:3.2.0'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Acquiring write lock for 'artifact:org.apache.maven:maven-artifact:3.0'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Acquiring write lock for 'artifact:org.apache.maven:maven-core:3.0'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Acquiring write lock for 'artifact:org.apache.maven:maven-model-builder:3.0'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Acquiring write lock for 'artifact:org.apache.maven:maven-model:3.0'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Acquiring write lock for 'artifact:org.apache.maven:maven-plugin-api:3.0'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Acquiring write lock for 'artifact:org.apache.maven:maven-repository-metadata:3.0'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Acquiring write lock for 'artifact:org.apache.maven:maven-settings-builder:3.0'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Acquiring write lock for 'artifact:org.apache.maven:maven-settings:3.0'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Acquiring write lock for 'artifact:org.codehaus.plexus:plexus-archiver:3.5'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Acquiring write lock for 'artifact:org.codehaus.plexus:plexus-classworlds:2.2.3'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Acquiring write lock for 'artifact:org.codehaus.plexus:plexus-component-annotations:1.7.1'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Acquiring write lock for 'artifact:org.codehaus.plexus:plexus-interpolation:1.14'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Acquiring write lock for 'artifact:org.codehaus.plexus:plexus-io:3.0.0'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Acquiring write lock for 'artifact:org.codehaus.plexus:plexus-utils:3.1.0'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Acquiring write lock for 'artifact:org.iq80.snappy:snappy:0.4'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Acquiring write lock for 'artifact:org.sonatype.aether:aether-api:1.7'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Acquiring write lock for 'artifact:org.sonatype.aether:aether-impl:1.7'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Acquiring write lock for 'artifact:org.sonatype.aether:aether-spi:1.7'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Acquiring write lock for 'artifact:org.sonatype.aether:aether-util:1.7'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Acquiring write lock for 'artifact:org.sonatype.plexus:plexus-cipher:1.4'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Acquiring write lock for 'artifact:org.sonatype.plexus:plexus-sec-dispatcher:1.3'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Acquiring write lock for 'artifact:org.sonatype.sisu:sisu-guice:2.1.7'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Acquiring write lock for 'artifact:org.sonatype.sisu:sisu-inject-bean:1.4.2'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Acquiring write lock for 'artifact:org.sonatype.sisu:sisu-inject-plexus:1.4.2'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Acquiring write lock for 'artifact:org.tukaani:xz:1.6'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Total locks acquired: 31
   [main] [DEBUG] DefaultTransporterProvider - Using transporter WagonTransporter with priority -1.0 for http://bsd1srv.fritz.box:8081/nexus/content/repositories/central/
   [main] [DEBUG] DefaultRepositoryConnectorProvider - Using connector BasicRepositoryConnector with priority 0.0 for http://bsd1srv.fritz.box:8081/nexus/content/repositories/central/
   [BasicRepositoryConnector-bsd1srv.fritz.box-12-0] [INFO] Slf4jMavenTransferListener - Downloading from nexus: http://bsd1srv.fritz.box:8081/nexus/content/repositories/central/org/apache/maven/maven-archiver/3.2.0/maven-archiver-3.2.0.jar
   [BasicRepositoryConnector-bsd1srv.fritz.box-12-1] [INFO] Slf4jMavenTransferListener - Downloading from nexus: http://bsd1srv.fritz.box:8081/nexus/content/repositories/central/org/apache/maven/shared/maven-shared-utils/3.2.0/maven-shared-utils-3.2.0.jar
   [BasicRepositoryConnector-bsd1srv.fritz.box-12-3] [INFO] Slf4jMavenTransferListener - Downloading from nexus: http://bsd1srv.fritz.box:8081/nexus/content/repositories/central/org/codehaus/plexus/plexus-io/3.0.0/plexus-io-3.0.0.jar
   [BasicRepositoryConnector-bsd1srv.fritz.box-12-4] [INFO] Slf4jMavenTransferListener - Downloading from nexus: http://bsd1srv.fritz.box:8081/nexus/content/repositories/central/org/apache/commons/commons-compress/1.14/commons-compress-1.14.jar
   [BasicRepositoryConnector-bsd1srv.fritz.box-12-3] [INFO] Slf4jMavenTransferListener - Downloaded from nexus: http://bsd1srv.fritz.box:8081/nexus/content/repositories/central/org/codehaus/plexus/plexus-io/3.0.0/plexus-io-3.0.0.jar (74 kB at 11 MB/s)
   [BasicRepositoryConnector-bsd1srv.fritz.box-12-3] [INFO] Slf4jMavenTransferListener - Downloading from nexus: http://bsd1srv.fritz.box:8081/nexus/content/repositories/central/org/tukaani/xz/1.6/xz-1.6.jar
   [BasicRepositoryConnector-bsd1srv.fritz.box-12-2] [INFO] Slf4jMavenTransferListener - Downloading from nexus: http://bsd1srv.fritz.box:8081/nexus/content/repositories/central/org/codehaus/plexus/plexus-archiver/3.5/plexus-archiver-3.5.jar
   [BasicRepositoryConnector-bsd1srv.fritz.box-12-4] [INFO] Slf4jMavenTransferListener - Downloaded from nexus: http://bsd1srv.fritz.box:8081/nexus/content/repositories/central/org/apache/commons/commons-compress/1.14/commons-compress-1.14.jar (530 kB at 18 MB/s)
   [BasicRepositoryConnector-bsd1srv.fritz.box-12-3] [INFO] Slf4jMavenTransferListener - Downloaded from nexus: http://bsd1srv.fritz.box:8081/nexus/content/repositories/central/org/tukaani/xz/1.6/xz-1.6.jar (103 kB at 3.4 MB/s)
   [BasicRepositoryConnector-bsd1srv.fritz.box-12-0] [INFO] Slf4jMavenTransferListener - Downloaded from nexus: http://bsd1srv.fritz.box:8081/nexus/content/repositories/central/org/apache/maven/maven-archiver/3.2.0/maven-archiver-3.2.0.jar (24 kB at 741 kB/s)
   [BasicRepositoryConnector-bsd1srv.fritz.box-12-1] [INFO] Slf4jMavenTransferListener - Downloaded from nexus: http://bsd1srv.fritz.box:8081/nexus/content/repositories/central/org/apache/maven/shared/maven-shared-utils/3.2.0/maven-shared-utils-3.2.0.jar (165 kB at 5.2 MB/s)
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.sonatype.sisu:sisu-inject-plexus:1.4.2 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.sonatype.plexus:plexus-cipher:1.4 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.sonatype.plexus:plexus-sec-dispatcher:1.3 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.apache.maven.plugins:maven-jar-plugin:3.1.0 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.apache.maven:maven-archiver:3.2.0 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.apache.maven.shared:maven-shared-utils:3.2.0 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.codehaus.plexus:plexus-archiver:3.5 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.codehaus.plexus:plexus-io:3.0.0 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.apache.commons:commons-compress:1.14 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.tukaani:xz:1.6 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.apache.maven.plugins:maven-jar-plugin:3.1.0 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.apache.maven.plugins:maven-jar-plugin:3.1.0 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:commons-io:commons-io:2.5 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.apache.maven:maven-aether-provider:3.0 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.apache.maven:maven-artifact:3.0 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.apache.maven:maven-core:3.0 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.apache.maven:maven-model-builder:3.0 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.apache.maven:maven-model:3.0 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.apache.maven:maven-plugin-api:3.0 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.apache.maven:maven-repository-metadata:3.0 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.apache.maven:maven-settings-builder:3.0 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.apache.maven:maven-settings:3.0 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.codehaus.plexus:plexus-classworlds:2.2.3 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.codehaus.plexus:plexus-component-annotations:1.7.1 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.codehaus.plexus:plexus-utils:3.1.0 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.sonatype.aether:aether-api:1.7 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.sonatype.aether:aether-impl:1.7 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.sonatype.aether:aether-spi:1.7 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.sonatype.aether:aether-util:1.7 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.sonatype.plexus:plexus-cipher:1.4 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.sonatype.plexus:plexus-sec-dispatcher:1.3 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.sonatype.sisu:sisu-guice:2.1.7 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.sonatype.sisu:sisu-inject-bean:1.4.2 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.sonatype.sisu:sisu-inject-plexus:1.4.2 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:commons-io:commons-io:2.5 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.apache.maven:maven-aether-provider:3.0 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.apache.maven:maven-artifact:3.0 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.apache.maven:maven-core:3.0 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.apache.maven:maven-model-builder:3.0 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.apache.maven:maven-model:3.0 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.apache.maven:maven-plugin-api:3.0 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.apache.maven:maven-repository-metadata:3.0 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.apache.maven:maven-settings-builder:3.0 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.apache.maven:maven-settings:3.0 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.codehaus.plexus:plexus-classworlds:2.2.3 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.codehaus.plexus:plexus-interpolation:1.14 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.sonatype.aether:aether-api:1.7 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.sonatype.aether:aether-impl:1.7 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.sonatype.aether:aether-spi:1.7 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.sonatype.aether:aether-util:1.7 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.sonatype.plexus:plexus-cipher:1.4 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.sonatype.plexus:plexus-sec-dispatcher:1.3 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.sonatype.sisu:sisu-guice:2.1.7 references=1
   [Finalizer] [WARNING] ReadWriteLockNamedLock - NamedLock leak: artifact:org.sonatype.sisu:sisu-inject-bean:1.4.2 references=1
   [BasicRepositoryConnector-bsd1srv.fritz.box-12-2] [INFO] Slf4jMavenTransferListener - Downloaded from nexus: http://bsd1srv.fritz.box:8081/nexus/content/repositories/central/org/codehaus/plexus/plexus-archiver/3.5/plexus-archiver-3.5.jar (187 kB at 4.8 MB/s)
   [main] [DEBUG] TrackingFileManager - Writing tracking file /usr/home/mosipov/var/Projekte/maven-integration-testing/repo/org/apache/maven/maven-archiver/3.2.0/_remote.repositories
   [main] [DEBUG] TrackingFileManager - Writing tracking file /usr/home/mosipov/var/Projekte/maven-integration-testing/repo/org/apache/maven/maven-archiver/3.2.0/maven-archiver-3.2.0.jar.lastUpdated
   [main] [DEBUG] TrackingFileManager - Writing tracking file /usr/home/mosipov/var/Projekte/maven-integration-testing/repo/org/apache/maven/shared/maven-shared-utils/3.2.0/_remote.repositories
   [main] [DEBUG] TrackingFileManager - Writing tracking file /usr/home/mosipov/var/Projekte/maven-integration-testing/repo/org/apache/maven/shared/maven-shared-utils/3.2.0/maven-shared-utils-3.2.0.jar.lastUpdated
   [main] [DEBUG] TrackingFileManager - Writing tracking file /usr/home/mosipov/var/Projekte/maven-integration-testing/repo/org/codehaus/plexus/plexus-archiver/3.5/_remote.repositories
   [main] [DEBUG] TrackingFileManager - Writing tracking file /usr/home/mosipov/var/Projekte/maven-integration-testing/repo/org/codehaus/plexus/plexus-archiver/3.5/plexus-archiver-3.5.jar.lastUpdated
   [main] [DEBUG] TrackingFileManager - Writing tracking file /usr/home/mosipov/var/Projekte/maven-integration-testing/repo/org/codehaus/plexus/plexus-io/3.0.0/_remote.repositories
   [main] [DEBUG] TrackingFileManager - Writing tracking file /usr/home/mosipov/var/Projekte/maven-integration-testing/repo/org/codehaus/plexus/plexus-io/3.0.0/plexus-io-3.0.0.jar.lastUpdated
   [main] [DEBUG] TrackingFileManager - Writing tracking file /usr/home/mosipov/var/Projekte/maven-integration-testing/repo/org/apache/commons/commons-compress/1.14/_remote.repositories
   [main] [DEBUG] TrackingFileManager - Writing tracking file /usr/home/mosipov/var/Projekte/maven-integration-testing/repo/org/apache/commons/commons-compress/1.14/commons-compress-1.14.jar.lastUpdated
   [main] [DEBUG] TrackingFileManager - Writing tracking file /usr/home/mosipov/var/Projekte/maven-integration-testing/repo/org/tukaani/xz/1.6/_remote.repositories
   [main] [DEBUG] TrackingFileManager - Writing tracking file /usr/home/mosipov/var/Projekte/maven-integration-testing/repo/org/tukaani/xz/1.6/xz-1.6.jar.lastUpdated
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Releasing write lock for 'artifact:org.tukaani:xz:1.6'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Releasing write lock for 'artifact:org.sonatype.sisu:sisu-inject-plexus:1.4.2'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Releasing write lock for 'artifact:org.sonatype.sisu:sisu-inject-bean:1.4.2'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Releasing write lock for 'artifact:org.sonatype.sisu:sisu-guice:2.1.7'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Releasing write lock for 'artifact:org.sonatype.plexus:plexus-sec-dispatcher:1.3'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Releasing write lock for 'artifact:org.sonatype.plexus:plexus-cipher:1.4'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Releasing write lock for 'artifact:org.sonatype.aether:aether-util:1.7'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Releasing write lock for 'artifact:org.sonatype.aether:aether-spi:1.7'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Releasing write lock for 'artifact:org.sonatype.aether:aether-impl:1.7'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Releasing write lock for 'artifact:org.sonatype.aether:aether-api:1.7'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Releasing write lock for 'artifact:org.iq80.snappy:snappy:0.4'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Releasing write lock for 'artifact:org.codehaus.plexus:plexus-utils:3.1.0'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Releasing write lock for 'artifact:org.codehaus.plexus:plexus-io:3.0.0'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Releasing write lock for 'artifact:org.codehaus.plexus:plexus-interpolation:1.14'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Releasing write lock for 'artifact:org.codehaus.plexus:plexus-component-annotations:1.7.1'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Releasing write lock for 'artifact:org.codehaus.plexus:plexus-classworlds:2.2.3'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Releasing write lock for 'artifact:org.codehaus.plexus:plexus-archiver:3.5'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Releasing write lock for 'artifact:org.apache.maven:maven-settings:3.0'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Releasing write lock for 'artifact:org.apache.maven:maven-settings-builder:3.0'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Releasing write lock for 'artifact:org.apache.maven:maven-repository-metadata:3.0'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Releasing write lock for 'artifact:org.apache.maven:maven-plugin-api:3.0'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Releasing write lock for 'artifact:org.apache.maven:maven-model:3.0'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Releasing write lock for 'artifact:org.apache.maven:maven-model-builder:3.0'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Releasing write lock for 'artifact:org.apache.maven:maven-core:3.0'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Releasing write lock for 'artifact:org.apache.maven:maven-artifact:3.0'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Releasing write lock for 'artifact:org.apache.maven:maven-archiver:3.2.0'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Releasing write lock for 'artifact:org.apache.maven:maven-aether-provider:3.0'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Releasing write lock for 'artifact:org.apache.maven.shared:maven-shared-utils:3.2.0'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Releasing write lock for 'artifact:org.apache.maven.plugins:maven-jar-plugin:3.1.0'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Releasing write lock for 'artifact:org.apache.commons:commons-compress:1.14'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Releasing write lock for 'artifact:commons-io:commons-io:2.5'
   [main] [TRACE] NamedLockFactoryAdapter$AdaptedLockSyncContext - Total locks released: 31
   ```
   
   Can you tell whether `finalize()` is plaing tricks with us and showing false positives?
   
   I will continue testing...


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-764908120


   @michael-o @rmannibucau My proposal is to merge this PR, we already know current master is broken (see MRESOLVER-153), and while in this PR I did "return" (well, copied to new place) the `NoLockSyncContextFactory` (the `DefaultSyncContextFactory` that was noop, cause of MRESOLVER-153) I am now tempted to drop it, and merge.
   WDYT?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r605539574



##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/named/GAVNameMapper.java
##########
@@ -0,0 +1,89 @@
+package org.eclipse.aether.internal.impl.synccontext.named;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Collection;
+import java.util.TreeSet;
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+
+/**
+ * Artifact GAV {@link NameMapper}, uses artifact and metadata coordinates to name their corresponding locks. Is not
+ * considering local repository, only the artifact coordinates.
+ */
+@Singleton
+@Named( GAVNameMapper.NAME )
+public class GAVNameMapper
+    implements NameMapper
+{
+  public static final String NAME = "gav";
+
+  @Override
+  public TreeSet<String> nameLocks( final RepositorySystemSession session,

Review comment:
       It matter as much as interface implementation matter :smile: So, iface is `Collection` but implementation clearly says "am giving out sorted names". This is really an implementation detail here, no need to "mask" return type to `Collection`, as iface (and anyone coding against iface) use it "masked" already.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o edited a comment on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o edited a comment on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-808807986


   I forgot to mention: I do really like the idea of the name mappers. I have used a similar approach in a completely different area years ago, but that code serves me daily thousands of times.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r605520475



##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/impl/guice/AetherModule.java
##########
@@ -146,10 +161,77 @@ protected void configure()
         bind( LocalRepositoryManagerFactory.class ).annotatedWith( Names.named( "enhanced" ) ) //
         .to( EnhancedLocalRepositoryManagerFactory.class ).in( Singleton.class );
 
+        bind( SyncContextFactoryDelegate.class ).annotatedWith( Names.named( NoLockSyncContextFactory.NAME ) )
+                .to( NoLockSyncContextFactory.class ).in( Singleton.class );
+        bind( SyncContextFactoryDelegate.class ).annotatedWith( Names.named( GlobalSyncContextFactory.NAME ) )
+                .to( GlobalSyncContextFactory.class ).in( Singleton.class );
+        bind( SyncContextFactoryDelegate.class ).annotatedWith( Names.named( NamedSyncContextFactory.NAME ) )
+                .to( NamedSyncContextFactory.class ).in( Singleton.class );
+
+        bind( NameMapper.class ).annotatedWith( Names.named( StaticNameMapper.NAME ) )
+            .to( StaticNameMapper.class ).in( Singleton.class );
+        bind( NameMapper.class ).annotatedWith( Names.named( GAVNameMapper.NAME ) )
+            .to( GAVNameMapper.class ).in( Singleton.class );
+        bind( NameMapper.class ).annotatedWith( Names.named( DiscriminatingNameMapper.NAME ) )
+            .to( DiscriminatingNameMapper.class ).in( Singleton.class );
+        bind( NameMapper.class ).annotatedWith( Names.named( TakariNameMapper.NAME ) )
+            .to( TakariNameMapper.class ).in( Singleton.class );
+
+        bind( NamedLockFactory.class ).annotatedWith( Names.named( LocalReadWriteLockNamedLockFactory.NAME ) )
+                .to( LocalReadWriteLockNamedLockFactory.class ).in( Singleton.class );
+        bind( NamedLockFactory.class ).annotatedWith( Names.named( LocalSemaphoreNamedLockFactory.NAME ) )
+                .to( LocalSemaphoreNamedLockFactory.class ).in( Singleton.class );
+        bind( NamedLockFactory.class ).annotatedWith( Names.named( TakariNamedLockFactory.NAME ) )
+            .to( TakariNamedLockFactory.class ).in( Singleton.class );
+
         install( new Slf4jModule() );
 
     }
 
+    @Provides
+    @Singleton
+    Map<String, SyncContextFactoryDelegate> provideSyncContextFactoryDelegates(
+            @Named( NoLockSyncContextFactory.NAME ) SyncContextFactoryDelegate nolock,
+            @Named( GlobalSyncContextFactory.NAME ) SyncContextFactoryDelegate global,
+            @Named( NamedSyncContextFactory.NAME ) SyncContextFactoryDelegate named )
+    {
+        Map<String, SyncContextFactoryDelegate> factories = new HashMap<>();
+        factories.put( NoLockSyncContextFactory.NAME, nolock );
+        factories.put( GlobalSyncContextFactory.NAME, global );
+        factories.put( NamedSyncContextFactory.NAME, named );
+        return Collections.unmodifiableMap( factories );
+    }
+
+    @Provides
+    @Singleton
+    Map<String, NameMapper> provideNameMappers(
+        @Named( StaticNameMapper.NAME ) NameMapper staticNameMapper,
+        @Named( GAVNameMapper.NAME ) NameMapper gavNameMapper,
+        @Named( DiscriminatingNameMapper.NAME ) NameMapper lgavNameMapper,

Review comment:
       leftover, fixed. At one point it was "local repo + gav mapper", but since it got changed to use composition with gav mapper and became "discriminating"




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-731601543


   @michael-o Just go for it


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r611854531



##########
File path: maven-resolver-named-locks/src/main/java/org/eclipse/aether/named/NamedLock.java
##########
@@ -0,0 +1,71 @@
+package org.eclipse.aether.named;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * A named lock, functionally similar to existing JVM and other implementations. Must support boxing (reentrancy), but
+ * no lock upgrade is supported. Usual pattern to use this lock:
+ * <pre>
+ *   try (NamedLock lock = factory.getLock("resourceName")) {
+ *     if (lock.lockExclusively(10L, Timeunit.SECONDS)) {
+ *       try {
+ *         ... exclusive access to "resourceName" resource gained here
+ *       }
+ *       finally {
+ *         lock.unlock();
+ *       }
+ *     }
+ *     else {
+ *       ... failed to gain access within specified time, handle it
+ *     }
+ *   }
+ * </pre>
+ */
+public interface NamedLock
+    extends AutoCloseable
+{
+  /**
+   * Returns this instance name, never null.
+   */
+  String name();
+
+  /**
+   * Tries to lock shared, may block for given time. If successful, returns {@code true}.
+   */
+  boolean lockShared( long time, TimeUnit unit ) throws InterruptedException;
+
+  /**
+   * Tries to lock exclusively, may block for given time. If successful, returns {@code true}.
+   */
+  boolean lockExclusively( long time, TimeUnit unit ) throws InterruptedException;
+
+  /**
+   * Unlocks the lock.
+   */
+  void unlock();
+
+  /**
+   * Closes the lock.
+   */
+  @Override
+  void close();

Review comment:
       This is better. Though the wording could be better:
   * When should be `close()` be performed before or after `unlock()`?
   * What happens when `close()` is called before `lock()`? Undefined behavior?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r605556278



##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/NamedSyncContextFactory.java
##########
@@ -0,0 +1,128 @@
+package org.eclipse.aether.internal.impl.synccontext;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.internal.impl.synccontext.named.DiscriminatingNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.GAVNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.NameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.NamedLockFactoryAdapter;
+import org.eclipse.aether.internal.impl.synccontext.named.StaticNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.takari.TakariNamedLockFactory;
+import org.eclipse.aether.internal.impl.synccontext.named.takari.TakariNameMapper;
+import org.eclipse.aether.named.NamedLockFactory;
+import org.eclipse.aether.named.providers.LocalReadWriteLockNamedLockFactory;
+import org.eclipse.aether.named.providers.LocalSemaphoreNamedLockFactory;
+
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Named {@link SyncContextFactoryDelegate} implementation that selects underlying {@link NamedLockFactory}
+ * implementation at creation.
+ */
+@Singleton
+@Named( NamedSyncContextFactory.NAME )
+public final class NamedSyncContextFactory
+        implements SyncContextFactoryDelegate
+{
+    public static final String NAME = "named";
+
+    private static final String FACTORY_NAME = System.getProperty(
+            "aether.syncContext.named.factory", LocalReadWriteLockNamedLockFactory.NAME
+    );
+
+    private static final String NAME_MAPPING = System.getProperty(
+        "aether.syncContext.named.nameMapping", DiscriminatingNameMapper.NAME
+    );
+
+    private static final long TIME_OUT = Long.getLong(
+            "aether.syncContext.named.timeOut", 30L
+    );
+
+    private static final TimeUnit TIME_UNIT = TimeUnit.valueOf( System.getProperty(
+            "aether.syncContext.named.timeUnit", TimeUnit.SECONDS.name()
+    ) );
+
+    private final NamedLockFactoryAdapter namedLockFactoryAdapter;
+
+    /**
+     * Constructor used with DI, where factories are injected and selected based on key.
+     */
+    @Inject
+    public NamedSyncContextFactory( final Map<String, NameMapper> nameMappers,
+                                    final Map<String, NamedLockFactory> factories )
+    {
+        this.namedLockFactoryAdapter = selectAndAdapt( nameMappers, factories );
+    }
+
+    /**
+     * Default constructor.
+     */
+    public NamedSyncContextFactory()
+    {
+        HashMap<String, NameMapper> nameMappers = new HashMap<>();
+        nameMappers.put( StaticNameMapper.NAME, new StaticNameMapper() );
+        nameMappers.put( GAVNameMapper.NAME, new GAVNameMapper() );
+        nameMappers.put( DiscriminatingNameMapper.NAME, new DiscriminatingNameMapper( new GAVNameMapper() ) );
+        nameMappers.put( TakariNameMapper.NAME, new TakariNameMapper() );
+        HashMap<String, NamedLockFactory> factories = new HashMap<>();
+        factories.put( LocalReadWriteLockNamedLockFactory.NAME, new LocalReadWriteLockNamedLockFactory() );
+        factories.put( LocalSemaphoreNamedLockFactory.NAME, new LocalSemaphoreNamedLockFactory() );
+        factories.put( TakariNamedLockFactory.NAME, new TakariNamedLockFactory() );
+        this.namedLockFactoryAdapter = selectAndAdapt( nameMappers, factories );
+    }
+
+    private static NamedLockFactoryAdapter selectAndAdapt( final Map<String, NameMapper> nameMappers,
+                                                           final Map<String, NamedLockFactory> factories )
+    {
+        NameMapper nameMapper = nameMappers.get( NAME_MAPPING );
+        if ( nameMapper == null )
+        {
+            throw new IllegalArgumentException( "Unknown NameMapper name: " + NAME_MAPPING
+                + ", known ones: " + nameMappers.keySet() );
+        }
+        NamedLockFactory factory = factories.get( FACTORY_NAME );
+        if ( factory == null )
+        {
+            throw new IllegalArgumentException( "Unknown NamedLockFactory name: " + FACTORY_NAME

Review comment:
       Commented on previous comment.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-817384481


   We need one lock per artifact to coordinate access to files.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-817376215


   @Tibor17  If I understand you correctly you want to obtain locks concurrently. If yes, this will be a source of deadlocks because they have to be acquired in serial from within one thread and then released in reversed in the same thread. I have done unsorted order and it deadlocked the process.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r549341209



##########
File path: maven-resolver-impl/pom.xml
##########
@@ -49,6 +49,10 @@
       <groupId>org.apache.maven.resolver</groupId>
       <artifactId>maven-resolver-spi</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.maven.resolver</groupId>
+      <artifactId>maven-resolver-named</artifactId>

Review comment:
       I think this is a bad name for an artifact id. It says that the Resolver is named. `maven-resolver-synccontext-named`?

##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/NamedSyncContextFactory.java
##########
@@ -0,0 +1,91 @@
+package org.eclipse.aether.internal.impl.synccontext;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.named.NamedLockFactory;
+import org.eclipse.aether.named.providers.LocalReadWriteLockProvider;
+import org.eclipse.aether.spi.synccontext.SyncContextFactory;
+
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Provider;
+import javax.inject.Singleton;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Named {@link SyncContextFactory} implementation that selects underlying {@link NamedLockFactory} implementation
+ * at creation.
+ */
+@Named
+@Singleton
+public final class NamedSyncContextFactory
+        implements SyncContextFactory
+{
+    private static final long TIME = Long.getLong(

Review comment:
       Isn't this rather a timeout?

##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/SyncContextFactoryAdapter.java
##########
@@ -0,0 +1,272 @@
+package org.eclipse.aether.internal.impl.synccontext;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+import org.eclipse.aether.named.NamedLock;
+import org.eclipse.aether.named.NamedLockFactory;
+import org.eclipse.aether.util.ChecksumUtils;
+import org.eclipse.aether.util.ConfigUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayDeque;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.TreeSet;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Adapter to adapt {@link NamedLockFactory} and {@link NamedLock} to {@link SyncContext}.
+ */
+public final class SyncContextFactoryAdapter
+{
+    private static final String DEFAULT_DISCRIMINATOR_DIGEST = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
+
+    private static final String DEFAULT_HOSTNAME = "localhost";
+
+    private static final Logger LOGGER = LoggerFactory.getLogger( SyncContextFactoryAdapter.class );
+
+    private final NamedLockFactory namedLockFactory;
+
+    private final long time;
+
+    private final TimeUnit timeUnit;
+
+    private final String hostname;
+
+    public SyncContextFactoryAdapter( final NamedLockFactory namedLockFactory,
+                                      final long time,
+                                      final TimeUnit timeUnit )
+    {
+        this.namedLockFactory = namedLockFactory;
+        this.time = time;
+        this.timeUnit = timeUnit;
+        this.hostname = getHostname();
+    }
+
+    private String getHostname()
+    {
+        try
+        {
+            return InetAddress.getLocalHost().getHostName();
+        }
+        catch ( UnknownHostException e )
+        {
+            LOGGER.warn( "Failed to get hostname, using '{}'", DEFAULT_HOSTNAME, e );
+            return DEFAULT_HOSTNAME;
+        }
+    }
+
+    public SyncContext newInstance( final RepositorySystemSession session, final boolean shared )
+    {
+        return new AdaptedLockSyncContext( session, hostname, namedLockFactory, time, timeUnit, shared );
+    }
+
+    public void shutdown()
+    {
+        namedLockFactory.shutdown();
+    }
+
+    private static class AdaptedLockSyncContext
+            implements SyncContext
+    {
+        private static final String CONFIG_PROP_DISCRIMINATOR = "aether.syncContext.named.discriminator";
+
+        private static final String KEY_PREFIX = "mvn:resolver:";
+
+        private static final Logger LOGGER = LoggerFactory.getLogger( AdaptedLockSyncContext.class );
+
+        private final RepositorySystemSession session;
+
+        private final String hostname;
+
+        private final NamedLockFactory namedLockFactory;
+
+        private final long time;
+
+        private final TimeUnit timeUnit;
+
+        private final boolean shared;
+
+        private final ArrayDeque<NamedLock> locks;
+
+        private AdaptedLockSyncContext( final RepositorySystemSession session,
+                                        final String hostname,
+                                        final NamedLockFactory namedLockFactory,
+                                        final long time,
+                                        final TimeUnit timeUnit,
+                                        final boolean shared )
+        {
+            this.session = session;
+            this.hostname = hostname;
+            this.namedLockFactory = namedLockFactory;
+            this.time = time;
+            this.timeUnit = timeUnit;
+            this.shared = shared;
+            this.locks = new ArrayDeque<>();
+        }
+
+        @Override
+        public void acquire( Collection<? extends Artifact> artifacts,
+                             Collection<? extends Metadata> metadatas )
+        {
+            // Deadlock prevention: https://stackoverflow.com/a/16780988/696632
+            // We must acquire multiple locks always in the same order!
+            Collection<String> keys = new TreeSet<>();
+            if ( artifacts != null )
+            {
+                for ( Artifact artifact : artifacts )
+                {
+                    // TODO Should we include extension and classifier too?
+                    String key = "artifact:" + artifact.getGroupId() + ":"
+                            + artifact.getArtifactId() + ":" + artifact.getBaseVersion();
+                    keys.add( key );
+                }
+            }
+
+            if ( metadatas != null )
+            {
+                for ( Metadata metadata : metadatas )
+                {
+                    StringBuilder key = new StringBuilder( "metadata:" );
+                    if ( !metadata.getGroupId().isEmpty() )
+                    {
+                        key.append( metadata.getGroupId() );
+                        if ( !metadata.getArtifactId().isEmpty() )
+                        {
+                            key.append( ':' ).append( metadata.getArtifactId() );
+                            if ( !metadata.getVersion().isEmpty() )
+                            {
+                                key.append( ':' ).append( metadata.getVersion() );
+                            }
+                        }
+                    }
+                    keys.add( key.toString() );
+                }
+            }
+
+            if ( keys.isEmpty() )
+            {
+                return;
+            }
+
+            String discriminator = createDiscriminator();
+            LOGGER.trace( "Using key discriminator '{}' during this session", discriminator );
+
+            LOGGER.trace( "Need {} {} lock(s) for {}", keys.size(), shared ? "read" : "write", keys );
+            int acquiredLockCount = 0;
+            for ( String key : keys )
+            {
+                NamedLock namedLock = namedLockFactory.getLock( KEY_PREFIX + discriminator + ":" + key );
+                try
+                {
+                    boolean locked;
+                    if ( shared )
+                    {
+                        locked = namedLock.lockShared( time, timeUnit );
+                    }
+                    else
+                    {
+                        locked = namedLock.lockExclusively( time, timeUnit );
+                    }
+
+                    if ( !locked )
+                    {
+                        namedLock.close();
+                        throw new IllegalStateException( "Could not lock "
+                                + namedLock.name() + " (shared=" + shared + ")" );
+                    }
+
+                    locks.push( namedLock );
+                    acquiredLockCount++;
+                }
+                catch ( InterruptedException e )
+                {
+                    Thread.currentThread().interrupt();
+                    throw new RuntimeException( e );
+                }
+            }
+            LOGGER.trace( "Total new locks acquired: {}", acquiredLockCount );
+        }
+
+        private String createDiscriminator()
+        {
+            String discriminator = ConfigUtils.getString( session, null, CONFIG_PROP_DISCRIMINATOR );
+
+            if ( discriminator == null || discriminator.isEmpty() )
+            {
+                File basedir = session.getLocalRepository().getBasedir();
+                discriminator = hostname + ":" + basedir;
+                try
+                {
+                    Map<String, Object> checksums = ChecksumUtils.calc(
+                            discriminator.getBytes( StandardCharsets.UTF_8 ),
+                            Collections.singletonList( "SHA-1" ) );
+                    Object checksum = checksums.get( "SHA-1" );
+
+                    if ( checksum instanceof Exception )
+                    {
+                        throw ( Exception ) checksum;
+                    }
+
+                    return String.valueOf( checksum );
+                }
+                catch ( Exception e )
+                {
+                    LOGGER.warn( "Failed to calculate discriminator digest, using '{}'",
+                            DEFAULT_DISCRIMINATOR_DIGEST, e );
+                    return DEFAULT_DISCRIMINATOR_DIGEST;
+                }
+            }
+
+            return discriminator;
+        }
+
+        @Override
+        public void close()
+        {
+            if ( locks.isEmpty() )
+            {
+                return;
+            }
+
+            // Release locks in reverse insertion order
+            int released = 0;
+            while ( !locks.isEmpty() )

Review comment:
       I understand that the array deque gives you the pop for free, but the map has more benefits.

##########
File path: maven-resolver-named-hazelcast/src/test/resources/hazelcast-client.xml
##########
@@ -0,0 +1,39 @@
+<?xml version="1.0"?>
+
+<!--
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file 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 KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+-->
+
+<hazelcast-client xmlns="http://www.hazelcast.com/schema/client-config"
+                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+                  xsi:schemaLocation="http://www.hazelcast.com/schema/client-config
+                  http://www.hazelcast.com/schema/client-config/hazelcast-client-config-3.12.xsd">
+
+    <group>
+        <name>maven-resolved-named</name>
+    </group>
+    <instance-name>client</instance-name>
+    <properties>
+        <property name="hazelcast.logging.type">slf4j</property>
+    </properties>
+    <network>
+        <cluster-members>
+            <address>127.0.0.1</address>

Review comment:
       This shoulc rather be `localhost` host otherwise other IPv4 local address won't bind or `::1`.

##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/NamedSyncContextFactory.java
##########
@@ -0,0 +1,91 @@
+package org.eclipse.aether.internal.impl.synccontext;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.named.NamedLockFactory;
+import org.eclipse.aether.named.providers.LocalReadWriteLockProvider;
+import org.eclipse.aether.spi.synccontext.SyncContextFactory;
+
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Provider;
+import javax.inject.Singleton;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Named {@link SyncContextFactory} implementation that selects underlying {@link NamedLockFactory} implementation
+ * at creation.
+ */
+@Named
+@Singleton
+public final class NamedSyncContextFactory

Review comment:
       All system properties for this class should start with `aether.syncContext.named.` to scope them for Resolver property.

##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/SyncContextFactoryAdapter.java
##########
@@ -0,0 +1,272 @@
+package org.eclipse.aether.internal.impl.synccontext;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+import org.eclipse.aether.named.NamedLock;
+import org.eclipse.aether.named.NamedLockFactory;
+import org.eclipse.aether.util.ChecksumUtils;
+import org.eclipse.aether.util.ConfigUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayDeque;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.TreeSet;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Adapter to adapt {@link NamedLockFactory} and {@link NamedLock} to {@link SyncContext}.
+ */
+public final class SyncContextFactoryAdapter
+{
+    private static final String DEFAULT_DISCRIMINATOR_DIGEST = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
+
+    private static final String DEFAULT_HOSTNAME = "localhost";
+
+    private static final Logger LOGGER = LoggerFactory.getLogger( SyncContextFactoryAdapter.class );
+
+    private final NamedLockFactory namedLockFactory;
+
+    private final long time;
+
+    private final TimeUnit timeUnit;
+
+    private final String hostname;
+
+    public SyncContextFactoryAdapter( final NamedLockFactory namedLockFactory,
+                                      final long time,
+                                      final TimeUnit timeUnit )
+    {
+        this.namedLockFactory = namedLockFactory;
+        this.time = time;
+        this.timeUnit = timeUnit;
+        this.hostname = getHostname();
+    }
+
+    private String getHostname()
+    {
+        try
+        {
+            return InetAddress.getLocalHost().getHostName();
+        }
+        catch ( UnknownHostException e )
+        {
+            LOGGER.warn( "Failed to get hostname, using '{}'", DEFAULT_HOSTNAME, e );
+            return DEFAULT_HOSTNAME;
+        }
+    }
+
+    public SyncContext newInstance( final RepositorySystemSession session, final boolean shared )
+    {
+        return new AdaptedLockSyncContext( session, hostname, namedLockFactory, time, timeUnit, shared );
+    }
+
+    public void shutdown()
+    {
+        namedLockFactory.shutdown();
+    }
+
+    private static class AdaptedLockSyncContext
+            implements SyncContext
+    {
+        private static final String CONFIG_PROP_DISCRIMINATOR = "aether.syncContext.named.discriminator";
+
+        private static final String KEY_PREFIX = "mvn:resolver:";
+
+        private static final Logger LOGGER = LoggerFactory.getLogger( AdaptedLockSyncContext.class );
+
+        private final RepositorySystemSession session;
+
+        private final String hostname;
+
+        private final NamedLockFactory namedLockFactory;
+
+        private final long time;
+
+        private final TimeUnit timeUnit;
+
+        private final boolean shared;
+
+        private final ArrayDeque<NamedLock> locks;
+
+        private AdaptedLockSyncContext( final RepositorySystemSession session,
+                                        final String hostname,
+                                        final NamedLockFactory namedLockFactory,
+                                        final long time,
+                                        final TimeUnit timeUnit,
+                                        final boolean shared )
+        {
+            this.session = session;
+            this.hostname = hostname;
+            this.namedLockFactory = namedLockFactory;
+            this.time = time;
+            this.timeUnit = timeUnit;
+            this.shared = shared;
+            this.locks = new ArrayDeque<>();
+        }
+
+        @Override
+        public void acquire( Collection<? extends Artifact> artifacts,
+                             Collection<? extends Metadata> metadatas )
+        {
+            // Deadlock prevention: https://stackoverflow.com/a/16780988/696632
+            // We must acquire multiple locks always in the same order!
+            Collection<String> keys = new TreeSet<>();
+            if ( artifacts != null )
+            {
+                for ( Artifact artifact : artifacts )
+                {
+                    // TODO Should we include extension and classifier too?
+                    String key = "artifact:" + artifact.getGroupId() + ":"
+                            + artifact.getArtifactId() + ":" + artifact.getBaseVersion();
+                    keys.add( key );
+                }
+            }
+
+            if ( metadatas != null )
+            {
+                for ( Metadata metadata : metadatas )
+                {
+                    StringBuilder key = new StringBuilder( "metadata:" );
+                    if ( !metadata.getGroupId().isEmpty() )
+                    {
+                        key.append( metadata.getGroupId() );
+                        if ( !metadata.getArtifactId().isEmpty() )
+                        {
+                            key.append( ':' ).append( metadata.getArtifactId() );
+                            if ( !metadata.getVersion().isEmpty() )
+                            {
+                                key.append( ':' ).append( metadata.getVersion() );
+                            }
+                        }
+                    }
+                    keys.add( key.toString() );
+                }
+            }
+
+            if ( keys.isEmpty() )
+            {
+                return;
+            }
+
+            String discriminator = createDiscriminator();
+            LOGGER.trace( "Using key discriminator '{}' during this session", discriminator );
+
+            LOGGER.trace( "Need {} {} lock(s) for {}", keys.size(), shared ? "read" : "write", keys );
+            int acquiredLockCount = 0;
+            for ( String key : keys )
+            {
+                NamedLock namedLock = namedLockFactory.getLock( KEY_PREFIX + discriminator + ":" + key );
+                try
+                {
+                    boolean locked;
+                    if ( shared )
+                    {
+                        locked = namedLock.lockShared( time, timeUnit );

Review comment:
       Now this is really a timeout, not just time. I am quite certain that this will fail with 10 s when large artifacts are transferred. But OK, users should adapt or we bump to 30 s.

##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/SyncContextFactoryAdapter.java
##########
@@ -0,0 +1,272 @@
+package org.eclipse.aether.internal.impl.synccontext;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+import org.eclipse.aether.named.NamedLock;
+import org.eclipse.aether.named.NamedLockFactory;
+import org.eclipse.aether.util.ChecksumUtils;
+import org.eclipse.aether.util.ConfigUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayDeque;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.TreeSet;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Adapter to adapt {@link NamedLockFactory} and {@link NamedLock} to {@link SyncContext}.
+ */
+public final class SyncContextFactoryAdapter
+{
+    private static final String DEFAULT_DISCRIMINATOR_DIGEST = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
+
+    private static final String DEFAULT_HOSTNAME = "localhost";
+
+    private static final Logger LOGGER = LoggerFactory.getLogger( SyncContextFactoryAdapter.class );
+
+    private final NamedLockFactory namedLockFactory;
+
+    private final long time;
+
+    private final TimeUnit timeUnit;
+
+    private final String hostname;
+
+    public SyncContextFactoryAdapter( final NamedLockFactory namedLockFactory,
+                                      final long time,
+                                      final TimeUnit timeUnit )
+    {
+        this.namedLockFactory = namedLockFactory;
+        this.time = time;
+        this.timeUnit = timeUnit;
+        this.hostname = getHostname();
+    }
+
+    private String getHostname()
+    {
+        try
+        {
+            return InetAddress.getLocalHost().getHostName();
+        }
+        catch ( UnknownHostException e )
+        {
+            LOGGER.warn( "Failed to get hostname, using '{}'", DEFAULT_HOSTNAME, e );
+            return DEFAULT_HOSTNAME;
+        }
+    }
+
+    public SyncContext newInstance( final RepositorySystemSession session, final boolean shared )
+    {
+        return new AdaptedLockSyncContext( session, hostname, namedLockFactory, time, timeUnit, shared );
+    }
+
+    public void shutdown()
+    {
+        namedLockFactory.shutdown();
+    }
+
+    private static class AdaptedLockSyncContext
+            implements SyncContext
+    {
+        private static final String CONFIG_PROP_DISCRIMINATOR = "aether.syncContext.named.discriminator";
+
+        private static final String KEY_PREFIX = "mvn:resolver:";

Review comment:
       This might be a matter of taste, but I rather prefix the full name here `maven:resolver:`. See https://github.com/apache/maven/pull/419/files#diff-c9096a367ccf68804df8750db73e4a5cc8493bfb3d46242442cd7418a9e110e0R248.

##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/SyncContextFactoryAdapter.java
##########
@@ -0,0 +1,272 @@
+package org.eclipse.aether.internal.impl.synccontext;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+import org.eclipse.aether.named.NamedLock;
+import org.eclipse.aether.named.NamedLockFactory;
+import org.eclipse.aether.util.ChecksumUtils;
+import org.eclipse.aether.util.ConfigUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayDeque;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.TreeSet;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Adapter to adapt {@link NamedLockFactory} and {@link NamedLock} to {@link SyncContext}.
+ */
+public final class SyncContextFactoryAdapter
+{
+    private static final String DEFAULT_DISCRIMINATOR_DIGEST = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
+
+    private static final String DEFAULT_HOSTNAME = "localhost";
+
+    private static final Logger LOGGER = LoggerFactory.getLogger( SyncContextFactoryAdapter.class );
+
+    private final NamedLockFactory namedLockFactory;
+
+    private final long time;
+
+    private final TimeUnit timeUnit;
+
+    private final String hostname;
+
+    public SyncContextFactoryAdapter( final NamedLockFactory namedLockFactory,
+                                      final long time,
+                                      final TimeUnit timeUnit )
+    {
+        this.namedLockFactory = namedLockFactory;
+        this.time = time;
+        this.timeUnit = timeUnit;
+        this.hostname = getHostname();
+    }
+
+    private String getHostname()
+    {
+        try
+        {
+            return InetAddress.getLocalHost().getHostName();
+        }
+        catch ( UnknownHostException e )
+        {
+            LOGGER.warn( "Failed to get hostname, using '{}'", DEFAULT_HOSTNAME, e );
+            return DEFAULT_HOSTNAME;
+        }
+    }
+
+    public SyncContext newInstance( final RepositorySystemSession session, final boolean shared )
+    {
+        return new AdaptedLockSyncContext( session, hostname, namedLockFactory, time, timeUnit, shared );
+    }
+
+    public void shutdown()
+    {
+        namedLockFactory.shutdown();
+    }
+
+    private static class AdaptedLockSyncContext
+            implements SyncContext
+    {
+        private static final String CONFIG_PROP_DISCRIMINATOR = "aether.syncContext.named.discriminator";
+
+        private static final String KEY_PREFIX = "mvn:resolver:";
+
+        private static final Logger LOGGER = LoggerFactory.getLogger( AdaptedLockSyncContext.class );
+
+        private final RepositorySystemSession session;
+
+        private final String hostname;
+
+        private final NamedLockFactory namedLockFactory;
+
+        private final long time;
+
+        private final TimeUnit timeUnit;
+
+        private final boolean shared;
+
+        private final ArrayDeque<NamedLock> locks;
+
+        private AdaptedLockSyncContext( final RepositorySystemSession session,
+                                        final String hostname,
+                                        final NamedLockFactory namedLockFactory,
+                                        final long time,
+                                        final TimeUnit timeUnit,
+                                        final boolean shared )
+        {
+            this.session = session;
+            this.hostname = hostname;
+            this.namedLockFactory = namedLockFactory;
+            this.time = time;
+            this.timeUnit = timeUnit;
+            this.shared = shared;
+            this.locks = new ArrayDeque<>();
+        }
+
+        @Override
+        public void acquire( Collection<? extends Artifact> artifacts,
+                             Collection<? extends Metadata> metadatas )
+        {
+            // Deadlock prevention: https://stackoverflow.com/a/16780988/696632
+            // We must acquire multiple locks always in the same order!
+            Collection<String> keys = new TreeSet<>();
+            if ( artifacts != null )
+            {
+                for ( Artifact artifact : artifacts )
+                {
+                    // TODO Should we include extension and classifier too?
+                    String key = "artifact:" + artifact.getGroupId() + ":"
+                            + artifact.getArtifactId() + ":" + artifact.getBaseVersion();
+                    keys.add( key );
+                }
+            }
+
+            if ( metadatas != null )
+            {
+                for ( Metadata metadata : metadatas )
+                {
+                    StringBuilder key = new StringBuilder( "metadata:" );
+                    if ( !metadata.getGroupId().isEmpty() )
+                    {
+                        key.append( metadata.getGroupId() );
+                        if ( !metadata.getArtifactId().isEmpty() )
+                        {
+                            key.append( ':' ).append( metadata.getArtifactId() );
+                            if ( !metadata.getVersion().isEmpty() )
+                            {
+                                key.append( ':' ).append( metadata.getVersion() );
+                            }
+                        }
+                    }
+                    keys.add( key.toString() );
+                }
+            }
+
+            if ( keys.isEmpty() )
+            {
+                return;
+            }
+
+            String discriminator = createDiscriminator();
+            LOGGER.trace( "Using key discriminator '{}' during this session", discriminator );
+
+            LOGGER.trace( "Need {} {} lock(s) for {}", keys.size(), shared ? "read" : "write", keys );
+            int acquiredLockCount = 0;
+            for ( String key : keys )
+            {
+                NamedLock namedLock = namedLockFactory.getLock( KEY_PREFIX + discriminator + ":" + key );
+                try
+                {
+                    boolean locked;
+                    if ( shared )
+                    {
+                        locked = namedLock.lockShared( time, timeUnit );
+                    }
+                    else
+                    {
+                        locked = namedLock.lockExclusively( time, timeUnit );
+                    }
+
+                    if ( !locked )
+                    {
+                        namedLock.close();
+                        throw new IllegalStateException( "Could not lock "
+                                + namedLock.name() + " (shared=" + shared + ")" );
+                    }
+
+                    locks.push( namedLock );

Review comment:
       Since you already cache locks, why not a the linked hash map to reuse the from for reacquision?

##########
File path: maven-resolver-named-hazelcast/src/site/site.xml
##########
@@ -22,7 +22,7 @@ under the License.
 <project xmlns="http://maven.apache.org/DECORATION/1.0.0"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/DECORATION/1.0.0 http://maven.apache.org/xsd/decoration-1.0.0.xsd"
-  name="GlobalSyncContext">
+  name="NamedSyncContext">

Review comment:
       The name says `NamedSyncContext` although this is Hazelcast?

##########
File path: maven-resolver-named-redisson/pom.xml
##########
@@ -28,51 +28,57 @@
     <version>1.7.0-SNAPSHOT</version>
   </parent>
 
-  <artifactId>maven-resolver-synccontext-redisson</artifactId>
+  <artifactId>maven-resolver-named-redisson</artifactId>

Review comment:
       See comment for `maven-resolver-named`.

##########
File path: maven-resolver-named/src/main/java/org/eclipse/aether/named/NamedLock.java
##########
@@ -0,0 +1,71 @@
+package org.eclipse.aether.named;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * A named lock, functionally similar to existing JVM and other implementations. Does support boxing, but no
+ * lock upgrade is supported. Usual pattern to use this lock:
+ * <pre>
+ *   try (NamedLock lock = factory.getLock("resourceName")) {
+ *     if (lock.lockExclusively(10L, Timeunit.SECONDS)) {
+ *       try {
+ *         ... exclusive access to "resourceName" resource gained here
+ *       }
+ *       finally {
+ *         lock.unlock();
+ *       }
+ *     }
+ *     else {
+ *       ... failed to gain access within specified time, handle it
+ *     }
+ *   }
+ * </pre>
+ */
+public interface NamedLock

Review comment:
       The documentation should clearly state that every implementation must support reentrancy. This is required by the `SyncContextFactory`.

##########
File path: maven-resolver-named-redisson/src/site/markdown/index.md.vm
##########
@@ -0,0 +1,69 @@
+${esc.hash} Named Sync Context for Maven Resolver
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+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
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+The Named Sync Context Factory is a distributed lock factory for Maven Resolver
+on top of JVM and Hazelcast to provide a fast, concurrent-safe access from one or multiple Maven instances to the
+same local Maven repository.
+
+For further details about the factory read the [Javadoc](./apidocs/org/eclipse/aether/synccontext/NamedSyncContextFactory.html).
+
+${esc.hash}${esc.hash} Open Issues/Notes
+
+- It only works when dependency injection is used and not the bundled `AetherModule` or
+  `ServiceLocator` (Maven uses dependency injection).
+- It includes a lot of trace logging which partially will go way as soon as it has been stabilized.
+- Usage from plugins has not been tested yet.
+- The `furnace-maven-plugin` does not work this implementation because it uses `ServiceLocator` instead
+  of dependency injection.
+
+${esc.hash}${esc.hash} Installation/Testing
+
+- Create the directory `${maven.home}/lib/ext/hazelcast/`.

Review comment:
       The file path says redisson while this covers Hazelcast.

##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/SyncContextFactoryAdapter.java
##########
@@ -0,0 +1,272 @@
+package org.eclipse.aether.internal.impl.synccontext;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+import org.eclipse.aether.named.NamedLock;
+import org.eclipse.aether.named.NamedLockFactory;
+import org.eclipse.aether.util.ChecksumUtils;
+import org.eclipse.aether.util.ConfigUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayDeque;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.TreeSet;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Adapter to adapt {@link NamedLockFactory} and {@link NamedLock} to {@link SyncContext}.
+ */
+public final class SyncContextFactoryAdapter
+{
+    private static final String DEFAULT_DISCRIMINATOR_DIGEST = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
+
+    private static final String DEFAULT_HOSTNAME = "localhost";
+
+    private static final Logger LOGGER = LoggerFactory.getLogger( SyncContextFactoryAdapter.class );
+
+    private final NamedLockFactory namedLockFactory;
+
+    private final long time;
+
+    private final TimeUnit timeUnit;
+
+    private final String hostname;
+
+    public SyncContextFactoryAdapter( final NamedLockFactory namedLockFactory,
+                                      final long time,
+                                      final TimeUnit timeUnit )
+    {
+        this.namedLockFactory = namedLockFactory;
+        this.time = time;
+        this.timeUnit = timeUnit;
+        this.hostname = getHostname();
+    }
+
+    private String getHostname()
+    {
+        try
+        {
+            return InetAddress.getLocalHost().getHostName();
+        }
+        catch ( UnknownHostException e )
+        {
+            LOGGER.warn( "Failed to get hostname, using '{}'", DEFAULT_HOSTNAME, e );
+            return DEFAULT_HOSTNAME;
+        }
+    }
+
+    public SyncContext newInstance( final RepositorySystemSession session, final boolean shared )
+    {
+        return new AdaptedLockSyncContext( session, hostname, namedLockFactory, time, timeUnit, shared );
+    }
+
+    public void shutdown()
+    {
+        namedLockFactory.shutdown();
+    }
+
+    private static class AdaptedLockSyncContext
+            implements SyncContext
+    {
+        private static final String CONFIG_PROP_DISCRIMINATOR = "aether.syncContext.named.discriminator";
+
+        private static final String KEY_PREFIX = "mvn:resolver:";
+
+        private static final Logger LOGGER = LoggerFactory.getLogger( AdaptedLockSyncContext.class );
+
+        private final RepositorySystemSession session;
+
+        private final String hostname;
+
+        private final NamedLockFactory namedLockFactory;
+
+        private final long time;
+
+        private final TimeUnit timeUnit;
+
+        private final boolean shared;
+
+        private final ArrayDeque<NamedLock> locks;
+
+        private AdaptedLockSyncContext( final RepositorySystemSession session,
+                                        final String hostname,
+                                        final NamedLockFactory namedLockFactory,
+                                        final long time,
+                                        final TimeUnit timeUnit,
+                                        final boolean shared )
+        {
+            this.session = session;
+            this.hostname = hostname;
+            this.namedLockFactory = namedLockFactory;
+            this.time = time;
+            this.timeUnit = timeUnit;
+            this.shared = shared;
+            this.locks = new ArrayDeque<>();
+        }
+
+        @Override
+        public void acquire( Collection<? extends Artifact> artifacts,
+                             Collection<? extends Metadata> metadatas )
+        {
+            // Deadlock prevention: https://stackoverflow.com/a/16780988/696632
+            // We must acquire multiple locks always in the same order!
+            Collection<String> keys = new TreeSet<>();
+            if ( artifacts != null )
+            {
+                for ( Artifact artifact : artifacts )
+                {
+                    // TODO Should we include extension and classifier too?
+                    String key = "artifact:" + artifact.getGroupId() + ":"
+                            + artifact.getArtifactId() + ":" + artifact.getBaseVersion();
+                    keys.add( key );
+                }
+            }
+
+            if ( metadatas != null )
+            {
+                for ( Metadata metadata : metadatas )
+                {
+                    StringBuilder key = new StringBuilder( "metadata:" );
+                    if ( !metadata.getGroupId().isEmpty() )
+                    {
+                        key.append( metadata.getGroupId() );
+                        if ( !metadata.getArtifactId().isEmpty() )
+                        {
+                            key.append( ':' ).append( metadata.getArtifactId() );
+                            if ( !metadata.getVersion().isEmpty() )
+                            {
+                                key.append( ':' ).append( metadata.getVersion() );
+                            }
+                        }
+                    }
+                    keys.add( key.toString() );
+                }
+            }
+
+            if ( keys.isEmpty() )
+            {
+                return;
+            }
+
+            String discriminator = createDiscriminator();
+            LOGGER.trace( "Using key discriminator '{}' during this session", discriminator );
+
+            LOGGER.trace( "Need {} {} lock(s) for {}", keys.size(), shared ? "read" : "write", keys );
+            int acquiredLockCount = 0;
+            for ( String key : keys )
+            {
+                NamedLock namedLock = namedLockFactory.getLock( KEY_PREFIX + discriminator + ":" + key );
+                try
+                {
+                    boolean locked;
+                    if ( shared )
+                    {
+                        locked = namedLock.lockShared( time, timeUnit );
+                    }
+                    else
+                    {
+                        locked = namedLock.lockExclusively( time, timeUnit );
+                    }
+
+                    if ( !locked )
+                    {
+                        namedLock.close();
+                        throw new IllegalStateException( "Could not lock "
+                                + namedLock.name() + " (shared=" + shared + ")" );
+                    }
+
+                    locks.push( namedLock );
+                    acquiredLockCount++;
+                }
+                catch ( InterruptedException e )
+                {
+                    Thread.currentThread().interrupt();
+                    throw new RuntimeException( e );
+                }
+            }
+            LOGGER.trace( "Total new locks acquired: {}", acquiredLockCount );

Review comment:
       This isn't true anymore. The reacquisition of locks is gone while from a debugging point of view I'd like to retain it. 

##########
File path: maven-resolver-named-redisson/src/site/site.xml
##########
@@ -22,7 +22,7 @@ under the License.
 <project xmlns="http://maven.apache.org/DECORATION/1.0.0"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/DECORATION/1.0.0 http://maven.apache.org/xsd/decoration-1.0.0.xsd"
-  name="RedissonSyncContext">
+  name="NamedSyncContext">

Review comment:
       Same as with Hazelcast.

##########
File path: maven-resolver-named/src/site/markdown/index.md.vm
##########
@@ -0,0 +1,69 @@
+${esc.hash} Named Sync Context for Maven Resolver
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+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
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+The Named Sync Context Factory is a distributed lock factory for Maven Resolver
+on top of JVM and Hazelcast to provide a fast, concurrent-safe access from one or multiple Maven instances to the
+same local Maven repository.
+
+For further details about the factory read the [Javadoc](./apidocs/org/eclipse/aether/synccontext/NamedSyncContextFactory.html).
+
+${esc.hash}${esc.hash} Open Issues/Notes
+
+- It only works when dependency injection is used and not the bundled `AetherModule` or
+  `ServiceLocator` (Maven uses dependency injection).
+- It includes a lot of trace logging which partially will go way as soon as it has been stabilized.
+- Usage from plugins has not been tested yet.
+- The `furnace-maven-plugin` does not work this implementation because it uses `ServiceLocator` instead
+  of dependency injection.
+
+${esc.hash}${esc.hash} Installation/Testing
+
+- Create the directory `${maven.home}/lib/ext/hazelcast/`.

Review comment:
       Same as the other file...

##########
File path: maven-resolver-named-hazelcast/src/test/resources/hazelcast.xml
##########
@@ -0,0 +1,42 @@
+<?xml version="1.0"?>
+
+<!--
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file 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 KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+-->
+
+<hazelcast xmlns="http://www.hazelcast.com/schema/config"
+           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+           xsi:schemaLocation="http://www.hazelcast.com/schema/config
+           http://www.hazelcast.com/schema/config/hazelcast-config-3.12.xsd">
+
+    <group>
+        <name>maven-resolved-named</name>
+    </group>
+    <instance-name>server</instance-name>
+    <properties>
+        <property name="hazelcast.logging.type">slf4j</property>
+    </properties>
+    <network>
+        <join>
+            <multicast enabled="false"/>
+            <tcp-ip>
+                <interface>127.0.0.1</interface>

Review comment:
       Same here

##########
File path: maven-resolver-named/src/main/java/org/eclipse/aether/named/providers/GlobalReadWriteLockProvider.java
##########
@@ -0,0 +1,129 @@
+package org.eclipse.aether.named.providers;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.named.NamedLock;
+import org.eclipse.aether.named.NamedLockFactory;
+
+import javax.inject.Named;
+import javax.inject.Provider;
+import javax.inject.Singleton;
+import java.util.ArrayDeque;
+import java.util.NoSuchElementException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+/**
+ * Provider of {@link GlobalNamedLockFactory}. This uses one "global" {@link ReentrantReadWriteLock}, is really not a
+ * "named" lock.
+ */
+@Singleton
+@Named( GlobalReadWriteLockProvider.NAME )
+public final class GlobalReadWriteLockProvider
+        implements Provider<NamedLockFactory>
+{
+    public static final String NAME = "global";
+
+    @Override
+    public NamedLockFactory get()
+    {
+        return new GlobalNamedLockFactory();
+    }
+
+    /**
+     * A global named lock factory that actually uses one singleton named lock instance for all names.
+     */
+    public static final class GlobalNamedLockFactory implements NamedLockFactory
+    {
+        private final GlobalNamedLock globalNamedLock = new GlobalNamedLock();
+
+        @Override
+        public NamedLock getLock( String name )
+        {
+            return globalNamedLock;
+        }
+
+        @Override
+        public void shutdown()
+        {
+            // nop
+        }
+    }
+
+    /**
+     * A global named lock that uses one single reentrant read-write lock.
+     */
+    public static final class GlobalNamedLock implements NamedLock
+    {
+        private final ReentrantReadWriteLock global = new ReentrantReadWriteLock();
+
+        private final ArrayDeque<Lock> steps = new ArrayDeque<>();

Review comment:
       Does the deque serve as hold count for reeentrant calls like in my Redisson?
   ```
                   while ( actualLock.getHoldCount() > 0 )
                   {
                       // Avoid #getHoldCount() roundtrips when we are not logging
                       if ( LOGGER.isTraceEnabled() )
                       {
                           LOGGER.trace( "Releasing {} lock for '{}' (currently held: {})",
                                         shared ? "read" : "write", key, actualLock.getHoldCount() );
                       }
                       actualLock.unlock();
                   }
   ```

##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/SyncContextFactoryAdapter.java
##########
@@ -0,0 +1,272 @@
+package org.eclipse.aether.internal.impl.synccontext;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+import org.eclipse.aether.named.NamedLock;
+import org.eclipse.aether.named.NamedLockFactory;
+import org.eclipse.aether.util.ChecksumUtils;
+import org.eclipse.aether.util.ConfigUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayDeque;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.TreeSet;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Adapter to adapt {@link NamedLockFactory} and {@link NamedLock} to {@link SyncContext}.
+ */
+public final class SyncContextFactoryAdapter
+{
+    private static final String DEFAULT_DISCRIMINATOR_DIGEST = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
+
+    private static final String DEFAULT_HOSTNAME = "localhost";
+
+    private static final Logger LOGGER = LoggerFactory.getLogger( SyncContextFactoryAdapter.class );
+
+    private final NamedLockFactory namedLockFactory;
+
+    private final long time;
+
+    private final TimeUnit timeUnit;
+
+    private final String hostname;
+
+    public SyncContextFactoryAdapter( final NamedLockFactory namedLockFactory,
+                                      final long time,
+                                      final TimeUnit timeUnit )
+    {
+        this.namedLockFactory = namedLockFactory;
+        this.time = time;
+        this.timeUnit = timeUnit;
+        this.hostname = getHostname();
+    }
+
+    private String getHostname()
+    {
+        try
+        {
+            return InetAddress.getLocalHost().getHostName();
+        }
+        catch ( UnknownHostException e )
+        {
+            LOGGER.warn( "Failed to get hostname, using '{}'", DEFAULT_HOSTNAME, e );
+            return DEFAULT_HOSTNAME;
+        }
+    }
+
+    public SyncContext newInstance( final RepositorySystemSession session, final boolean shared )
+    {
+        return new AdaptedLockSyncContext( session, hostname, namedLockFactory, time, timeUnit, shared );
+    }
+
+    public void shutdown()
+    {
+        namedLockFactory.shutdown();
+    }
+
+    private static class AdaptedLockSyncContext
+            implements SyncContext
+    {
+        private static final String CONFIG_PROP_DISCRIMINATOR = "aether.syncContext.named.discriminator";
+
+        private static final String KEY_PREFIX = "mvn:resolver:";
+
+        private static final Logger LOGGER = LoggerFactory.getLogger( AdaptedLockSyncContext.class );
+
+        private final RepositorySystemSession session;
+
+        private final String hostname;
+
+        private final NamedLockFactory namedLockFactory;
+
+        private final long time;
+
+        private final TimeUnit timeUnit;
+
+        private final boolean shared;
+
+        private final ArrayDeque<NamedLock> locks;
+
+        private AdaptedLockSyncContext( final RepositorySystemSession session,
+                                        final String hostname,
+                                        final NamedLockFactory namedLockFactory,
+                                        final long time,
+                                        final TimeUnit timeUnit,
+                                        final boolean shared )
+        {
+            this.session = session;
+            this.hostname = hostname;
+            this.namedLockFactory = namedLockFactory;
+            this.time = time;
+            this.timeUnit = timeUnit;
+            this.shared = shared;
+            this.locks = new ArrayDeque<>();
+        }
+
+        @Override
+        public void acquire( Collection<? extends Artifact> artifacts,
+                             Collection<? extends Metadata> metadatas )
+        {
+            // Deadlock prevention: https://stackoverflow.com/a/16780988/696632
+            // We must acquire multiple locks always in the same order!
+            Collection<String> keys = new TreeSet<>();
+            if ( artifacts != null )
+            {
+                for ( Artifact artifact : artifacts )
+                {
+                    // TODO Should we include extension and classifier too?
+                    String key = "artifact:" + artifact.getGroupId() + ":"
+                            + artifact.getArtifactId() + ":" + artifact.getBaseVersion();
+                    keys.add( key );
+                }
+            }
+
+            if ( metadatas != null )
+            {
+                for ( Metadata metadata : metadatas )
+                {
+                    StringBuilder key = new StringBuilder( "metadata:" );
+                    if ( !metadata.getGroupId().isEmpty() )
+                    {
+                        key.append( metadata.getGroupId() );
+                        if ( !metadata.getArtifactId().isEmpty() )
+                        {
+                            key.append( ':' ).append( metadata.getArtifactId() );
+                            if ( !metadata.getVersion().isEmpty() )
+                            {
+                                key.append( ':' ).append( metadata.getVersion() );
+                            }
+                        }
+                    }
+                    keys.add( key.toString() );
+                }
+            }
+
+            if ( keys.isEmpty() )
+            {
+                return;
+            }
+
+            String discriminator = createDiscriminator();

Review comment:
       I think having this here is wrong. This is an inplementation detail of a concrete named provider and not a general one. Mostly distirbuted locking systems need it. In-VM don't require it. I would prefer that this classes uses external lock names while a named provider can tranform this to a internal one.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r549461252



##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/SyncContextFactoryAdapter.java
##########
@@ -0,0 +1,272 @@
+package org.eclipse.aether.internal.impl.synccontext;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+import org.eclipse.aether.named.NamedLock;
+import org.eclipse.aether.named.NamedLockFactory;
+import org.eclipse.aether.util.ChecksumUtils;
+import org.eclipse.aether.util.ConfigUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayDeque;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.TreeSet;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Adapter to adapt {@link NamedLockFactory} and {@link NamedLock} to {@link SyncContext}.
+ */
+public final class SyncContextFactoryAdapter
+{
+    private static final String DEFAULT_DISCRIMINATOR_DIGEST = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
+
+    private static final String DEFAULT_HOSTNAME = "localhost";
+
+    private static final Logger LOGGER = LoggerFactory.getLogger( SyncContextFactoryAdapter.class );
+
+    private final NamedLockFactory namedLockFactory;
+
+    private final long time;
+
+    private final TimeUnit timeUnit;
+
+    private final String hostname;
+
+    public SyncContextFactoryAdapter( final NamedLockFactory namedLockFactory,
+                                      final long time,
+                                      final TimeUnit timeUnit )
+    {
+        this.namedLockFactory = namedLockFactory;
+        this.time = time;
+        this.timeUnit = timeUnit;
+        this.hostname = getHostname();
+    }
+
+    private String getHostname()
+    {
+        try
+        {
+            return InetAddress.getLocalHost().getHostName();
+        }
+        catch ( UnknownHostException e )
+        {
+            LOGGER.warn( "Failed to get hostname, using '{}'", DEFAULT_HOSTNAME, e );
+            return DEFAULT_HOSTNAME;
+        }
+    }
+
+    public SyncContext newInstance( final RepositorySystemSession session, final boolean shared )
+    {
+        return new AdaptedLockSyncContext( session, hostname, namedLockFactory, time, timeUnit, shared );
+    }
+
+    public void shutdown()
+    {
+        namedLockFactory.shutdown();
+    }
+
+    private static class AdaptedLockSyncContext
+            implements SyncContext
+    {
+        private static final String CONFIG_PROP_DISCRIMINATOR = "aether.syncContext.named.discriminator";
+
+        private static final String KEY_PREFIX = "mvn:resolver:";
+
+        private static final Logger LOGGER = LoggerFactory.getLogger( AdaptedLockSyncContext.class );
+
+        private final RepositorySystemSession session;
+
+        private final String hostname;
+
+        private final NamedLockFactory namedLockFactory;
+
+        private final long time;
+
+        private final TimeUnit timeUnit;
+
+        private final boolean shared;
+
+        private final ArrayDeque<NamedLock> locks;
+
+        private AdaptedLockSyncContext( final RepositorySystemSession session,
+                                        final String hostname,
+                                        final NamedLockFactory namedLockFactory,
+                                        final long time,
+                                        final TimeUnit timeUnit,
+                                        final boolean shared )
+        {
+            this.session = session;
+            this.hostname = hostname;
+            this.namedLockFactory = namedLockFactory;
+            this.time = time;
+            this.timeUnit = timeUnit;
+            this.shared = shared;
+            this.locks = new ArrayDeque<>();
+        }
+
+        @Override
+        public void acquire( Collection<? extends Artifact> artifacts,
+                             Collection<? extends Metadata> metadatas )
+        {
+            // Deadlock prevention: https://stackoverflow.com/a/16780988/696632
+            // We must acquire multiple locks always in the same order!
+            Collection<String> keys = new TreeSet<>();
+            if ( artifacts != null )
+            {
+                for ( Artifact artifact : artifacts )
+                {
+                    // TODO Should we include extension and classifier too?
+                    String key = "artifact:" + artifact.getGroupId() + ":"
+                            + artifact.getArtifactId() + ":" + artifact.getBaseVersion();
+                    keys.add( key );
+                }
+            }
+
+            if ( metadatas != null )
+            {
+                for ( Metadata metadata : metadatas )
+                {
+                    StringBuilder key = new StringBuilder( "metadata:" );
+                    if ( !metadata.getGroupId().isEmpty() )
+                    {
+                        key.append( metadata.getGroupId() );
+                        if ( !metadata.getArtifactId().isEmpty() )
+                        {
+                            key.append( ':' ).append( metadata.getArtifactId() );
+                            if ( !metadata.getVersion().isEmpty() )
+                            {
+                                key.append( ':' ).append( metadata.getVersion() );
+                            }
+                        }
+                    }
+                    keys.add( key.toString() );
+                }
+            }
+
+            if ( keys.isEmpty() )
+            {
+                return;
+            }
+
+            String discriminator = createDiscriminator();
+            LOGGER.trace( "Using key discriminator '{}' during this session", discriminator );
+
+            LOGGER.trace( "Need {} {} lock(s) for {}", keys.size(), shared ? "read" : "write", keys );
+            int acquiredLockCount = 0;
+            for ( String key : keys )
+            {
+                NamedLock namedLock = namedLockFactory.getLock( KEY_PREFIX + discriminator + ":" + key );
+                try
+                {
+                    boolean locked;
+                    if ( shared )
+                    {
+                        locked = namedLock.lockShared( time, timeUnit );
+                    }
+                    else
+                    {
+                        locked = namedLock.lockExclusively( time, timeUnit );
+                    }
+
+                    if ( !locked )
+                    {
+                        namedLock.close();
+                        throw new IllegalStateException( "Could not lock "
+                                + namedLock.name() + " (shared=" + shared + ")" );
+                    }
+
+                    locks.push( namedLock );
+                    acquiredLockCount++;
+                }
+                catch ( InterruptedException e )
+                {
+                    Thread.currentThread().interrupt();
+                    throw new RuntimeException( e );
+                }
+            }
+            LOGGER.trace( "Total new locks acquired: {}", acquiredLockCount );

Review comment:
       Removed "new" (the untrue part). 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r605525855



##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/NamedSyncContextFactory.java
##########
@@ -0,0 +1,128 @@
+package org.eclipse.aether.internal.impl.synccontext;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.internal.impl.synccontext.named.DiscriminatingNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.GAVNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.NameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.NamedLockFactoryAdapter;
+import org.eclipse.aether.internal.impl.synccontext.named.StaticNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.takari.TakariNamedLockFactory;
+import org.eclipse.aether.internal.impl.synccontext.named.takari.TakariNameMapper;
+import org.eclipse.aether.named.NamedLockFactory;
+import org.eclipse.aether.named.providers.LocalReadWriteLockNamedLockFactory;
+import org.eclipse.aether.named.providers.LocalSemaphoreNamedLockFactory;
+
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Named {@link SyncContextFactoryDelegate} implementation that selects underlying {@link NamedLockFactory}
+ * implementation at creation.
+ */
+@Singleton
+@Named( NamedSyncContextFactory.NAME )
+public final class NamedSyncContextFactory
+        implements SyncContextFactoryDelegate
+{
+    public static final String NAME = "named";
+
+    private static final String FACTORY_NAME = System.getProperty(
+            "aether.syncContext.named.factory", LocalReadWriteLockNamedLockFactory.NAME
+    );
+
+    private static final String NAME_MAPPING = System.getProperty(
+        "aether.syncContext.named.nameMapping", DiscriminatingNameMapper.NAME
+    );
+
+    private static final long TIME_OUT = Long.getLong(
+            "aether.syncContext.named.timeOut", 30L
+    );
+
+    private static final TimeUnit TIME_UNIT = TimeUnit.valueOf( System.getProperty(
+            "aether.syncContext.named.timeUnit", TimeUnit.SECONDS.name()

Review comment:
       fixed




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r611797238



##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/named/NameMapper.java
##########
@@ -0,0 +1,41 @@
+package org.eclipse.aether.internal.impl.synccontext.named;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Collection;
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+
+/**
+ * Component mapping lock names to passed in artifacts and metadata as required.
+ */
+public interface NameMapper
+{
+  /**
+   * Creates (opaque) names for passed in artifacts and metadata. Returned collection has max size of sum of the passed
+   * in artifacts and metadata collections, or less. If empty collection returned, there will be no locking happening.
+   * Never returns {@code null}.
+   */
+  Collection<String> nameLocks( RepositorySystemSession session,

Review comment:
       Right, ~and not only that: just figured that `TakariNameMapper` lacks sorting....~ scratch that, am wrong. But yes, all implementations return `TreeSet`, so yes, we could explicitly state that, maybe even change collection to tree set on iface?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r611771246



##########
File path: maven-resolver-named-locks-redisson/src/main/java/org/eclipse/aether/named/redisson/RedissonNamedLockFactorySupport.java
##########
@@ -0,0 +1,120 @@
+package org.eclipse.aether.named.redisson;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.named.support.NamedLockFactorySupport;
+import org.eclipse.aether.named.support.NamedLockSupport;
+import org.redisson.Redisson;
+import org.redisson.api.RedissonClient;
+import org.redisson.config.Config;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+/**
+ * Support class for factories using {@link RedissonClient}.
+ *
+ * @param <L> the actual implementation, subclass of {@link NamedLockSupport}.
+ */
+public abstract class RedissonNamedLockFactorySupport<L extends NamedLockSupport>
+    extends NamedLockFactorySupport<L>
+{
+  protected static final String NAME_PREFIX = "maven:resolver:";
+
+  private static final String DEFAULT_CONFIG_FILE_NAME = "maven-resolver-redisson.yaml";
+
+  private static final String DEFAULT_REDIS_ADDRESS = "redis://localhost:6379";
+
+  private static final String DEFAULT_CLIENT_NAME = "maven-resolver";
+
+  private static final String CONFIG_PROP_CONFIG_FILE = "aether.syncContext.redisson.configFile";

Review comment:
       fixed




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r605516892



##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/DefaultSyncContextFactory.java
##########
@@ -0,0 +1,86 @@
+package org.eclipse.aether.internal.impl.synccontext;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.spi.synccontext.SyncContextFactory;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * Default {@link SyncContextFactory} implementation that delegates to some {@link SyncContextFactoryDelegate}
+ * implementation.
+ */
+@Singleton
+@Named
+public final class DefaultSyncContextFactory
+        implements SyncContextFactory, org.eclipse.aether.impl.SyncContextFactory
+{
+    private static final String SYNC_CONTEXT_FACTORY_NAME = System.getProperty(
+            "aether.syncContext.impl", NamedSyncContextFactory.NAME
+    );
+
+    private final SyncContextFactoryDelegate delegate;
+
+    /**
+     * Constructor used with DI, where factories are injected and selected based on key.
+     */
+    @Inject
+    public DefaultSyncContextFactory( final Map<String, SyncContextFactoryDelegate> delegates )
+    {
+        Objects.requireNonNull( delegates );
+        this.delegate = selectDelegate( delegates );
+    }
+
+    /**
+     * Default constructor.
+     */
+    public DefaultSyncContextFactory()
+    {
+        HashMap<String, SyncContextFactoryDelegate> delegates = new HashMap<>( 3 );
+        delegates.put( NoLockSyncContextFactory.NAME, new NoLockSyncContextFactory() );
+        delegates.put( GlobalSyncContextFactory.NAME, new GlobalSyncContextFactory() );
+        delegates.put( NamedSyncContextFactory.NAME, new NamedSyncContextFactory() );
+        this.delegate = selectDelegate( delegates );
+    }

Review comment:
       Default ctor is used only w/ `ServiceLocator`, once it is gone, this ctor is gone as well. Has nothing to do with DI.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-813447624


   Question: Does it make sense to add an enum to `NameMappers` which denotes whether they are local (in-VM) or distributed (multi-VM) and appropriate impls you reject mappes with incorrect "scope"?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-731603812


   So no code changes are required to do a single node setup like with Redis?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r549467158



##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/SyncContextFactoryAdapter.java
##########
@@ -0,0 +1,272 @@
+package org.eclipse.aether.internal.impl.synccontext;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+import org.eclipse.aether.named.NamedLock;
+import org.eclipse.aether.named.NamedLockFactory;
+import org.eclipse.aether.util.ChecksumUtils;
+import org.eclipse.aether.util.ConfigUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayDeque;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.TreeSet;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Adapter to adapt {@link NamedLockFactory} and {@link NamedLock} to {@link SyncContext}.
+ */
+public final class SyncContextFactoryAdapter
+{
+    private static final String DEFAULT_DISCRIMINATOR_DIGEST = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
+
+    private static final String DEFAULT_HOSTNAME = "localhost";
+
+    private static final Logger LOGGER = LoggerFactory.getLogger( SyncContextFactoryAdapter.class );
+
+    private final NamedLockFactory namedLockFactory;
+
+    private final long time;
+
+    private final TimeUnit timeUnit;
+
+    private final String hostname;
+
+    public SyncContextFactoryAdapter( final NamedLockFactory namedLockFactory,
+                                      final long time,
+                                      final TimeUnit timeUnit )
+    {
+        this.namedLockFactory = namedLockFactory;
+        this.time = time;
+        this.timeUnit = timeUnit;
+        this.hostname = getHostname();
+    }
+
+    private String getHostname()
+    {
+        try
+        {
+            return InetAddress.getLocalHost().getHostName();
+        }
+        catch ( UnknownHostException e )
+        {
+            LOGGER.warn( "Failed to get hostname, using '{}'", DEFAULT_HOSTNAME, e );
+            return DEFAULT_HOSTNAME;
+        }
+    }
+
+    public SyncContext newInstance( final RepositorySystemSession session, final boolean shared )
+    {
+        return new AdaptedLockSyncContext( session, hostname, namedLockFactory, time, timeUnit, shared );
+    }
+
+    public void shutdown()
+    {
+        namedLockFactory.shutdown();
+    }
+
+    private static class AdaptedLockSyncContext
+            implements SyncContext
+    {
+        private static final String CONFIG_PROP_DISCRIMINATOR = "aether.syncContext.named.discriminator";
+
+        private static final String KEY_PREFIX = "mvn:resolver:";
+
+        private static final Logger LOGGER = LoggerFactory.getLogger( AdaptedLockSyncContext.class );
+
+        private final RepositorySystemSession session;
+
+        private final String hostname;
+
+        private final NamedLockFactory namedLockFactory;
+
+        private final long time;
+
+        private final TimeUnit timeUnit;
+
+        private final boolean shared;
+
+        private final ArrayDeque<NamedLock> locks;
+
+        private AdaptedLockSyncContext( final RepositorySystemSession session,
+                                        final String hostname,
+                                        final NamedLockFactory namedLockFactory,
+                                        final long time,
+                                        final TimeUnit timeUnit,
+                                        final boolean shared )
+        {
+            this.session = session;
+            this.hostname = hostname;
+            this.namedLockFactory = namedLockFactory;
+            this.time = time;
+            this.timeUnit = timeUnit;
+            this.shared = shared;
+            this.locks = new ArrayDeque<>();
+        }
+
+        @Override
+        public void acquire( Collection<? extends Artifact> artifacts,
+                             Collection<? extends Metadata> metadatas )
+        {
+            // Deadlock prevention: https://stackoverflow.com/a/16780988/696632
+            // We must acquire multiple locks always in the same order!
+            Collection<String> keys = new TreeSet<>();
+            if ( artifacts != null )
+            {
+                for ( Artifact artifact : artifacts )
+                {
+                    // TODO Should we include extension and classifier too?
+                    String key = "artifact:" + artifact.getGroupId() + ":"
+                            + artifact.getArtifactId() + ":" + artifact.getBaseVersion();
+                    keys.add( key );
+                }
+            }
+
+            if ( metadatas != null )
+            {
+                for ( Metadata metadata : metadatas )
+                {
+                    StringBuilder key = new StringBuilder( "metadata:" );
+                    if ( !metadata.getGroupId().isEmpty() )
+                    {
+                        key.append( metadata.getGroupId() );
+                        if ( !metadata.getArtifactId().isEmpty() )
+                        {
+                            key.append( ':' ).append( metadata.getArtifactId() );
+                            if ( !metadata.getVersion().isEmpty() )
+                            {
+                                key.append( ':' ).append( metadata.getVersion() );
+                            }
+                        }
+                    }
+                    keys.add( key.toString() );
+                }
+            }
+
+            if ( keys.isEmpty() )
+            {
+                return;
+            }
+
+            String discriminator = createDiscriminator();

Review comment:
       Unsure about this... while I tend to agree, what happens in cases. like mvnd, where muitiple executions (potentially having mutiple settings XML used) may be executing? (mvnd is new to me, unsure what and how it really solve this). In that case localRepo1:GAV and localRepo2:GAV are two separate things, no?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-764908120


   @michael-o @rmannibucau My proposal is to merge this PR, we already know current master is broken (see MRESOLVER-153), and while in this PR I did "return" (well, copied to new place) the `NoLockSyncContextFactory` (the `DefaultSyncContextFactory` that was noop, cause of MRESOLVER-153) I am now tempted to drop it, and merge.
   WDYT?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r550303703



##########
File path: maven-resolver-named/src/site/markdown/index.md.vm
##########
@@ -0,0 +1,69 @@
+${esc.hash} Named Sync Context for Maven Resolver
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+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
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+The Named Sync Context Factory is a distributed lock factory for Maven Resolver
+on top of JVM and Hazelcast to provide a fast, concurrent-safe access from one or multiple Maven instances to the
+same local Maven repository.
+
+For further details about the factory read the [Javadoc](./apidocs/org/eclipse/aether/synccontext/NamedSyncContextFactory.html).
+
+${esc.hash}${esc.hash} Open Issues/Notes
+
+- It only works when dependency injection is used and not the bundled `AetherModule` or
+  `ServiceLocator` (Maven uses dependency injection).
+- It includes a lot of trace logging which partially will go way as soon as it has been stabilized.
+- Usage from plugins has not been tested yet.
+- The `furnace-maven-plugin` does not work this implementation because it uses `ServiceLocator` instead
+  of dependency injection.
+
+${esc.hash}${esc.hash} Installation/Testing
+
+- Create the directory `${maven.home}/lib/ext/hazelcast/`.

Review comment:
       Fixed




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-751683148


   Howdy @rmannibucau 
   For now I consider both HZ and Redisson as "lab" implementation still, due these:
   * for HZ to work we either must use deprecated HZ 3.x call (HazelcastInstance#getSemaphore), or have a remote CP cluster set up (here, setup is somewhat similar to Redisson: you must have some remote "thing", server, cluster set up beforehand)
   * for Redisson, no clue how to test (any ideas?)
   
   So for start, I'd focus on local (JVM local) locks and the two "extra" (again, for testing purposes: global and nolock) implementations. As they are pretty much in place. Given this PR does not include any of HZ or Redisson code into resolver (they are separate modules, it leaves it to integrator), I think we still have time to solve both questions, that IMO are valid and actually sounds useful (generic props for configuration).


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r605541753



##########
File path: maven-resolver-named-locks/src/main/java/org/eclipse/aether/named/support/NamedLockFactorySupport.java
##########
@@ -0,0 +1,88 @@
+package org.eclipse.aether.named.support;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.eclipse.aether.named.NamedLockFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Support class for {@link NamedLockFactory} implementations providing reference counting.
+ *
+ * @param <L> the actual implementation, subclass of {@link NamedLockSupport}.
+ */
+public abstract class NamedLockFactorySupport<L extends NamedLockSupport>
+    implements NamedLockFactory
+{
+  protected final Logger log = LoggerFactory.getLogger( getClass() );
+
+  private final ConcurrentHashMap<String, L> locks;

Review comment:
       This map contains as much entries as much concurrently accessed files are in given moment (max: if all concurrently access files are different, or less if there is overlap among them), and as we use reference counting, is cleaned up afterwards last ref is removed. So, this map theoretically MAY contain as much entries as many threads are executing in parallel (so metadata threads + `-T` param?). 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r611797238



##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/named/NameMapper.java
##########
@@ -0,0 +1,41 @@
+package org.eclipse.aether.internal.impl.synccontext.named;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Collection;
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+
+/**
+ * Component mapping lock names to passed in artifacts and metadata as required.
+ */
+public interface NameMapper
+{
+  /**
+   * Creates (opaque) names for passed in artifacts and metadata. Returned collection has max size of sum of the passed
+   * in artifacts and metadata collections, or less. If empty collection returned, there will be no locking happening.
+   * Never returns {@code null}.
+   */
+  Collection<String> nameLocks( RepositorySystemSession session,

Review comment:
       Right, and not only that: just figured that TakariMapper lacks sorting....




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-817984588


   re formatting: the maven site exposed formatting rule for Idea IDE drives me nuts, it is not aligned with checkstyle, so several "reformat" attempts, sorry for that 😞 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-818693664


   > I understand this now, but am not happy with for the following reasons: We have a hard requirement on reentrancy, it is up to the lock to implement that properly. If some lock does not support it, you can employ your history for that (granted), but why impose it on locks which support it out of the box? Java's locks do perfectly fine, so does Redisson. I ran Redisson builds hundreds of times and the overhead was very little. I don't see a reason to impose another layer of emulation if the underlying lock just can be used passthrough. In fact, this can even cause bugs/weird behavior if we don't use the locks as intended.
   
   See https://github.com/cstamas/maven-resolver/pull/1 (locally passes test, let's see CI)
   
   But in general, I cannot emphasize enough: we use JVM iface ReadWriteLock (that is implemented by both ReentrantReadWriteLock and RedissonReadWriteLock) and that iface **state nothing** about required re-entrant capability of lock implementation. Anytway, the PR above removes questioned bits, pls review


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-818679028


   > 
   > 
   > > There is one more thing I do not understand and think that this undermines reentrancy: While I understand that you maintain a concurrent map in `NamedLockFactorySupport` to manage locks (counts) between threads in one JVM to properly obtain and release them, but I fail to understand why both `AdaptedReadWriteLockNamedLock` and `AdaptedSemaphoreNamedLock` use thread locals to manage these locks. Looking at how lock and unlock are done, I don't see how underlying locks are used when reentrancy happens. Thus, the internal lock count is not increased, but you turn reentrancy into a `NOOP` and the end. Each call to `lockShared()`/`lockExclusively()` should be delegated to the underlying lock , no matter what. Please explain!
   > 
   > So, while `NamedLock` is re-entrant, the underlying constructs are not always. For example, all the "semaphore-like" things are not re-entrant: each lock requires permissions to be taken from it (shared: ONE, exclusive: ALL). So, re-entrant capability with semaphores is implemented here by tracking "history" and avoiding doing steps not necessary (the condition is already met, then noop step is performed). On the other hand, with "lock-like" things same thing is done, as used `ReadWriteLock` does not state anything about re-entrant capability (is left to implementations), but here it could be considered as "optimization" as well, as none of these actually change anything on semantic. BUT, in both cases (semaphore and lock) when using some remote construct (like Hazelcast or Redisson constructs, or who knows what else may be used) all the lock/unlock calls performs remote calls, that require serialization, orchestration and all the things you really want to avoid, especially in c
 ase when the outcome would really not change anything (the condition you need, the lock level you want is already in your pocket).
   > 
   > PS: intentionally write "semaphore-like" and "lock-like" things, as underlying constructs usually do not share common interface or ancestor, so we "adapt" them, but the term is more to express their "nature", or simpler, what is they principle how they work.
   
   I understand this now, but am not happy with for the following reasons: We have a hard requirement on reentrancy, it is up to the lock to implement that properly. If some lock does not support it, you can employ your history for that (granted), but why impose it on locks which support it out of the box? Java's locks do perfectly fine, so does Redisson. I ran Redisson builds hundreds of times and the overhead was very little. I don't see a reason to impose another layer of emulation if the underlying lock just can be used passthrough. In fact, this can even cause bugs/weird behavior if we don't use the locks as intended.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-817388228


   > yes but the problem is that the lock is at the same level as the collection. It should be at the level of individual file and the JVM together with OS would lock it by itself within the process.
   
   I don't understand why you make this conclusion. The lock per artifact is JVM wide.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] Tibor17 commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
Tibor17 commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-723502847


   It looks like the `ForkJoinPool` may substitute [SyncContext](https://maven.apache.org/resolver/maven-resolver-api/apidocs/org/eclipse/aether/SyncContext.html). If the parent Artifact sees the children > 0 then the parent Thread would fork to children threads. That's the mechanism how the locks are shared in the thread pool but it is already implemented in Java.
   btw. the usecase in `NamedLockFactoryTestSupport.java` looks like the one which exists in Java, I mean `CyclicBarrier` or  `Phaser` .


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r611843665



##########
File path: maven-resolver-named-locks/src/main/java/org/eclipse/aether/named/NamedLock.java
##########
@@ -0,0 +1,71 @@
+package org.eclipse.aether.named;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * A named lock, functionally similar to existing JVM and other implementations. Must support boxing (reentrancy), but
+ * no lock upgrade is supported. Usual pattern to use this lock:
+ * <pre>
+ *   try (NamedLock lock = factory.getLock("resourceName")) {
+ *     if (lock.lockExclusively(10L, Timeunit.SECONDS)) {
+ *       try {
+ *         ... exclusive access to "resourceName" resource gained here
+ *       }
+ *       finally {
+ *         lock.unlock();
+ *       }
+ *     }
+ *     else {
+ *       ... failed to gain access within specified time, handle it
+ *     }
+ *   }
+ * </pre>
+ */
+public interface NamedLock
+    extends AutoCloseable
+{
+  /**
+   * Returns this instance name, never null.
+   */
+  String name();
+
+  /**
+   * Tries to lock shared, may block for given time. If successful, returns {@code true}.
+   */
+  boolean lockShared( long time, TimeUnit unit ) throws InterruptedException;
+
+  /**
+   * Tries to lock exclusively, may block for given time. If successful, returns {@code true}.
+   */
+  boolean lockExclusively( long time, TimeUnit unit ) throws InterruptedException;

Review comment:
       But isn't the same behavior expected as in Java's `Lock` since we are using it by default?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-731601588


   When I read your note about HZ, does it make sense at all when it requires at least three nodes to work? This seems like overkill. I was able to achieve very decent peformance with Redis on an old `CPU: Intel(R) Core(TM) i5-2400 CPU @ 3.10GHz`. On a new server even better.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-728320815


   @michael-o Once you resolve all remaining conversations and have no more remark/change req, I'll squash the commits into one, until then am leaving them to be able to ref them from comments.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on pull request #77: SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-722576829


   I will have a look this week.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r602790952



##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/impl/guice/AetherModule.java
##########
@@ -146,10 +161,77 @@ protected void configure()
         bind( LocalRepositoryManagerFactory.class ).annotatedWith( Names.named( "enhanced" ) ) //
         .to( EnhancedLocalRepositoryManagerFactory.class ).in( Singleton.class );
 
+        bind( SyncContextFactoryDelegate.class ).annotatedWith( Names.named( NoLockSyncContextFactory.NAME ) )
+                .to( NoLockSyncContextFactory.class ).in( Singleton.class );
+        bind( SyncContextFactoryDelegate.class ).annotatedWith( Names.named( GlobalSyncContextFactory.NAME ) )
+                .to( GlobalSyncContextFactory.class ).in( Singleton.class );
+        bind( SyncContextFactoryDelegate.class ).annotatedWith( Names.named( NamedSyncContextFactory.NAME ) )
+                .to( NamedSyncContextFactory.class ).in( Singleton.class );
+
+        bind( NameMapper.class ).annotatedWith( Names.named( StaticNameMapper.NAME ) )
+            .to( StaticNameMapper.class ).in( Singleton.class );
+        bind( NameMapper.class ).annotatedWith( Names.named( GAVNameMapper.NAME ) )
+            .to( GAVNameMapper.class ).in( Singleton.class );
+        bind( NameMapper.class ).annotatedWith( Names.named( DiscriminatingNameMapper.NAME ) )
+            .to( DiscriminatingNameMapper.class ).in( Singleton.class );
+        bind( NameMapper.class ).annotatedWith( Names.named( TakariNameMapper.NAME ) )
+            .to( TakariNameMapper.class ).in( Singleton.class );
+
+        bind( NamedLockFactory.class ).annotatedWith( Names.named( LocalReadWriteLockNamedLockFactory.NAME ) )
+                .to( LocalReadWriteLockNamedLockFactory.class ).in( Singleton.class );
+        bind( NamedLockFactory.class ).annotatedWith( Names.named( LocalSemaphoreNamedLockFactory.NAME ) )
+                .to( LocalSemaphoreNamedLockFactory.class ).in( Singleton.class );
+        bind( NamedLockFactory.class ).annotatedWith( Names.named( TakariNamedLockFactory.NAME ) )
+            .to( TakariNamedLockFactory.class ).in( Singleton.class );
+
         install( new Slf4jModule() );
 
     }
 
+    @Provides
+    @Singleton
+    Map<String, SyncContextFactoryDelegate> provideSyncContextFactoryDelegates(
+            @Named( NoLockSyncContextFactory.NAME ) SyncContextFactoryDelegate nolock,
+            @Named( GlobalSyncContextFactory.NAME ) SyncContextFactoryDelegate global,
+            @Named( NamedSyncContextFactory.NAME ) SyncContextFactoryDelegate named )
+    {
+        Map<String, SyncContextFactoryDelegate> factories = new HashMap<>();
+        factories.put( NoLockSyncContextFactory.NAME, nolock );
+        factories.put( GlobalSyncContextFactory.NAME, global );
+        factories.put( NamedSyncContextFactory.NAME, named );
+        return Collections.unmodifiableMap( factories );
+    }
+
+    @Provides
+    @Singleton
+    Map<String, NameMapper> provideNameMappers(
+        @Named( StaticNameMapper.NAME ) NameMapper staticNameMapper,
+        @Named( GAVNameMapper.NAME ) NameMapper gavNameMapper,
+        @Named( DiscriminatingNameMapper.NAME ) NameMapper lgavNameMapper,

Review comment:
       Why `lgavNameMapper`?

##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/DefaultSyncContextFactory.java
##########
@@ -0,0 +1,86 @@
+package org.eclipse.aether.internal.impl.synccontext;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.spi.synccontext.SyncContextFactory;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * Default {@link SyncContextFactory} implementation that delegates to some {@link SyncContextFactoryDelegate}
+ * implementation.
+ */
+@Singleton
+@Named
+public final class DefaultSyncContextFactory
+        implements SyncContextFactory, org.eclipse.aether.impl.SyncContextFactory
+{
+    private static final String SYNC_CONTEXT_FACTORY_NAME = System.getProperty(
+            "aether.syncContext.impl", NamedSyncContextFactory.NAME
+    );
+
+    private final SyncContextFactoryDelegate delegate;
+
+    /**
+     * Constructor used with DI, where factories are injected and selected based on key.
+     */
+    @Inject
+    public DefaultSyncContextFactory( final Map<String, SyncContextFactoryDelegate> delegates )
+    {
+        Objects.requireNonNull( delegates );
+        this.delegate = selectDelegate( delegates );
+    }
+
+    /**
+     * Default constructor.
+     */
+    public DefaultSyncContextFactory()
+    {
+        HashMap<String, SyncContextFactoryDelegate> delegates = new HashMap<>( 3 );
+        delegates.put( NoLockSyncContextFactory.NAME, new NoLockSyncContextFactory() );
+        delegates.put( GlobalSyncContextFactory.NAME, new GlobalSyncContextFactory() );
+        delegates.put( NamedSyncContextFactory.NAME, new NamedSyncContextFactory() );
+        this.delegate = selectDelegate( delegates );
+    }
+
+    private SyncContextFactoryDelegate selectDelegate( final Map<String, SyncContextFactoryDelegate> delegates )
+    {
+        SyncContextFactoryDelegate delegate = delegates.get( SYNC_CONTEXT_FACTORY_NAME );
+        if ( delegate == null )
+        {
+            throw new IllegalArgumentException( "Unknown SyncContextFactory impl: " + SYNC_CONTEXT_FACTORY_NAME

Review comment:
       Stupid question: Isn't this rather an `IllegalStateException`? The input might be legal, but the delegate isn't available for some reason. WDYT?

##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/DefaultSyncContextFactory.java
##########
@@ -0,0 +1,86 @@
+package org.eclipse.aether.internal.impl.synccontext;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.spi.synccontext.SyncContextFactory;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * Default {@link SyncContextFactory} implementation that delegates to some {@link SyncContextFactoryDelegate}
+ * implementation.
+ */
+@Singleton
+@Named
+public final class DefaultSyncContextFactory
+        implements SyncContextFactory, org.eclipse.aether.impl.SyncContextFactory
+{
+    private static final String SYNC_CONTEXT_FACTORY_NAME = System.getProperty(
+            "aether.syncContext.impl", NamedSyncContextFactory.NAME
+    );
+
+    private final SyncContextFactoryDelegate delegate;
+
+    /**
+     * Constructor used with DI, where factories are injected and selected based on key.
+     */
+    @Inject
+    public DefaultSyncContextFactory( final Map<String, SyncContextFactoryDelegate> delegates )
+    {
+        Objects.requireNonNull( delegates );
+        this.delegate = selectDelegate( delegates );
+    }
+
+    /**
+     * Default constructor.
+     */
+    public DefaultSyncContextFactory()
+    {
+        HashMap<String, SyncContextFactoryDelegate> delegates = new HashMap<>( 3 );
+        delegates.put( NoLockSyncContextFactory.NAME, new NoLockSyncContextFactory() );
+        delegates.put( GlobalSyncContextFactory.NAME, new GlobalSyncContextFactory() );
+        delegates.put( NamedSyncContextFactory.NAME, new NamedSyncContextFactory() );
+        this.delegate = selectDelegate( delegates );
+    }

Review comment:
       Doesn't this make DI superfluous?

##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/NamedSyncContextFactory.java
##########
@@ -0,0 +1,128 @@
+package org.eclipse.aether.internal.impl.synccontext;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.internal.impl.synccontext.named.DiscriminatingNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.GAVNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.NameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.NamedLockFactoryAdapter;
+import org.eclipse.aether.internal.impl.synccontext.named.StaticNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.takari.TakariNamedLockFactory;
+import org.eclipse.aether.internal.impl.synccontext.named.takari.TakariNameMapper;
+import org.eclipse.aether.named.NamedLockFactory;
+import org.eclipse.aether.named.providers.LocalReadWriteLockNamedLockFactory;
+import org.eclipse.aether.named.providers.LocalSemaphoreNamedLockFactory;
+
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Named {@link SyncContextFactoryDelegate} implementation that selects underlying {@link NamedLockFactory}
+ * implementation at creation.
+ */
+@Singleton
+@Named( NamedSyncContextFactory.NAME )
+public final class NamedSyncContextFactory
+        implements SyncContextFactoryDelegate
+{
+    public static final String NAME = "named";
+
+    private static final String FACTORY_NAME = System.getProperty(
+            "aether.syncContext.named.factory", LocalReadWriteLockNamedLockFactory.NAME
+    );
+
+    private static final String NAME_MAPPING = System.getProperty(
+        "aether.syncContext.named.nameMapping", DiscriminatingNameMapper.NAME
+    );
+
+    private static final long TIME_OUT = Long.getLong(
+            "aether.syncContext.named.timeOut", 30L
+    );
+
+    private static final TimeUnit TIME_UNIT = TimeUnit.valueOf( System.getProperty(
+            "aether.syncContext.named.timeUnit", TimeUnit.SECONDS.name()
+    ) );
+
+    private final NamedLockFactoryAdapter namedLockFactoryAdapter;
+
+    /**
+     * Constructor used with DI, where factories are injected and selected based on key.
+     */
+    @Inject
+    public NamedSyncContextFactory( final Map<String, NameMapper> nameMappers,
+                                    final Map<String, NamedLockFactory> factories )
+    {
+        this.namedLockFactoryAdapter = selectAndAdapt( nameMappers, factories );
+    }
+
+    /**
+     * Default constructor.
+     */
+    public NamedSyncContextFactory()
+    {
+        HashMap<String, NameMapper> nameMappers = new HashMap<>();
+        nameMappers.put( StaticNameMapper.NAME, new StaticNameMapper() );
+        nameMappers.put( GAVNameMapper.NAME, new GAVNameMapper() );
+        nameMappers.put( DiscriminatingNameMapper.NAME, new DiscriminatingNameMapper( new GAVNameMapper() ) );
+        nameMappers.put( TakariNameMapper.NAME, new TakariNameMapper() );
+        HashMap<String, NamedLockFactory> factories = new HashMap<>();
+        factories.put( LocalReadWriteLockNamedLockFactory.NAME, new LocalReadWriteLockNamedLockFactory() );
+        factories.put( LocalSemaphoreNamedLockFactory.NAME, new LocalSemaphoreNamedLockFactory() );
+        factories.put( TakariNamedLockFactory.NAME, new TakariNamedLockFactory() );
+        this.namedLockFactoryAdapter = selectAndAdapt( nameMappers, factories );
+    }
+
+    private static NamedLockFactoryAdapter selectAndAdapt( final Map<String, NameMapper> nameMappers,
+                                                           final Map<String, NamedLockFactory> factories )
+    {
+        NameMapper nameMapper = nameMappers.get( NAME_MAPPING );
+        if ( nameMapper == null )
+        {
+            throw new IllegalArgumentException( "Unknown NameMapper name: " + NAME_MAPPING
+                + ", known ones: " + nameMappers.keySet() );
+        }
+        NamedLockFactory factory = factories.get( FACTORY_NAME );
+        if ( factory == null )
+        {
+            throw new IllegalArgumentException( "Unknown NamedLockFactory name: " + FACTORY_NAME

Review comment:
       I guess both exceptions are subject to the previous comment.

##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/NamedSyncContextFactory.java
##########
@@ -0,0 +1,128 @@
+package org.eclipse.aether.internal.impl.synccontext;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.internal.impl.synccontext.named.DiscriminatingNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.GAVNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.NameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.NamedLockFactoryAdapter;
+import org.eclipse.aether.internal.impl.synccontext.named.StaticNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.takari.TakariNamedLockFactory;
+import org.eclipse.aether.internal.impl.synccontext.named.takari.TakariNameMapper;
+import org.eclipse.aether.named.NamedLockFactory;
+import org.eclipse.aether.named.providers.LocalReadWriteLockNamedLockFactory;
+import org.eclipse.aether.named.providers.LocalSemaphoreNamedLockFactory;
+
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Named {@link SyncContextFactoryDelegate} implementation that selects underlying {@link NamedLockFactory}
+ * implementation at creation.
+ */
+@Singleton
+@Named( NamedSyncContextFactory.NAME )
+public final class NamedSyncContextFactory
+        implements SyncContextFactoryDelegate
+{
+    public static final String NAME = "named";
+
+    private static final String FACTORY_NAME = System.getProperty(
+            "aether.syncContext.named.factory", LocalReadWriteLockNamedLockFactory.NAME
+    );
+
+    private static final String NAME_MAPPING = System.getProperty(
+        "aether.syncContext.named.nameMapping", DiscriminatingNameMapper.NAME
+    );
+
+    private static final long TIME_OUT = Long.getLong(
+            "aether.syncContext.named.timeOut", 30L
+    );
+
+    private static final TimeUnit TIME_UNIT = TimeUnit.valueOf( System.getProperty(
+            "aether.syncContext.named.timeUnit", TimeUnit.SECONDS.name()
+    ) );
+
+    private final NamedLockFactoryAdapter namedLockFactoryAdapter;
+
+    /**
+     * Constructor used with DI, where factories are injected and selected based on key.
+     */
+    @Inject
+    public NamedSyncContextFactory( final Map<String, NameMapper> nameMappers,
+                                    final Map<String, NamedLockFactory> factories )
+    {
+        this.namedLockFactoryAdapter = selectAndAdapt( nameMappers, factories );
+    }
+
+    /**
+     * Default constructor.
+     */
+    public NamedSyncContextFactory()
+    {
+        HashMap<String, NameMapper> nameMappers = new HashMap<>();

Review comment:
       `Map` on the left side.

##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/named/StaticNameMapper.java
##########
@@ -0,0 +1,78 @@
+package org.eclipse.aether.internal.impl.synccontext.named;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Objects;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+import org.eclipse.aether.util.ConfigUtils;
+
+/**
+ * Static {@link NameMapper}, always assigns one same name, effectively becoming equivalent to "global" sync context.
+ */
+@Singleton
+@Named( StaticNameMapper.NAME )
+public class StaticNameMapper
+    implements NameMapper
+{
+  public static final String NAME = "static";
+
+  /**
+   * Configuration property to pass in static name.
+   */
+  private static final String CONFIG_PROP_NAME = "aether.syncContext.named.static.name";
+
+  private final String globalName;

Review comment:
       Why do you call this global while the class name says static? (consistency)

##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/NamedSyncContextFactory.java
##########
@@ -0,0 +1,128 @@
+package org.eclipse.aether.internal.impl.synccontext;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.internal.impl.synccontext.named.DiscriminatingNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.GAVNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.NameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.NamedLockFactoryAdapter;
+import org.eclipse.aether.internal.impl.synccontext.named.StaticNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.takari.TakariNamedLockFactory;
+import org.eclipse.aether.internal.impl.synccontext.named.takari.TakariNameMapper;
+import org.eclipse.aether.named.NamedLockFactory;
+import org.eclipse.aether.named.providers.LocalReadWriteLockNamedLockFactory;
+import org.eclipse.aether.named.providers.LocalSemaphoreNamedLockFactory;
+
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Named {@link SyncContextFactoryDelegate} implementation that selects underlying {@link NamedLockFactory}
+ * implementation at creation.
+ */
+@Singleton
+@Named( NamedSyncContextFactory.NAME )
+public final class NamedSyncContextFactory
+        implements SyncContextFactoryDelegate
+{
+    public static final String NAME = "named";
+
+    private static final String FACTORY_NAME = System.getProperty(
+            "aether.syncContext.named.factory", LocalReadWriteLockNamedLockFactory.NAME
+    );
+
+    private static final String NAME_MAPPING = System.getProperty(
+        "aether.syncContext.named.nameMapping", DiscriminatingNameMapper.NAME
+    );
+
+    private static final long TIME_OUT = Long.getLong(
+            "aether.syncContext.named.timeOut", 30L
+    );
+
+    private static final TimeUnit TIME_UNIT = TimeUnit.valueOf( System.getProperty(
+            "aether.syncContext.named.timeUnit", TimeUnit.SECONDS.name()

Review comment:
       I wonder whether we could make them `.timeout` and `.timeout.unit`. I will explain why: The unit solely applies to the timeout and not the named sync context.

##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/NamedSyncContextFactory.java
##########
@@ -0,0 +1,128 @@
+package org.eclipse.aether.internal.impl.synccontext;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.internal.impl.synccontext.named.DiscriminatingNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.GAVNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.NameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.NamedLockFactoryAdapter;
+import org.eclipse.aether.internal.impl.synccontext.named.StaticNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.takari.TakariNamedLockFactory;
+import org.eclipse.aether.internal.impl.synccontext.named.takari.TakariNameMapper;
+import org.eclipse.aether.named.NamedLockFactory;
+import org.eclipse.aether.named.providers.LocalReadWriteLockNamedLockFactory;
+import org.eclipse.aether.named.providers.LocalSemaphoreNamedLockFactory;
+
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Named {@link SyncContextFactoryDelegate} implementation that selects underlying {@link NamedLockFactory}
+ * implementation at creation.
+ */
+@Singleton
+@Named( NamedSyncContextFactory.NAME )
+public final class NamedSyncContextFactory
+        implements SyncContextFactoryDelegate
+{
+    public static final String NAME = "named";
+
+    private static final String FACTORY_NAME = System.getProperty(
+            "aether.syncContext.named.factory", LocalReadWriteLockNamedLockFactory.NAME
+    );
+
+    private static final String NAME_MAPPING = System.getProperty(
+        "aether.syncContext.named.nameMapping", DiscriminatingNameMapper.NAME
+    );
+
+    private static final long TIME_OUT = Long.getLong(
+            "aether.syncContext.named.timeOut", 30L
+    );
+
+    private static final TimeUnit TIME_UNIT = TimeUnit.valueOf( System.getProperty(
+            "aether.syncContext.named.timeUnit", TimeUnit.SECONDS.name()
+    ) );
+
+    private final NamedLockFactoryAdapter namedLockFactoryAdapter;
+
+    /**
+     * Constructor used with DI, where factories are injected and selected based on key.
+     */
+    @Inject
+    public NamedSyncContextFactory( final Map<String, NameMapper> nameMappers,
+                                    final Map<String, NamedLockFactory> factories )
+    {
+        this.namedLockFactoryAdapter = selectAndAdapt( nameMappers, factories );
+    }
+
+    /**
+     * Default constructor.
+     */
+    public NamedSyncContextFactory()
+    {
+        HashMap<String, NameMapper> nameMappers = new HashMap<>();
+        nameMappers.put( StaticNameMapper.NAME, new StaticNameMapper() );
+        nameMappers.put( GAVNameMapper.NAME, new GAVNameMapper() );
+        nameMappers.put( DiscriminatingNameMapper.NAME, new DiscriminatingNameMapper( new GAVNameMapper() ) );
+        nameMappers.put( TakariNameMapper.NAME, new TakariNameMapper() );
+        HashMap<String, NamedLockFactory> factories = new HashMap<>();

Review comment:
       Here also.

##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/named/takari/TakariNameMapper.java
##########
@@ -0,0 +1,98 @@
+package org.eclipse.aether.internal.impl.synccontext.named.takari;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.internal.impl.synccontext.named.NameMapper;
+import org.eclipse.aether.metadata.Metadata;
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+import java.util.Collection;
+import java.util.TreeSet;
+
+/**
+ * A {@link NameMapper} that creates same name mapping as Takari Local Repository does, without baseDir (local repo).
+ * Part of code blatantly copies parts of the Takari {@code LockingSyncContext}.
+ *
+ * @see <a href="https://github.com/takari/takari-local-repository/blob/master/src/main/java/io/takari/aether/concurrency/LockingSyncContext.java">Takari LockingSyncContext.java</a>
+ */
+@Singleton
+@Named( TakariNameMapper.NAME )
+public class TakariNameMapper

Review comment:
       Is this one intended as a logical drop-in replacement for the takari impl?

##########
File path: maven-resolver-named-locks/src/main/java/org/eclipse/aether/named/providers/FileLockNamedLock.java
##########
@@ -0,0 +1,171 @@
+package org.eclipse.aether.named.providers;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.nio.channels.FileChannel;
+import java.nio.channels.FileLock;
+import java.util.ArrayDeque;
+import java.util.Collection;
+import java.util.Deque;
+import java.util.HashMap;
+import java.util.concurrent.TimeUnit;
+
+import org.eclipse.aether.named.support.NamedLockSupport;
+
+/**
+ * Named lock that uses {@link FileLock}.
+ */
+public final class FileLockNamedLock
+    extends NamedLockSupport
+{
+    private static final long LOCK_POSITION = 0L;
+
+    private static final long LOCK_SIZE = 1L;
+
+    private final HashMap<Thread, Deque<FileLock>> threadSteps;

Review comment:
       `Map`?

##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/named/GAVNameMapper.java
##########
@@ -0,0 +1,89 @@
+package org.eclipse.aether.internal.impl.synccontext.named;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Collection;
+import java.util.TreeSet;
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+
+/**
+ * Artifact GAV {@link NameMapper}, uses artifact and metadata coordinates to name their corresponding locks. Is not
+ * considering local repository, only the artifact coordinates.
+ */
+@Singleton
+@Named( GAVNameMapper.NAME )
+public class GAVNameMapper
+    implements NameMapper
+{
+  public static final String NAME = "gav";
+
+  @Override
+  public TreeSet<String> nameLocks( final RepositorySystemSession session,

Review comment:
       Why not just `Collection`, does the actuall implementation matter?

##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/named/StaticNameMapper.java
##########
@@ -0,0 +1,78 @@
+package org.eclipse.aether.internal.impl.synccontext.named;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Objects;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+import org.eclipse.aether.util.ConfigUtils;
+
+/**
+ * Static {@link NameMapper}, always assigns one same name, effectively becoming equivalent to "global" sync context.
+ */
+@Singleton
+@Named( StaticNameMapper.NAME )
+public class StaticNameMapper
+    implements NameMapper
+{
+  public static final String NAME = "static";
+
+  /**
+   * Configuration property to pass in static name.
+   */
+  private static final String CONFIG_PROP_NAME = "aether.syncContext.named.static.name";
+
+  private final String globalName;
+
+  /**
+   * Uses string {@code "global"} for the static name.

Review comment:
       `NAME` says `static`

##########
File path: maven-resolver-named-locks/src/main/java/org/eclipse/aether/named/support/NamedLockFactorySupport.java
##########
@@ -0,0 +1,88 @@
+package org.eclipse.aether.named.support;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.eclipse.aether.named.NamedLockFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Support class for {@link NamedLockFactory} implementations providing reference counting.
+ *
+ * @param <L> the actual implementation, subclass of {@link NamedLockSupport}.
+ */
+public abstract class NamedLockFactorySupport<L extends NamedLockSupport>
+    implements NamedLockFactory
+{
+  protected final Logger log = LoggerFactory.getLogger( getClass() );
+
+  private final ConcurrentHashMap<String, L> locks;

Review comment:
       `ConcurrentMap`?

##########
File path: maven-resolver-named-locks/src/main/java/org/eclipse/aether/named/support/NamedLockFactorySupport.java
##########
@@ -0,0 +1,88 @@
+package org.eclipse.aether.named.support;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.eclipse.aether.named.NamedLockFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Support class for {@link NamedLockFactory} implementations providing reference counting.
+ *
+ * @param <L> the actual implementation, subclass of {@link NamedLockSupport}.
+ */
+public abstract class NamedLockFactorySupport<L extends NamedLockSupport>
+    implements NamedLockFactory
+{
+  protected final Logger log = LoggerFactory.getLogger( getClass() );
+
+  private final ConcurrentHashMap<String, L> locks;

Review comment:
       WDYT how overall runtme behavior will be we need cache thousands of locks here in a large build?

##########
File path: maven-resolver-named-locks-redisson/src/main/java/org/eclipse/aether/named/redisson/RedissonSemaphoreNamedLockFactory.java
##########
@@ -0,0 +1,69 @@
+package org.eclipse.aether.named.redisson;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.named.support.AdaptedSemaphoreNamedLock;
+import org.redisson.api.RSemaphore;
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Provider of {@link RedissonSemaphoreNamedLockFactory} using Redisson and {@link org.redisson.api.RSemaphore}.
+ */
+@Singleton
+@Named( RedissonSemaphoreNamedLockFactory.NAME )
+public class RedissonSemaphoreNamedLockFactory
+    extends RedissonNamedLockFactorySupport<AdaptedSemaphoreNamedLock>
+{
+  public static final String NAME = "semaphore-redisson";
+
+  @Override
+  protected AdaptedSemaphoreNamedLock createLock( final String name )
+  {
+    return new AdaptedSemaphoreNamedLock(
+            name, this, new RedissonSemaphore( redissonClient.getSemaphore( NAME_PREFIX + name ) )
+    );
+  }
+
+  private static final class RedissonSemaphore implements AdaptedSemaphoreNamedLock.AdaptedSemaphore
+  {
+    private final RSemaphore semaphore;
+
+    private RedissonSemaphore( final RSemaphore semaphore )
+    {
+      semaphore.addPermits( Integer.MAX_VALUE );
+      this.semaphore = semaphore;
+    }
+
+    @Override
+    public boolean tryAcquire( final int perms, final long time, final TimeUnit unit ) throws InterruptedException

Review comment:
       `timeout`?

##########
File path: maven-resolver-named-locks-redisson/src/main/java/org/eclipse/aether/named/redisson/RedissonReadWriteLockNamedLockFactory.java
##########
@@ -0,0 +1,50 @@
+package org.eclipse.aether.named.redisson;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.named.support.AdaptedReadWriteLockNamedLock;
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+/**
+ * Provider of {@link RedissonReadWriteLockNamedLockFactory} using Redisson and {@link org.redisson.api.RReadWriteLock}.
+ */
+@Singleton
+@Named( RedissonReadWriteLockNamedLockFactory.NAME )
+public class RedissonReadWriteLockNamedLockFactory
+    extends RedissonNamedLockFactorySupport<AdaptedReadWriteLockNamedLock>
+{
+  public static final String NAME = "rwlock-redisson";
+
+  private static final String NAME_PREFIX = "maven:resolver:";

Review comment:
       Why not use the proctected one from `super`?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r605539574



##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/named/GAVNameMapper.java
##########
@@ -0,0 +1,89 @@
+package org.eclipse.aether.internal.impl.synccontext.named;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Collection;
+import java.util.TreeSet;
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+
+/**
+ * Artifact GAV {@link NameMapper}, uses artifact and metadata coordinates to name their corresponding locks. Is not
+ * considering local repository, only the artifact coordinates.
+ */
+@Singleton
+@Named( GAVNameMapper.NAME )
+public class GAVNameMapper
+    implements NameMapper
+{
+  public static final String NAME = "gav";
+
+  @Override
+  public TreeSet<String> nameLocks( final RepositorySystemSession session,

Review comment:
       It matter as much as interface implementation matter :smile: So, iface defines `Collection` but implementation clearly says "am giving out sorted names". This is really an implementation detail here, no need to "mask" return type to `Collection`, as iface (and anyone coding against iface) use it "masked" already.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas edited a comment on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas edited a comment on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-811791981


   General remark: my personal preference for local variables is to declare them as they are, so `T variable = new T()`, in cases when the variable is strictly local scoped. I really see no value in doing `Map aMap = new HashMap()` when the `aMap` is used in local scope only. Is not only more logical to me, but lessens import count as well (Map vs HashMap in example above).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r549460660



##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/NamedSyncContextFactory.java
##########
@@ -0,0 +1,91 @@
+package org.eclipse.aether.internal.impl.synccontext;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.named.NamedLockFactory;
+import org.eclipse.aether.named.providers.LocalReadWriteLockProvider;
+import org.eclipse.aether.spi.synccontext.SyncContextFactory;
+
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Provider;
+import javax.inject.Singleton;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Named {@link SyncContextFactory} implementation that selects underlying {@link NamedLockFactory} implementation
+ * at creation.
+ */
+@Named
+@Singleton
+public final class NamedSyncContextFactory

Review comment:
       Fixed




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r611219268



##########
File path: maven-resolver-named-locks/src/main/java/org/eclipse/aether/named/NamedLock.java
##########
@@ -0,0 +1,71 @@
+package org.eclipse.aether.named;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * A named lock, functionally similar to existing JVM and other implementations. Must support boxing (reentrancy), but
+ * no lock upgrade is supported. Usual pattern to use this lock:
+ * <pre>
+ *   try (NamedLock lock = factory.getLock("resourceName")) {
+ *     if (lock.lockExclusively(10L, Timeunit.SECONDS)) {
+ *       try {
+ *         ... exclusive access to "resourceName" resource gained here
+ *       }
+ *       finally {
+ *         lock.unlock();
+ *       }
+ *     }
+ *     else {
+ *       ... failed to gain access within specified time, handle it
+ *     }
+ *   }
+ * </pre>
+ */
+public interface NamedLock
+    extends AutoCloseable
+{
+  /**
+   * Returns this instance name, never null.
+   */
+  String name();
+
+  /**
+   * Tries to lock shared, may block for given time. If successful, returns {@code true}.
+   */
+  boolean lockShared( long time, TimeUnit unit ) throws InterruptedException;
+
+  /**
+   * Tries to lock exclusively, may block for given time. If successful, returns {@code true}.
+   */
+  boolean lockExclusively( long time, TimeUnit unit ) throws InterruptedException;
+
+  /**
+   * Unlocks the lock.
+   */
+  void unlock();
+
+  /**
+   * Closes the lock.
+   */
+  @Override
+  void close();

Review comment:
       One should describe whether there is a difference between `close()` and `unlock()`.

##########
File path: maven-resolver-named-locks/src/main/java/org/eclipse/aether/named/NamedLock.java
##########
@@ -0,0 +1,71 @@
+package org.eclipse.aether.named;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * A named lock, functionally similar to existing JVM and other implementations. Must support boxing (reentrancy), but
+ * no lock upgrade is supported. Usual pattern to use this lock:
+ * <pre>
+ *   try (NamedLock lock = factory.getLock("resourceName")) {
+ *     if (lock.lockExclusively(10L, Timeunit.SECONDS)) {
+ *       try {
+ *         ... exclusive access to "resourceName" resource gained here
+ *       }
+ *       finally {
+ *         lock.unlock();
+ *       }
+ *     }
+ *     else {
+ *       ... failed to gain access within specified time, handle it
+ *     }
+ *   }
+ * </pre>
+ */
+public interface NamedLock
+    extends AutoCloseable
+{
+  /**
+   * Returns this instance name, never null.
+   */
+  String name();
+
+  /**
+   * Tries to lock shared, may block for given time. If successful, returns {@code true}.
+   */
+  boolean lockShared( long time, TimeUnit unit ) throws InterruptedException;
+
+  /**
+   * Tries to lock exclusively, may block for given time. If successful, returns {@code true}.
+   */
+  boolean lockExclusively( long time, TimeUnit unit ) throws InterruptedException;

Review comment:
       I think that those two method should resemble Java's `Lock`: `tryLock...(long, TimeUnit)`.

##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/named/NameMapper.java
##########
@@ -0,0 +1,41 @@
+package org.eclipse.aether.internal.impl.synccontext.named;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Collection;
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+
+/**
+ * Component mapping lock names to passed in artifacts and metadata as required.
+ */
+public interface NameMapper
+{
+  /**
+   * Creates (opaque) names for passed in artifacts and metadata. Returned collection has max size of sum of the passed
+   * in artifacts and metadata collections, or less. If empty collection returned, there will be no locking happening.
+   * Never returns {@code null}.
+   */
+  Collection<String> nameLocks( RepositorySystemSession session,

Review comment:
       I wonder whether we should require the collection to be stable regardless of the input order to comply with this comment:
   https://github.com/apache/maven-resolver/blob/f27b51de959f316e37d081fd4d2e572e778d6813/maven-resolver-synccontext-redisson/src/main/java/org/eclipse/aether/synccontext/RedissonSyncContextFactory.java#L246-L247
   
   WDYT?

##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/named/NamedLockFactoryAdapter.java
##########
@@ -0,0 +1,189 @@
+package org.eclipse.aether.internal.impl.synccontext.named;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+import org.eclipse.aether.named.NamedLock;
+import org.eclipse.aether.named.NamedLockFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayDeque;
+import java.util.Collection;
+import java.util.Objects;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Adapter to adapt {@link NamedLockFactory} and {@link NamedLock} to {@link SyncContext}.
+ */
+public final class NamedLockFactoryAdapter
+{
+    private final NameMapper nameMapper;
+
+    private final NamedLockFactory namedLockFactory;
+
+    private final long time;
+
+    private final TimeUnit timeUnit;
+
+    public NamedLockFactoryAdapter( final NameMapper nameMapper,
+                                    final NamedLockFactory namedLockFactory,
+                                    final long time,
+                                    final TimeUnit timeUnit )
+    {
+        this.nameMapper = Objects.requireNonNull( nameMapper );
+        this.namedLockFactory = Objects.requireNonNull( namedLockFactory );
+        if ( time < 0L )
+        {
+            throw new IllegalArgumentException( "time cannot be negative" );
+        }
+        this.time = time;
+        this.timeUnit = Objects.requireNonNull( timeUnit );
+    }
+
+    public SyncContext newInstance( final RepositorySystemSession session, final boolean shared )
+    {
+        return new AdaptedLockSyncContext(
+                session,
+                shared,
+                nameMapper,
+                namedLockFactory,
+                time,
+                timeUnit );
+    }
+
+    public void shutdown()
+    {
+        namedLockFactory.shutdown();
+    }
+
+    private static class AdaptedLockSyncContext
+            implements SyncContext
+    {
+        private static final Logger LOGGER = LoggerFactory.getLogger( AdaptedLockSyncContext.class );
+
+        private final RepositorySystemSession session;
+
+        private final boolean shared;
+
+        private final NameMapper lockNaming;
+
+        private final SessionAwareNamedLockFactory sessionAwareNamedLockFactory;
+
+        private final NamedLockFactory namedLockFactory;
+
+        private final long timeOut;
+
+        private final TimeUnit timeUnit;
+
+        private final ArrayDeque<NamedLock> locks;
+
+        private AdaptedLockSyncContext( final RepositorySystemSession session,
+                                        final boolean shared,
+                                        final NameMapper lockNaming,
+                                        final NamedLockFactory namedLockFactory,
+                                        final long timeOut,
+                                        final TimeUnit timeUnit )
+        {
+            this.session = session;
+            this.shared = shared;
+            this.lockNaming = lockNaming;
+            this.sessionAwareNamedLockFactory = namedLockFactory instanceof SessionAwareNamedLockFactory
+                    ? (SessionAwareNamedLockFactory) namedLockFactory
+                    : null;
+            this.namedLockFactory = namedLockFactory;
+            this.timeOut = timeOut;
+            this.timeUnit = timeUnit;
+            this.locks = new ArrayDeque<>();
+        }
+
+        @Override
+        public void acquire( Collection<? extends Artifact> artifacts,
+                             Collection<? extends Metadata> metadatas )
+        {
+            Collection<String> keys = lockNaming.nameLocks( session, artifacts, metadatas );
+            if ( keys.isEmpty() )
+            {
+                return;
+            }
+
+            LOGGER.trace( "Need {} {} lock(s) for {}", keys.size(), shared ? "read" : "write", keys );
+            int acquiredLockCount = 0;
+            for ( String key : keys )
+            {
+                NamedLock namedLock = sessionAwareNamedLockFactory != null
+                        ? sessionAwareNamedLockFactory.getLock( session, key )
+                        : namedLockFactory.getLock( key );
+                try
+                {
+                    boolean locked;
+                    if ( shared )
+                    {
+                        locked = namedLock.lockShared( timeOut, timeUnit );
+                    }
+                    else
+                    {
+                        locked = namedLock.lockExclusively( timeOut, timeUnit );
+                    }
+
+                    if ( !locked )
+                    {
+                        namedLock.close();
+                        throw new IllegalStateException( "Could not lock "
+                                + namedLock.name() + " (shared=" + shared + ")" );
+                    }

Review comment:
       I wonder whether this behavior should be configurable? WDYT?

##########
File path: maven-resolver-named-locks/src/main/java/org/eclipse/aether/named/support/AdaptedSemaphoreNamedLock.java
##########
@@ -0,0 +1,112 @@
+package org.eclipse.aether.named.support;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayDeque;
+import java.util.Deque;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Named lock support implementation that is using "adapted" semaphore (to be able to use semaphores not sharing common
+ * API).
+ */
+public class AdaptedSemaphoreNamedLock
+    extends NamedLockSupport
+{
+    /**
+     * Wrapper for semaphore-like stuff, that do not share common ancestor. Semaphore must be created to support
+     * {@link Integer#MAX_VALUE} permissions.
+     */
+    public interface AdaptedSemaphore
+    {
+        boolean tryAcquire( int perms, long timeout, TimeUnit unit ) throws InterruptedException;
+
+        void release( int perms );
+    }
+
+    private final ThreadLocal<Deque<Integer>> threadPerms;
+
+    private final AdaptedSemaphore semaphore;
+
+    public AdaptedSemaphoreNamedLock( final String name,
+                                      final NamedLockFactorySupport factory,

Review comment:
       Here too, generic type.

##########
File path: maven-resolver-named-locks/src/main/java/org/eclipse/aether/named/support/AdaptedSemaphoreNamedLock.java
##########
@@ -0,0 +1,112 @@
+package org.eclipse.aether.named.support;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayDeque;
+import java.util.Deque;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Named lock support implementation that is using "adapted" semaphore (to be able to use semaphores not sharing common
+ * API).
+ */
+public class AdaptedSemaphoreNamedLock

Review comment:
       I think for the ease of readability you should assign static finals to 0, 1, and `Integer.MAX_VALUE` just like `org.eclipse.aether.named.support.AdaptedReadWriteLockNamedLock.Step` or have them int values and reuse them.

##########
File path: maven-resolver-named-locks/src/main/java/org/eclipse/aether/named/support/NamedLockSupport.java
##########
@@ -0,0 +1,87 @@
+package org.eclipse.aether.named.support;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.eclipse.aether.named.NamedLock;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Support class for {@link NamedLock} implementations providing reference counting.
+ */
+public abstract class NamedLockSupport
+    implements NamedLock
+{
+  protected final Logger log = LoggerFactory.getLogger( getClass() );
+
+  private final String name;
+
+  private final NamedLockFactorySupport factory;
+
+  private final AtomicInteger refCount;
+
+  public NamedLockSupport( final String name, final NamedLockFactorySupport factory )

Review comment:
       Same here.

##########
File path: maven-resolver-named-locks/src/main/java/org/eclipse/aether/named/support/NamedLockSupport.java
##########
@@ -0,0 +1,87 @@
+package org.eclipse.aether.named.support;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.eclipse.aether.named.NamedLock;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Support class for {@link NamedLock} implementations providing reference counting.
+ */
+public abstract class NamedLockSupport
+    implements NamedLock
+{
+  protected final Logger log = LoggerFactory.getLogger( getClass() );
+
+  private final String name;
+
+  private final NamedLockFactorySupport factory;

Review comment:
       Eclipse complains about raw type. `private final NamedLockFactorySupport<NamedLockSupport> factory;` fixes this for me.

##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/NamedSyncContextFactory.java
##########
@@ -0,0 +1,128 @@
+package org.eclipse.aether.internal.impl.synccontext;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.internal.impl.synccontext.named.DiscriminatingNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.GAVNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.NameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.NamedLockFactoryAdapter;
+import org.eclipse.aether.internal.impl.synccontext.named.StaticNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.takari.TakariNamedLockFactory;
+import org.eclipse.aether.internal.impl.synccontext.named.takari.TakariNameMapper;
+import org.eclipse.aether.named.NamedLockFactory;
+import org.eclipse.aether.named.providers.LocalReadWriteLockNamedLockFactory;
+import org.eclipse.aether.named.providers.LocalSemaphoreNamedLockFactory;
+
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Named {@link SyncContextFactoryDelegate} implementation that selects underlying {@link NamedLockFactory}
+ * implementation at creation.
+ */
+@Singleton
+@Named( NamedSyncContextFactory.NAME )
+public final class NamedSyncContextFactory
+        implements SyncContextFactoryDelegate
+{
+    public static final String NAME = "named";
+
+    private static final String FACTORY_NAME = System.getProperty(
+            "aether.syncContext.named.factory", LocalReadWriteLockNamedLockFactory.NAME
+    );
+
+    private static final String NAME_MAPPING = System.getProperty(
+        "aether.syncContext.named.nameMapping", DiscriminatingNameMapper.NAME

Review comment:
       I think this shoud be `mameMapper` since the interface is called that way.

##########
File path: maven-resolver-named-locks-redisson/src/main/java/org/eclipse/aether/named/redisson/RedissonNamedLockFactorySupport.java
##########
@@ -0,0 +1,120 @@
+package org.eclipse.aether.named.redisson;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.named.support.NamedLockFactorySupport;
+import org.eclipse.aether.named.support.NamedLockSupport;
+import org.redisson.Redisson;
+import org.redisson.api.RedissonClient;
+import org.redisson.config.Config;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+/**
+ * Support class for factories using {@link RedissonClient}.
+ *
+ * @param <L> the actual implementation, subclass of {@link NamedLockSupport}.
+ */
+public abstract class RedissonNamedLockFactorySupport<L extends NamedLockSupport>
+    extends NamedLockFactorySupport<L>
+{
+  protected static final String NAME_PREFIX = "maven:resolver:";
+
+  private static final String DEFAULT_CONFIG_FILE_NAME = "maven-resolver-redisson.yaml";
+
+  private static final String DEFAULT_REDIS_ADDRESS = "redis://localhost:6379";
+
+  private static final String DEFAULT_CLIENT_NAME = "maven-resolver";
+
+  private static final String CONFIG_PROP_CONFIG_FILE = "aether.syncContext.redisson.configFile";

Review comment:
       Since this is now part of the named lock, the propfile should be `aether.syncContext.named.redisson.configFile`. Makes sense?

##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/NamedSyncContextFactory.java
##########
@@ -0,0 +1,128 @@
+package org.eclipse.aether.internal.impl.synccontext;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.internal.impl.synccontext.named.DiscriminatingNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.GAVNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.NameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.NamedLockFactoryAdapter;
+import org.eclipse.aether.internal.impl.synccontext.named.StaticNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.takari.TakariNamedLockFactory;
+import org.eclipse.aether.internal.impl.synccontext.named.takari.TakariNameMapper;
+import org.eclipse.aether.named.NamedLockFactory;
+import org.eclipse.aether.named.providers.LocalReadWriteLockNamedLockFactory;
+import org.eclipse.aether.named.providers.LocalSemaphoreNamedLockFactory;
+
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Named {@link SyncContextFactoryDelegate} implementation that selects underlying {@link NamedLockFactory}
+ * implementation at creation.
+ */
+@Singleton
+@Named( NamedSyncContextFactory.NAME )
+public final class NamedSyncContextFactory
+        implements SyncContextFactoryDelegate
+{
+    public static final String NAME = "named";
+
+    private static final String FACTORY_NAME = System.getProperty(
+            "aether.syncContext.named.factory", LocalReadWriteLockNamedLockFactory.NAME
+    );
+
+    private static final String NAME_MAPPING = System.getProperty(
+        "aether.syncContext.named.nameMapping", DiscriminatingNameMapper.NAME

Review comment:
       I think since `LocalReadWriteLockNamedLockFactory` is the default, then the default mapper should be `GAVNameMapper` because it is local and not distributed (discriminating). It provides no overhead to name calculation while the distributed ones does. One can also use GAV with Redisson/HC if only one process accesses the local repo.

##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/NamedSyncContextFactory.java
##########
@@ -0,0 +1,128 @@
+package org.eclipse.aether.internal.impl.synccontext;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.internal.impl.synccontext.named.DiscriminatingNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.GAVNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.NameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.NamedLockFactoryAdapter;
+import org.eclipse.aether.internal.impl.synccontext.named.StaticNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.takari.TakariNamedLockFactory;
+import org.eclipse.aether.internal.impl.synccontext.named.takari.TakariNameMapper;
+import org.eclipse.aether.named.NamedLockFactory;
+import org.eclipse.aether.named.providers.LocalReadWriteLockNamedLockFactory;
+import org.eclipse.aether.named.providers.LocalSemaphoreNamedLockFactory;
+
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Named {@link SyncContextFactoryDelegate} implementation that selects underlying {@link NamedLockFactory}
+ * implementation at creation.
+ */
+@Singleton
+@Named( NamedSyncContextFactory.NAME )
+public final class NamedSyncContextFactory
+        implements SyncContextFactoryDelegate
+{
+    public static final String NAME = "named";
+
+    private static final String FACTORY_NAME = System.getProperty(
+            "aether.syncContext.named.factory", LocalReadWriteLockNamedLockFactory.NAME
+    );
+
+    private static final String NAME_MAPPING = System.getProperty(
+        "aether.syncContext.named.nameMapping", DiscriminatingNameMapper.NAME
+    );
+
+    private static final long TIME_OUT = Long.getLong(

Review comment:
       Should be `TIMEOUT`

##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/named/DiscriminatingNameMapper.java
##########
@@ -0,0 +1,141 @@
+package org.eclipse.aether.internal.impl.synccontext.named;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.File;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.nio.charset.StandardCharsets;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Objects;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+import org.eclipse.aether.util.ChecksumUtils;
+import org.eclipse.aether.util.ConfigUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static java.util.stream.Collectors.toList;
+
+/**
+ * Discriminating {@link NameMapper}, that wraps another {@link NameMapper} and adds "discriminator" as prefix,
+ * that makes lock names unique including local repository (by default). The discriminator may be passed in via
+ * {@link RepositorySystemSession} or is automatically calculated based on local repository path.
+ *
+ * The default setup wraps {@link GAVNameMapper}, but manually may be created any instance needed.
+ */
+@Singleton
+@Named( DiscriminatingNameMapper.NAME )
+public class DiscriminatingNameMapper

Review comment:
       This is damn good refactoring!

##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/NamedSyncContextFactory.java
##########
@@ -0,0 +1,128 @@
+package org.eclipse.aether.internal.impl.synccontext;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.internal.impl.synccontext.named.DiscriminatingNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.GAVNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.NameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.NamedLockFactoryAdapter;
+import org.eclipse.aether.internal.impl.synccontext.named.StaticNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.takari.TakariNamedLockFactory;
+import org.eclipse.aether.internal.impl.synccontext.named.takari.TakariNameMapper;
+import org.eclipse.aether.named.NamedLockFactory;
+import org.eclipse.aether.named.providers.LocalReadWriteLockNamedLockFactory;
+import org.eclipse.aether.named.providers.LocalSemaphoreNamedLockFactory;
+
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Named {@link SyncContextFactoryDelegate} implementation that selects underlying {@link NamedLockFactory}
+ * implementation at creation.
+ */
+@Singleton
+@Named( NamedSyncContextFactory.NAME )
+public final class NamedSyncContextFactory
+        implements SyncContextFactoryDelegate
+{
+    public static final String NAME = "named";
+
+    private static final String FACTORY_NAME = System.getProperty(
+            "aether.syncContext.named.factory", LocalReadWriteLockNamedLockFactory.NAME
+    );
+
+    private static final String NAME_MAPPING = System.getProperty(
+        "aether.syncContext.named.nameMapping", DiscriminatingNameMapper.NAME
+    );
+
+    private static final long TIME_OUT = Long.getLong(
+            "aether.syncContext.named.timeout", 30L
+    );
+
+    private static final TimeUnit TIME_UNIT = TimeUnit.valueOf( System.getProperty(

Review comment:
       Should be `TIMEOUT_UNIT`

##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/named/DiscriminatingNameMapper.java
##########
@@ -0,0 +1,141 @@
+package org.eclipse.aether.internal.impl.synccontext.named;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.File;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.nio.charset.StandardCharsets;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Objects;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+import org.eclipse.aether.util.ChecksumUtils;
+import org.eclipse.aether.util.ConfigUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static java.util.stream.Collectors.toList;
+
+/**
+ * Discriminating {@link NameMapper}, that wraps another {@link NameMapper} and adds "discriminator" as prefix,
+ * that makes lock names unique including local repository (by default). The discriminator may be passed in via
+ * {@link RepositorySystemSession} or is automatically calculated based on local repository path.

Review comment:
       I think the key point should be mentioned here: this mapper can be used with distributed locks with the default config.

##########
File path: maven-resolver-named-locks/src/main/java/org/eclipse/aether/named/support/NamedLockSupport.java
##########
@@ -0,0 +1,87 @@
+package org.eclipse.aether.named.support;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.eclipse.aether.named.NamedLock;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Support class for {@link NamedLock} implementations providing reference counting.
+ */
+public abstract class NamedLockSupport
+    implements NamedLock
+{
+  protected final Logger log = LoggerFactory.getLogger( getClass() );
+
+  private final String name;
+
+  private final NamedLockFactorySupport factory;
+
+  private final AtomicInteger refCount;
+
+  public NamedLockSupport( final String name, final NamedLockFactorySupport factory )
+  {
+    this.name = name;
+    this.factory = factory;
+    this.refCount = new AtomicInteger( 0 );
+  }
+
+  public int incRef()
+  {
+    return refCount.incrementAndGet();
+  }
+
+  public int decRef()
+  {
+    return refCount.decrementAndGet();
+  }

Review comment:
       Can you explain why these two methods exist? Shouldn't the lock itself manage its reference count internally?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r549481196



##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/SyncContextFactoryAdapter.java
##########
@@ -0,0 +1,272 @@
+package org.eclipse.aether.internal.impl.synccontext;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+import org.eclipse.aether.named.NamedLock;
+import org.eclipse.aether.named.NamedLockFactory;
+import org.eclipse.aether.util.ChecksumUtils;
+import org.eclipse.aether.util.ConfigUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayDeque;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.TreeSet;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Adapter to adapt {@link NamedLockFactory} and {@link NamedLock} to {@link SyncContext}.
+ */
+public final class SyncContextFactoryAdapter
+{
+    private static final String DEFAULT_DISCRIMINATOR_DIGEST = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
+
+    private static final String DEFAULT_HOSTNAME = "localhost";
+
+    private static final Logger LOGGER = LoggerFactory.getLogger( SyncContextFactoryAdapter.class );
+
+    private final NamedLockFactory namedLockFactory;
+
+    private final long time;
+
+    private final TimeUnit timeUnit;
+
+    private final String hostname;
+
+    public SyncContextFactoryAdapter( final NamedLockFactory namedLockFactory,
+                                      final long time,
+                                      final TimeUnit timeUnit )
+    {
+        this.namedLockFactory = namedLockFactory;
+        this.time = time;
+        this.timeUnit = timeUnit;
+        this.hostname = getHostname();
+    }
+
+    private String getHostname()
+    {
+        try
+        {
+            return InetAddress.getLocalHost().getHostName();
+        }
+        catch ( UnknownHostException e )
+        {
+            LOGGER.warn( "Failed to get hostname, using '{}'", DEFAULT_HOSTNAME, e );
+            return DEFAULT_HOSTNAME;
+        }
+    }
+
+    public SyncContext newInstance( final RepositorySystemSession session, final boolean shared )
+    {
+        return new AdaptedLockSyncContext( session, hostname, namedLockFactory, time, timeUnit, shared );
+    }
+
+    public void shutdown()
+    {
+        namedLockFactory.shutdown();
+    }
+
+    private static class AdaptedLockSyncContext
+            implements SyncContext
+    {
+        private static final String CONFIG_PROP_DISCRIMINATOR = "aether.syncContext.named.discriminator";
+
+        private static final String KEY_PREFIX = "mvn:resolver:";
+
+        private static final Logger LOGGER = LoggerFactory.getLogger( AdaptedLockSyncContext.class );
+
+        private final RepositorySystemSession session;
+
+        private final String hostname;
+
+        private final NamedLockFactory namedLockFactory;
+
+        private final long time;
+
+        private final TimeUnit timeUnit;
+
+        private final boolean shared;
+
+        private final ArrayDeque<NamedLock> locks;
+
+        private AdaptedLockSyncContext( final RepositorySystemSession session,
+                                        final String hostname,
+                                        final NamedLockFactory namedLockFactory,
+                                        final long time,
+                                        final TimeUnit timeUnit,
+                                        final boolean shared )
+        {
+            this.session = session;
+            this.hostname = hostname;
+            this.namedLockFactory = namedLockFactory;
+            this.time = time;
+            this.timeUnit = timeUnit;
+            this.shared = shared;
+            this.locks = new ArrayDeque<>();
+        }
+
+        @Override
+        public void acquire( Collection<? extends Artifact> artifacts,
+                             Collection<? extends Metadata> metadatas )
+        {
+            // Deadlock prevention: https://stackoverflow.com/a/16780988/696632
+            // We must acquire multiple locks always in the same order!
+            Collection<String> keys = new TreeSet<>();
+            if ( artifacts != null )
+            {
+                for ( Artifact artifact : artifacts )
+                {
+                    // TODO Should we include extension and classifier too?
+                    String key = "artifact:" + artifact.getGroupId() + ":"
+                            + artifact.getArtifactId() + ":" + artifact.getBaseVersion();
+                    keys.add( key );
+                }
+            }
+
+            if ( metadatas != null )
+            {
+                for ( Metadata metadata : metadatas )
+                {
+                    StringBuilder key = new StringBuilder( "metadata:" );
+                    if ( !metadata.getGroupId().isEmpty() )
+                    {
+                        key.append( metadata.getGroupId() );
+                        if ( !metadata.getArtifactId().isEmpty() )
+                        {
+                            key.append( ':' ).append( metadata.getArtifactId() );
+                            if ( !metadata.getVersion().isEmpty() )
+                            {
+                                key.append( ':' ).append( metadata.getVersion() );
+                            }
+                        }
+                    }
+                    keys.add( key.toString() );
+                }
+            }
+
+            if ( keys.isEmpty() )
+            {
+                return;
+            }
+
+            String discriminator = createDiscriminator();
+            LOGGER.trace( "Using key discriminator '{}' during this session", discriminator );
+
+            LOGGER.trace( "Need {} {} lock(s) for {}", keys.size(), shared ? "read" : "write", keys );
+            int acquiredLockCount = 0;
+            for ( String key : keys )
+            {
+                NamedLock namedLock = namedLockFactory.getLock( KEY_PREFIX + discriminator + ":" + key );
+                try
+                {
+                    boolean locked;
+                    if ( shared )
+                    {
+                        locked = namedLock.lockShared( time, timeUnit );
+                    }
+                    else
+                    {
+                        locked = namedLock.lockExclusively( time, timeUnit );
+                    }
+
+                    if ( !locked )
+                    {
+                        namedLock.close();
+                        throw new IllegalStateException( "Could not lock "
+                                + namedLock.name() + " (shared=" + shared + ")" );
+                    }
+
+                    locks.push( namedLock );
+                    acquiredLockCount++;
+                }
+                catch ( InterruptedException e )
+                {
+                    Thread.currentThread().interrupt();
+                    throw new RuntimeException( e );
+                }
+            }
+            LOGGER.trace( "Total new locks acquired: {}", acquiredLockCount );
+        }
+
+        private String createDiscriminator()
+        {
+            String discriminator = ConfigUtils.getString( session, null, CONFIG_PROP_DISCRIMINATOR );
+
+            if ( discriminator == null || discriminator.isEmpty() )
+            {
+                File basedir = session.getLocalRepository().getBasedir();
+                discriminator = hostname + ":" + basedir;
+                try
+                {
+                    Map<String, Object> checksums = ChecksumUtils.calc(
+                            discriminator.getBytes( StandardCharsets.UTF_8 ),
+                            Collections.singletonList( "SHA-1" ) );
+                    Object checksum = checksums.get( "SHA-1" );
+
+                    if ( checksum instanceof Exception )
+                    {
+                        throw ( Exception ) checksum;
+                    }
+
+                    return String.valueOf( checksum );
+                }
+                catch ( Exception e )
+                {
+                    LOGGER.warn( "Failed to calculate discriminator digest, using '{}'",
+                            DEFAULT_DISCRIMINATOR_DIGEST, e );
+                    return DEFAULT_DISCRIMINATOR_DIGEST;
+                }
+            }
+
+            return discriminator;
+        }
+
+        @Override
+        public void close()
+        {
+            if ( locks.isEmpty() )
+            {
+                return;
+            }
+
+            // Release locks in reverse insertion order
+            int released = 0;
+            while ( !locks.isEmpty() )

Review comment:
       Again, why complicate?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r549460708



##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/SyncContextFactoryAdapter.java
##########
@@ -0,0 +1,272 @@
+package org.eclipse.aether.internal.impl.synccontext;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+import org.eclipse.aether.named.NamedLock;
+import org.eclipse.aether.named.NamedLockFactory;
+import org.eclipse.aether.util.ChecksumUtils;
+import org.eclipse.aether.util.ConfigUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayDeque;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.TreeSet;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Adapter to adapt {@link NamedLockFactory} and {@link NamedLock} to {@link SyncContext}.
+ */
+public final class SyncContextFactoryAdapter
+{
+    private static final String DEFAULT_DISCRIMINATOR_DIGEST = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
+
+    private static final String DEFAULT_HOSTNAME = "localhost";
+
+    private static final Logger LOGGER = LoggerFactory.getLogger( SyncContextFactoryAdapter.class );
+
+    private final NamedLockFactory namedLockFactory;
+
+    private final long time;
+
+    private final TimeUnit timeUnit;
+
+    private final String hostname;
+
+    public SyncContextFactoryAdapter( final NamedLockFactory namedLockFactory,
+                                      final long time,
+                                      final TimeUnit timeUnit )
+    {
+        this.namedLockFactory = namedLockFactory;
+        this.time = time;
+        this.timeUnit = timeUnit;
+        this.hostname = getHostname();
+    }
+
+    private String getHostname()
+    {
+        try
+        {
+            return InetAddress.getLocalHost().getHostName();
+        }
+        catch ( UnknownHostException e )
+        {
+            LOGGER.warn( "Failed to get hostname, using '{}'", DEFAULT_HOSTNAME, e );
+            return DEFAULT_HOSTNAME;
+        }
+    }
+
+    public SyncContext newInstance( final RepositorySystemSession session, final boolean shared )
+    {
+        return new AdaptedLockSyncContext( session, hostname, namedLockFactory, time, timeUnit, shared );
+    }
+
+    public void shutdown()
+    {
+        namedLockFactory.shutdown();
+    }
+
+    private static class AdaptedLockSyncContext
+            implements SyncContext
+    {
+        private static final String CONFIG_PROP_DISCRIMINATOR = "aether.syncContext.named.discriminator";
+
+        private static final String KEY_PREFIX = "mvn:resolver:";

Review comment:
       Fixed

##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/NamedSyncContextFactory.java
##########
@@ -0,0 +1,91 @@
+package org.eclipse.aether.internal.impl.synccontext;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.named.NamedLockFactory;
+import org.eclipse.aether.named.providers.LocalReadWriteLockProvider;
+import org.eclipse.aether.spi.synccontext.SyncContextFactory;
+
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Provider;
+import javax.inject.Singleton;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Named {@link SyncContextFactory} implementation that selects underlying {@link NamedLockFactory} implementation
+ * at creation.
+ */
+@Named
+@Singleton
+public final class NamedSyncContextFactory
+        implements SyncContextFactory
+{
+    private static final long TIME = Long.getLong(

Review comment:
       Fixed




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r550303553



##########
File path: maven-resolver-named-hazelcast/src/site/site.xml
##########
@@ -22,7 +22,7 @@ under the License.
 <project xmlns="http://maven.apache.org/DECORATION/1.0.0"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/DECORATION/1.0.0 http://maven.apache.org/xsd/decoration-1.0.0.xsd"
-  name="GlobalSyncContext">
+  name="NamedSyncContext">

Review comment:
       Fixed

##########
File path: maven-resolver-named-redisson/pom.xml
##########
@@ -28,51 +28,57 @@
     <version>1.7.0-SNAPSHOT</version>
   </parent>
 
-  <artifactId>maven-resolver-synccontext-redisson</artifactId>
+  <artifactId>maven-resolver-named-redisson</artifactId>

Review comment:
       Renamed

##########
File path: maven-resolver-named-redisson/src/site/markdown/index.md.vm
##########
@@ -0,0 +1,69 @@
+${esc.hash} Named Sync Context for Maven Resolver
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+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
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+The Named Sync Context Factory is a distributed lock factory for Maven Resolver
+on top of JVM and Hazelcast to provide a fast, concurrent-safe access from one or multiple Maven instances to the
+same local Maven repository.
+
+For further details about the factory read the [Javadoc](./apidocs/org/eclipse/aether/synccontext/NamedSyncContextFactory.html).
+
+${esc.hash}${esc.hash} Open Issues/Notes
+
+- It only works when dependency injection is used and not the bundled `AetherModule` or
+  `ServiceLocator` (Maven uses dependency injection).
+- It includes a lot of trace logging which partially will go way as soon as it has been stabilized.
+- Usage from plugins has not been tested yet.
+- The `furnace-maven-plugin` does not work this implementation because it uses `ServiceLocator` instead
+  of dependency injection.
+
+${esc.hash}${esc.hash} Installation/Testing
+
+- Create the directory `${maven.home}/lib/ext/hazelcast/`.

Review comment:
       Fixed




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] Tibor17 edited a comment on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
Tibor17 edited a comment on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-811832259


   @hboutemy 
   @cstamas 
   @michael-o 
   Some long time ago I was talking about the following idea in our Slack.
   It was about atomic move for the artifact. Maybe the lock file as well.
   Can we utilize this?
   `java.nio.file.Files.move(Path source, Path target, CopyOption... options)` where option would be `StandardCopyOption.ATOMIC_MOVE`
   This means that we would download the artifact file apart. After it is done, move it or fail. I don't know if the lock file is necessary but I guess it is not in this case. Pls check it out.
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r550303951



##########
File path: maven-resolver-named-redisson/src/site/site.xml
##########
@@ -22,7 +22,7 @@ under the License.
 <project xmlns="http://maven.apache.org/DECORATION/1.0.0"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/DECORATION/1.0.0 http://maven.apache.org/xsd/decoration-1.0.0.xsd"
-  name="RedissonSyncContext">
+  name="NamedSyncContext">

Review comment:
       Fixed




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r611857217



##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/named/NameMapper.java
##########
@@ -0,0 +1,41 @@
+package org.eclipse.aether.internal.impl.synccontext.named;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Collection;
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+
+/**
+ * Component mapping lock names to passed in artifacts and metadata as required.
+ */
+public interface NameMapper
+{
+  /**
+   * Creates (opaque) names for passed in artifacts and metadata. Returned collection has max size of sum of the passed
+   * in artifacts and metadata collections, or less. If empty collection returned, there will be no locking happening.
+   * Never returns {@code null}.
+   */
+  Collection<String> nameLocks( RepositorySystemSession session,

Review comment:
       I don't that `TreeSet` is necessary, at most `SortedSet`, but since you perfectly documented the contract in the interface, a `Collection` is fine. If the output is not stable, the behavior will be *undefined*.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] rmannibucau commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
rmannibucau commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-751680455


   Hi, I have 2 questions on the PR:
   
   1. I think hazelcast should handle a property to find the client configuration file as redisson does (will avoid to play with classpath or hazelcast internal config). Aligning both/all configs sounds sane to me (maybe maven/conf/resolver.conf or so, not sure about the detail but aligning it sounds good for end users, maybe using a properties format for all and single configuration file)
   2. What about the maven classpath when using hz or redis client? Shouldn't both be shaded or (better?) isolated (using maven/resolver-lib for example and creating an URLClassLoader to execute them - or just another ClassRealm, no strong preference). 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-764929160


   I need to go through another iteration because I wasn't really happy with some things last time, plus I need test myself too. I am currently on a short leash, but will try to go through this month.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-822065281


   @michael-o need to look into this, this should not be happening


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-818655591


   > 
   > 
   > @michael-o just my 5 cents: "long running PRs" (this one is slowly 1/2 year old 😄 ) suffer from very same issues as "long running feature branches": is easy to become stale, forgotten, fall into oblivion... I don't think we need to "fix" last straw on every line of code here, in this PR (comments are becoming unmanageable huge and long threads). You already did tremendous work on improving original PR (you pointed out places for simplifying, tidy up and removing "non logical" bits), so IMO let's merge this and then we can continue "step by step" (or "baby steps" as one would say) improving overall code base. Solving _everything at once_ will take this linger even more....
   
   This is bascially my fault because it is a huge change and I have very little time...
   
   I generally agree, but I need [this question](https://github.com/apache/maven-resolver/pull/77#issuecomment-817367241) answered first to complete my understanding of your code. As soon as this is answered I will perform the tests and am good to merge this week hopefully.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] asfgit closed pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
asfgit closed pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] Tibor17 edited a comment on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
Tibor17 edited a comment on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-811832259


   @hboutemy 
   @cstamas 
   @michael-o 
   Some long time ago I was talking about the following isea in our Slack.
   It was about atomic move for the artifact. Maybe the lock file as well.
   Can we utilize this?
   `java.nio.file.Files.move(Path source, Path target, CopyOption... options)` where option would be `StandardCopyOption.ATOMIC_MOVE`
   This means that we would download the artifact file apart. After it is done, move it or fail. I don't know if the file lock is necessary but I guess it is not in this case. Pls check it out.
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] Tibor17 edited a comment on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
Tibor17 edited a comment on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-811832259


   @hboutemy 
   @cstamas 
   @michael-o 
   Some long time ago I was talking about the following isea in our Slack.
   It was about atomic move for the artifact. Maybe the lock file as well.
   Can we utilize this?
   `java.nio.file.Files.move(Path source, Path target, CopyOption... options)` where option would be `StandardCopyOption.ATOMIC_MOVE`
   This means that we would download the artifact file apart. After it is done, move it or fail. I don't know if the lock file is necessary but I guess it is not in this case. Pls check it out.
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-818012784


   > 
   > 
   > re formatting: the maven site exposed formatting rule for Idea IDE drives me nuts, it is not aligned with checkstyle, so several "reformat" attempts, sorry for that 😞
   
   No problem. Happens, really minor one!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-811791981


   General remark: my personal preference for local variables is to declare them as `T variable = new T()`, in cases when the variable is strictly local scoped. I really see no value in doing `Map aMap = new HashMap()` when the `aMap` is used in local scope only.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-819384263


   @michael-o squashed. Please merge at will once your testing done (and everything is OK).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r605523316



##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/named/takari/TakariNameMapper.java
##########
@@ -0,0 +1,98 @@
+package org.eclipse.aether.internal.impl.synccontext.named.takari;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.internal.impl.synccontext.named.NameMapper;
+import org.eclipse.aether.metadata.Metadata;
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+import java.util.Collection;
+import java.util.TreeSet;
+
+/**
+ * A {@link NameMapper} that creates same name mapping as Takari Local Repository does, without baseDir (local repo).
+ * Part of code blatantly copies parts of the Takari {@code LockingSyncContext}.
+ *
+ * @see <a href="https://github.com/takari/takari-local-repository/blob/master/src/main/java/io/takari/aether/concurrency/LockingSyncContext.java">Takari LockingSyncContext.java</a>
+ */
+@Singleton
+@Named( TakariNameMapper.NAME )
+public class TakariNameMapper

Review comment:
       yes




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas edited a comment on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas edited a comment on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-731602192


   3 nodes are required for CP only w/ Hazelcast 3.x cluster (RAFT consensus backed structures), and yes, is overkill (but someone may choose to run a "dedicated cluster" on CI nodes anyway, as here I use HZ client only that connects to some existing cluster). For non-CP stuff, single "node" that is started by provider itself is completely okay.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r611776789



##########
File path: maven-resolver-named-locks/src/main/java/org/eclipse/aether/named/NamedLock.java
##########
@@ -0,0 +1,71 @@
+package org.eclipse.aether.named;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * A named lock, functionally similar to existing JVM and other implementations. Must support boxing (reentrancy), but
+ * no lock upgrade is supported. Usual pattern to use this lock:
+ * <pre>
+ *   try (NamedLock lock = factory.getLock("resourceName")) {
+ *     if (lock.lockExclusively(10L, Timeunit.SECONDS)) {
+ *       try {
+ *         ... exclusive access to "resourceName" resource gained here
+ *       }
+ *       finally {
+ *         lock.unlock();
+ *       }
+ *     }
+ *     else {
+ *       ... failed to gain access within specified time, handle it
+ *     }
+ *   }
+ * </pre>
+ */
+public interface NamedLock
+    extends AutoCloseable
+{
+  /**
+   * Returns this instance name, never null.
+   */
+  String name();
+
+  /**
+   * Tries to lock shared, may block for given time. If successful, returns {@code true}.
+   */
+  boolean lockShared( long time, TimeUnit unit ) throws InterruptedException;
+
+  /**
+   * Tries to lock exclusively, may block for given time. If successful, returns {@code true}.
+   */
+  boolean lockExclusively( long time, TimeUnit unit ) throws InterruptedException;
+
+  /**
+   * Unlocks the lock.
+   */
+  void unlock();
+
+  /**
+   * Closes the lock.
+   */
+  @Override
+  void close();

Review comment:
       Extended javadoc, pls review 0778e2ead5c554fba2a29eb1e2ad3ab237d86198




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r549475294



##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/SyncContextFactoryAdapter.java
##########
@@ -0,0 +1,272 @@
+package org.eclipse.aether.internal.impl.synccontext;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+import org.eclipse.aether.named.NamedLock;
+import org.eclipse.aether.named.NamedLockFactory;
+import org.eclipse.aether.util.ChecksumUtils;
+import org.eclipse.aether.util.ConfigUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayDeque;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.TreeSet;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Adapter to adapt {@link NamedLockFactory} and {@link NamedLock} to {@link SyncContext}.
+ */
+public final class SyncContextFactoryAdapter
+{
+    private static final String DEFAULT_DISCRIMINATOR_DIGEST = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
+
+    private static final String DEFAULT_HOSTNAME = "localhost";
+
+    private static final Logger LOGGER = LoggerFactory.getLogger( SyncContextFactoryAdapter.class );
+
+    private final NamedLockFactory namedLockFactory;
+
+    private final long time;
+
+    private final TimeUnit timeUnit;
+
+    private final String hostname;
+
+    public SyncContextFactoryAdapter( final NamedLockFactory namedLockFactory,
+                                      final long time,
+                                      final TimeUnit timeUnit )
+    {
+        this.namedLockFactory = namedLockFactory;
+        this.time = time;
+        this.timeUnit = timeUnit;
+        this.hostname = getHostname();
+    }
+
+    private String getHostname()
+    {
+        try
+        {
+            return InetAddress.getLocalHost().getHostName();
+        }
+        catch ( UnknownHostException e )
+        {
+            LOGGER.warn( "Failed to get hostname, using '{}'", DEFAULT_HOSTNAME, e );
+            return DEFAULT_HOSTNAME;
+        }
+    }
+
+    public SyncContext newInstance( final RepositorySystemSession session, final boolean shared )
+    {
+        return new AdaptedLockSyncContext( session, hostname, namedLockFactory, time, timeUnit, shared );
+    }
+
+    public void shutdown()
+    {
+        namedLockFactory.shutdown();
+    }
+
+    private static class AdaptedLockSyncContext
+            implements SyncContext
+    {
+        private static final String CONFIG_PROP_DISCRIMINATOR = "aether.syncContext.named.discriminator";
+
+        private static final String KEY_PREFIX = "mvn:resolver:";
+
+        private static final Logger LOGGER = LoggerFactory.getLogger( AdaptedLockSyncContext.class );
+
+        private final RepositorySystemSession session;
+
+        private final String hostname;
+
+        private final NamedLockFactory namedLockFactory;
+
+        private final long time;
+
+        private final TimeUnit timeUnit;
+
+        private final boolean shared;
+
+        private final ArrayDeque<NamedLock> locks;
+
+        private AdaptedLockSyncContext( final RepositorySystemSession session,
+                                        final String hostname,
+                                        final NamedLockFactory namedLockFactory,
+                                        final long time,
+                                        final TimeUnit timeUnit,
+                                        final boolean shared )
+        {
+            this.session = session;
+            this.hostname = hostname;
+            this.namedLockFactory = namedLockFactory;
+            this.time = time;
+            this.timeUnit = timeUnit;
+            this.shared = shared;
+            this.locks = new ArrayDeque<>();
+        }
+
+        @Override
+        public void acquire( Collection<? extends Artifact> artifacts,
+                             Collection<? extends Metadata> metadatas )
+        {
+            // Deadlock prevention: https://stackoverflow.com/a/16780988/696632
+            // We must acquire multiple locks always in the same order!
+            Collection<String> keys = new TreeSet<>();
+            if ( artifacts != null )
+            {
+                for ( Artifact artifact : artifacts )
+                {
+                    // TODO Should we include extension and classifier too?
+                    String key = "artifact:" + artifact.getGroupId() + ":"
+                            + artifact.getArtifactId() + ":" + artifact.getBaseVersion();
+                    keys.add( key );
+                }
+            }
+
+            if ( metadatas != null )
+            {
+                for ( Metadata metadata : metadatas )
+                {
+                    StringBuilder key = new StringBuilder( "metadata:" );
+                    if ( !metadata.getGroupId().isEmpty() )
+                    {
+                        key.append( metadata.getGroupId() );
+                        if ( !metadata.getArtifactId().isEmpty() )
+                        {
+                            key.append( ':' ).append( metadata.getArtifactId() );
+                            if ( !metadata.getVersion().isEmpty() )
+                            {
+                                key.append( ':' ).append( metadata.getVersion() );
+                            }
+                        }
+                    }
+                    keys.add( key.toString() );
+                }
+            }
+
+            if ( keys.isEmpty() )
+            {
+                return;
+            }
+
+            String discriminator = createDiscriminator();
+            LOGGER.trace( "Using key discriminator '{}' during this session", discriminator );
+
+            LOGGER.trace( "Need {} {} lock(s) for {}", keys.size(), shared ? "read" : "write", keys );
+            int acquiredLockCount = 0;
+            for ( String key : keys )
+            {
+                NamedLock namedLock = namedLockFactory.getLock( KEY_PREFIX + discriminator + ":" + key );
+                try
+                {
+                    boolean locked;
+                    if ( shared )
+                    {
+                        locked = namedLock.lockShared( time, timeUnit );
+                    }
+                    else
+                    {
+                        locked = namedLock.lockExclusively( time, timeUnit );
+                    }
+
+                    if ( !locked )
+                    {
+                        namedLock.close();
+                        throw new IllegalStateException( "Could not lock "
+                                + namedLock.name() + " (shared=" + shared + ")" );
+                    }
+
+                    locks.push( namedLock );

Review comment:
       Why complicate? That's the point why factory caches locks (so getting already acquired ones is cheap), and the benefit is that client code (this code) is straightforward, simple, does not have hops like if-this-then-else-that... this code in adapter does not have to care at all about all those nuances IMHO.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-751531066


   Very nice, I will happily go through.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-818710284


   > 
   > 
   > > I understand this now, but am not happy with for the following reasons: We have a hard requirement on reentrancy, it is up to the lock to implement that properly. If some lock does not support it, you can employ your history for that (granted), but why impose it on locks which support it out of the box? Java's locks do perfectly fine, so does Redisson. I ran Redisson builds hundreds of times and the overhead was very little. I don't see a reason to impose another layer of emulation if the underlying lock just can be used passthrough. In fact, this can even cause bugs/weird behavior if we don't use the locks as intended.
   > 
   > See [cstamas#1](https://github.com/cstamas/maven-resolver/pull/1) (locally passes test, let's see CI)
   > 
   > But in general, I cannot emphasize enough: we use JVM iface ReadWriteLock (that is implemented by both ReentrantReadWriteLock and RedissonReadWriteLock) and that iface **state nothing** about required re-entrant capability of lock implementation. Anytway, the PR above removes questioned bits, pls review.
   
   I am not referring to the interfaces, but your are right about the interfaces, of course. See below.
   
   > Also, I don't quite understand the "We have a hard requirement on reentrancy", as `NamedLock` implementation are re-entrant. And for sure we do NOT have requirement on underlying constructs to be re-entrant (see semaphore case).
   
   Apologies for haven't made it clear enough. This is the reentrancy I am talking about: https://maven.apache.org/resolver/apidocs/org/eclipse/aether/SyncContext.html. This is the hard requirement I am talking about. Which is satisfied with `ReentrantReadWriteLock` and Redisson's Lock. Everything else needs to be simulated internally.
   
   Is my position clear now? 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r549461637



##########
File path: maven-resolver-named/src/main/java/org/eclipse/aether/named/NamedLock.java
##########
@@ -0,0 +1,71 @@
+package org.eclipse.aether.named;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * A named lock, functionally similar to existing JVM and other implementations. Does support boxing, but no
+ * lock upgrade is supported. Usual pattern to use this lock:
+ * <pre>
+ *   try (NamedLock lock = factory.getLock("resourceName")) {
+ *     if (lock.lockExclusively(10L, Timeunit.SECONDS)) {
+ *       try {
+ *         ... exclusive access to "resourceName" resource gained here
+ *       }
+ *       finally {
+ *         lock.unlock();
+ *       }
+ *     }
+ *     else {
+ *       ... failed to gain access within specified time, handle it
+ *     }
+ *   }
+ * </pre>
+ */
+public interface NamedLock

Review comment:
       That was already stated by "boxing". Reworded and added MUST and clarification, as it sounds clearer.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r611910509



##########
File path: maven-resolver-named-locks/src/main/java/org/eclipse/aether/named/support/AdaptedSemaphoreNamedLock.java
##########
@@ -41,6 +41,23 @@
         void release( int perms );
     }
 
+    /**
+     * Count of permissions involved with "nop" locking. When required lock step is preceded with a step that already
+     * fulfils currently requested locking, no locking is needed. In other words, caller already possesses the access
+     * to lock protected resource. The "nop" locking is use to track proper "boxing" of lock/unlock calls.
+     */
+    private static final int NONE = 0;

Review comment:
       As javadoc says, this is permission *count*, not "step".




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r611775129



##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/NamedSyncContextFactory.java
##########
@@ -0,0 +1,128 @@
+package org.eclipse.aether.internal.impl.synccontext;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.internal.impl.synccontext.named.DiscriminatingNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.GAVNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.NameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.NamedLockFactoryAdapter;
+import org.eclipse.aether.internal.impl.synccontext.named.StaticNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.takari.TakariNamedLockFactory;
+import org.eclipse.aether.internal.impl.synccontext.named.takari.TakariNameMapper;
+import org.eclipse.aether.named.NamedLockFactory;
+import org.eclipse.aether.named.providers.LocalReadWriteLockNamedLockFactory;
+import org.eclipse.aether.named.providers.LocalSemaphoreNamedLockFactory;
+
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Named {@link SyncContextFactoryDelegate} implementation that selects underlying {@link NamedLockFactory}
+ * implementation at creation.
+ */
+@Singleton
+@Named( NamedSyncContextFactory.NAME )
+public final class NamedSyncContextFactory
+        implements SyncContextFactoryDelegate
+{
+    public static final String NAME = "named";
+
+    private static final String FACTORY_NAME = System.getProperty(
+            "aether.syncContext.named.factory", LocalReadWriteLockNamedLockFactory.NAME
+    );
+
+    private static final String NAME_MAPPING = System.getProperty(
+        "aether.syncContext.named.nameMapping", DiscriminatingNameMapper.NAME
+    );
+
+    private static final long TIME_OUT = Long.getLong(

Review comment:
       Fixed

##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/NamedSyncContextFactory.java
##########
@@ -0,0 +1,128 @@
+package org.eclipse.aether.internal.impl.synccontext;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.internal.impl.synccontext.named.DiscriminatingNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.GAVNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.NameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.NamedLockFactoryAdapter;
+import org.eclipse.aether.internal.impl.synccontext.named.StaticNameMapper;
+import org.eclipse.aether.internal.impl.synccontext.named.takari.TakariNamedLockFactory;
+import org.eclipse.aether.internal.impl.synccontext.named.takari.TakariNameMapper;
+import org.eclipse.aether.named.NamedLockFactory;
+import org.eclipse.aether.named.providers.LocalReadWriteLockNamedLockFactory;
+import org.eclipse.aether.named.providers.LocalSemaphoreNamedLockFactory;
+
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Named {@link SyncContextFactoryDelegate} implementation that selects underlying {@link NamedLockFactory}
+ * implementation at creation.
+ */
+@Singleton
+@Named( NamedSyncContextFactory.NAME )
+public final class NamedSyncContextFactory
+        implements SyncContextFactoryDelegate
+{
+    public static final String NAME = "named";
+
+    private static final String FACTORY_NAME = System.getProperty(
+            "aether.syncContext.named.factory", LocalReadWriteLockNamedLockFactory.NAME
+    );
+
+    private static final String NAME_MAPPING = System.getProperty(
+        "aether.syncContext.named.nameMapping", DiscriminatingNameMapper.NAME

Review comment:
       Fixed




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r605551000



##########
File path: maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/DefaultSyncContextFactory.java
##########
@@ -0,0 +1,86 @@
+package org.eclipse.aether.internal.impl.synccontext;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.spi.synccontext.SyncContextFactory;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * Default {@link SyncContextFactory} implementation that delegates to some {@link SyncContextFactoryDelegate}
+ * implementation.
+ */
+@Singleton
+@Named
+public final class DefaultSyncContextFactory
+        implements SyncContextFactory, org.eclipse.aether.impl.SyncContextFactory
+{
+    private static final String SYNC_CONTEXT_FACTORY_NAME = System.getProperty(
+            "aether.syncContext.impl", NamedSyncContextFactory.NAME
+    );
+
+    private final SyncContextFactoryDelegate delegate;
+
+    /**
+     * Constructor used with DI, where factories are injected and selected based on key.
+     */
+    @Inject
+    public DefaultSyncContextFactory( final Map<String, SyncContextFactoryDelegate> delegates )
+    {
+        Objects.requireNonNull( delegates );
+        this.delegate = selectDelegate( delegates );
+    }
+
+    /**
+     * Default constructor.
+     */
+    public DefaultSyncContextFactory()
+    {
+        HashMap<String, SyncContextFactoryDelegate> delegates = new HashMap<>( 3 );
+        delegates.put( NoLockSyncContextFactory.NAME, new NoLockSyncContextFactory() );
+        delegates.put( GlobalSyncContextFactory.NAME, new GlobalSyncContextFactory() );
+        delegates.put( NamedSyncContextFactory.NAME, new NamedSyncContextFactory() );
+        this.delegate = selectDelegate( delegates );
+    }

Review comment:
       OK, makes sense!




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-783973787


   @michael-o ping


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] michael-o commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
michael-o commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r611859577



##########
File path: maven-resolver-named-locks/src/main/java/org/eclipse/aether/named/support/AdaptedSemaphoreNamedLock.java
##########
@@ -41,6 +41,23 @@
         void release( int perms );
     }
 
+    /**
+     * Count of permissions involved with "nop" locking. When required lock step is preceded with a step that already
+     * fulfils currently requested locking, no locking is needed. In other words, caller already possesses the access
+     * to lock protected resource. The "nop" locking is use to track proper "boxing" of lock/unlock calls.
+     */
+    private static final int NONE = 0;

Review comment:
       Why does this name differ from the Enum?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r524469609



##########
File path: maven-resolver-synccontext-named/src/main/java/org/eclipse/aether/internal/named/impl/AdaptedSemaphoreNamedLock.java
##########
@@ -0,0 +1,115 @@
+package org.eclipse.aether.internal.named.impl;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.internal.named.NamedLockFactorySupport;
+import org.eclipse.aether.internal.named.NamedLockSupport;
+
+import java.util.ArrayDeque;
+import java.util.Deque;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Named lock support implementation that is using "adapted" semaphore (to be able to use semaphores not sharing common
+ * API).
+ */
+public class AdaptedSemaphoreNamedLock
+        extends NamedLockSupport
+{
+    /**
+     * Wrapper for semaphore-like stuff, that do not share common ancestor. Semaphore must be created to support
+     * {@link Integer#MAX_VALUE} permissions.
+     */
+    protected interface AdaptedSemaphore
+    {
+        boolean tryAcquire( int perms, long time, TimeUnit unit ) throws InterruptedException;
+
+        void release( int perms );
+    }
+
+    private final ThreadLocal<Deque<Integer>> threadPerms;
+
+    private final AdaptedSemaphore semaphore;
+
+    public AdaptedSemaphoreNamedLock( final String name,
+                                      final NamedLockFactorySupport factory,
+                                      final AdaptedSemaphore semaphore )
+    {
+        super( name, factory );
+        this.threadPerms = ThreadLocal.withInitial( ArrayDeque::new );
+        this.semaphore = semaphore;
+    }
+
+    @Override
+    public boolean lockShared( final long time, final TimeUnit unit ) throws InterruptedException
+    {
+        Deque<Integer> perms = threadPerms.get();

Review comment:
       AdaptedSemaphoreNamedLock instance is created per "name" (so instance per name).




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r524505161



##########
File path: maven-resolver-synccontext-named/src/main/java/org/eclipse/aether/internal/named/SyncContextFactoryAdapter.java
##########
@@ -0,0 +1,300 @@
+package org.eclipse.aether.internal.named;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+import org.eclipse.aether.util.ChecksumUtils;
+import org.eclipse.aether.util.ConfigUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.nio.charset.StandardCharsets;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Deque;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.TreeSet;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Adapter to adapt {@link NamedLockFactory} and {@link NamedLock} to {@link SyncContext}.
+ */
+public final class SyncContextFactoryAdapter
+{
+    private static final String DEFAULT_DISCRIMINATOR_DIGEST = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
+
+    private static final String DEFAULT_HOSTNAME = "localhost";
+
+    private static final Logger LOGGER = LoggerFactory.getLogger( SyncContextFactoryAdapter.class );
+
+    private static final long TIME = Long.getLong(
+        SyncContextFactoryAdapter.class.getName() + ".time", 10L
+    );
+
+    private static final TimeUnit TIME_UNIT = TimeUnit.valueOf( System.getProperty(
+        SyncContextFactoryAdapter.class.getName() + ".timeunit", TimeUnit.SECONDS.name()
+    ) );
+
+    private final NamedLockFactory namedLockFactory;
+
+    private final long time;
+
+    private final TimeUnit timeUnit;
+
+    private final String hostname;
+
+    public SyncContextFactoryAdapter( final NamedLockFactory namedLockFactory )
+    {
+        this( namedLockFactory, TIME, TIME_UNIT );
+    }
+
+    public SyncContextFactoryAdapter( final NamedLockFactory namedLockFactory,
+                                      final long time,
+                                      final TimeUnit timeUnit )
+    {
+        this.namedLockFactory = namedLockFactory;
+        this.time = time;
+        this.timeUnit = timeUnit;
+        this.hostname = getHostname();
+    }
+
+    private String getHostname()
+    {
+        try
+        {
+            return InetAddress.getLocalHost().getHostName();
+        }
+        catch ( UnknownHostException e )
+        {
+            LOGGER.warn( "Failed to get hostname, using '{}'", DEFAULT_HOSTNAME, e );
+            return DEFAULT_HOSTNAME;
+        }
+    }
+
+    public SyncContext newInstance( final RepositorySystemSession session, final boolean shared )
+    {
+        return new AdaptedLockSyncContext( session, hostname, namedLockFactory, time, timeUnit, shared );
+    }
+
+    public void shutdown()
+    {
+        namedLockFactory.shutdown();
+    }
+
+    private static class AdaptedLockSyncContext
+            implements SyncContext
+    {
+        private static final String CONFIG_PROP_DISCRIMINATOR = "aether.syncContext.named.discriminator";
+
+        private static final String KEY_PREFIX = "mvn:resolver:";
+
+        private static final Logger LOGGER = LoggerFactory.getLogger( AdaptedLockSyncContext.class );
+
+        private final RepositorySystemSession session;
+
+        private final String hostname;
+
+        private final NamedLockFactory namedLockFactory;
+
+        private final long time;
+
+        private final TimeUnit timeUnit;
+
+        private final boolean shared;
+
+        private final Map<String, NamedLock> locks = new LinkedHashMap<>();
+
+        private AdaptedLockSyncContext( final RepositorySystemSession session,
+                                        final String hostname,
+                                        final NamedLockFactory namedLockFactory,
+                                        final long time,
+                                        final TimeUnit timeUnit,
+                                        final boolean shared )
+        {
+            this.session = session;
+            this.hostname = hostname;
+            this.namedLockFactory = namedLockFactory;
+            this.time = time;
+            this.timeUnit = timeUnit;
+            this.shared = shared;
+        }
+
+        @Override
+        public void acquire( Collection<? extends Artifact> artifacts,
+                             Collection<? extends Metadata> metadatas )
+        {
+            // Deadlock prevention: https://stackoverflow.com/a/16780988/696632
+            // We must acquire multiple locks always in the same order!
+            Collection<String> keys = new TreeSet<>();
+            if ( artifacts != null )
+            {
+                for ( Artifact artifact : artifacts )
+                {
+                    // TODO Should we include extension and classifier too?
+                    String key = "artifact:" + artifact.getGroupId() + ":"
+                            + artifact.getArtifactId() + ":" + artifact.getBaseVersion();
+                    keys.add( key );
+                }
+            }
+
+            if ( metadatas != null )
+            {
+                for ( Metadata metadata : metadatas )
+                {
+                    StringBuilder key = new StringBuilder( "metadata:" );
+                    if ( !metadata.getGroupId().isEmpty() )
+                    {
+                        key.append( metadata.getGroupId() );
+                        if ( !metadata.getArtifactId().isEmpty() )
+                        {
+                            key.append( ':' ).append( metadata.getArtifactId() );
+                            if ( !metadata.getVersion().isEmpty() )
+                            {
+                                key.append( ':' ).append( metadata.getVersion() );
+                            }
+                        }
+                    }
+                    keys.add( key.toString() );
+                }
+            }
+
+            if ( keys.isEmpty() )
+            {
+                return;
+            }
+
+            String discriminator = createDiscriminator();
+            LOGGER.trace( "Using key discriminator '{}' during this session", discriminator );
+
+            LOGGER.trace( "Need {} {} lock(s) for {}", keys.size(), shared ? "read" : "write", keys );
+            int acquiredLockCount = 0;
+            int reacquiredLockCount = 0;
+            boolean doLock;
+            for ( String key : keys )
+            {
+                NamedLock namedLock = locks.get( key );
+                if ( namedLock == null )
+                {
+                    namedLock = namedLockFactory.getLock( KEY_PREFIX + discriminator + ":" + key );
+                    locks.put( key, namedLock );
+                    acquiredLockCount++;
+                    doLock = true;
+                }
+                else
+                {
+                    reacquiredLockCount++;
+                    doLock = false;
+                }
+
+                if ( doLock )
+                {
+                    try
+                    {
+                        boolean locked;
+                        if ( shared )
+                        {
+                            locked = namedLock.lockShared( time, timeUnit );
+                        }
+                        else
+                        {
+                            locked = namedLock.lockExclusively( time, timeUnit );
+                        }
+
+                        if ( !locked )
+                        {
+                            throw new IllegalStateException( "Could not lock "
+                                    + namedLock.name() + " (shared=" + shared + ")" );
+                        }
+                    }
+                    catch ( InterruptedException e )
+                    {
+                        Thread.currentThread().interrupt();
+                        throw new RuntimeException( e );
+                    }
+                }
+            }
+            LOGGER.trace( "Total new locks acquired: {}, total existing locks reacquired: {}",

Review comment:
       See ec58eac66c88ad7c607e56e3c740e794785bea0e
   IMO, we misunderstood each other: lock upgrade is what SyncContext does not support (and NamedLocks did not either). I just tried to follow logic in adapter based on it's origin, the redisson. But this commit now simplifies things, and added tests for "nested" case as well.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r605541753



##########
File path: maven-resolver-named-locks/src/main/java/org/eclipse/aether/named/support/NamedLockFactorySupport.java
##########
@@ -0,0 +1,88 @@
+package org.eclipse.aether.named.support;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.eclipse.aether.named.NamedLockFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Support class for {@link NamedLockFactory} implementations providing reference counting.
+ *
+ * @param <L> the actual implementation, subclass of {@link NamedLockSupport}.
+ */
+public abstract class NamedLockFactorySupport<L extends NamedLockSupport>
+    implements NamedLockFactory
+{
+  protected final Logger log = LoggerFactory.getLogger( getClass() );
+
+  private final ConcurrentHashMap<String, L> locks;

Review comment:
       This map contains as much entries as much concurrently accessed files are in given moment (max: if all concurrently access files are different, or less if there is overlap among them), and as we use reference counting, is cleaned up afterwards last ref is removed. So, this map MAY contain as much entries as many threads are executing in parallel (so metadata threads + `-T` param?). 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r550303909



##########
File path: maven-resolver-named/src/main/java/org/eclipse/aether/named/providers/GlobalReadWriteLockProvider.java
##########
@@ -0,0 +1,129 @@
+package org.eclipse.aether.named.providers;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.named.NamedLock;
+import org.eclipse.aether.named.NamedLockFactory;
+
+import javax.inject.Named;
+import javax.inject.Provider;
+import javax.inject.Singleton;
+import java.util.ArrayDeque;
+import java.util.NoSuchElementException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+/**
+ * Provider of {@link GlobalNamedLockFactory}. This uses one "global" {@link ReentrantReadWriteLock}, is really not a
+ * "named" lock.
+ */
+@Singleton
+@Named( GlobalReadWriteLockProvider.NAME )
+public final class GlobalReadWriteLockProvider
+        implements Provider<NamedLockFactory>
+{
+    public static final String NAME = "global";
+
+    @Override
+    public NamedLockFactory get()
+    {
+        return new GlobalNamedLockFactory();
+    }
+
+    /**
+     * A global named lock factory that actually uses one singleton named lock instance for all names.
+     */
+    public static final class GlobalNamedLockFactory implements NamedLockFactory
+    {
+        private final GlobalNamedLock globalNamedLock = new GlobalNamedLock();
+
+        @Override
+        public NamedLock getLock( String name )
+        {
+            return globalNamedLock;
+        }
+
+        @Override
+        public void shutdown()
+        {
+            // nop
+        }
+    }
+
+    /**
+     * A global named lock that uses one single reentrant read-write lock.
+     */
+    public static final class GlobalNamedLock implements NamedLock
+    {
+        private final ReentrantReadWriteLock global = new ReentrantReadWriteLock();
+
+        private final ArrayDeque<Lock> steps = new ArrayDeque<>();

Review comment:
       This class is removed




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r524471145



##########
File path: maven-resolver-synccontext-named/src/main/java/org/eclipse/aether/internal/named/SyncContextFactoryAdapter.java
##########
@@ -0,0 +1,300 @@
+package org.eclipse.aether.internal.named;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+import org.eclipse.aether.util.ChecksumUtils;
+import org.eclipse.aether.util.ConfigUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.nio.charset.StandardCharsets;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Deque;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.TreeSet;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Adapter to adapt {@link NamedLockFactory} and {@link NamedLock} to {@link SyncContext}.
+ */
+public final class SyncContextFactoryAdapter
+{
+    private static final String DEFAULT_DISCRIMINATOR_DIGEST = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
+
+    private static final String DEFAULT_HOSTNAME = "localhost";
+
+    private static final Logger LOGGER = LoggerFactory.getLogger( SyncContextFactoryAdapter.class );
+
+    private static final long TIME = Long.getLong(
+        SyncContextFactoryAdapter.class.getName() + ".time", 10L
+    );
+
+    private static final TimeUnit TIME_UNIT = TimeUnit.valueOf( System.getProperty(
+        SyncContextFactoryAdapter.class.getName() + ".timeunit", TimeUnit.SECONDS.name()
+    ) );
+
+    private final NamedLockFactory namedLockFactory;
+
+    private final long time;
+
+    private final TimeUnit timeUnit;
+
+    private final String hostname;
+
+    public SyncContextFactoryAdapter( final NamedLockFactory namedLockFactory )
+    {
+        this( namedLockFactory, TIME, TIME_UNIT );
+    }
+
+    public SyncContextFactoryAdapter( final NamedLockFactory namedLockFactory,
+                                      final long time,
+                                      final TimeUnit timeUnit )
+    {
+        this.namedLockFactory = namedLockFactory;
+        this.time = time;
+        this.timeUnit = timeUnit;
+        this.hostname = getHostname();
+    }
+
+    private String getHostname()
+    {
+        try
+        {
+            return InetAddress.getLocalHost().getHostName();
+        }
+        catch ( UnknownHostException e )
+        {
+            LOGGER.warn( "Failed to get hostname, using '{}'", DEFAULT_HOSTNAME, e );
+            return DEFAULT_HOSTNAME;
+        }
+    }
+
+    public SyncContext newInstance( final RepositorySystemSession session, final boolean shared )
+    {
+        return new AdaptedLockSyncContext( session, hostname, namedLockFactory, time, timeUnit, shared );
+    }
+
+    public void shutdown()
+    {
+        namedLockFactory.shutdown();
+    }
+
+    private static class AdaptedLockSyncContext
+            implements SyncContext
+    {
+        private static final String CONFIG_PROP_DISCRIMINATOR = "aether.syncContext.named.discriminator";
+
+        private static final String KEY_PREFIX = "mvn:resolver:";
+
+        private static final Logger LOGGER = LoggerFactory.getLogger( AdaptedLockSyncContext.class );
+
+        private final RepositorySystemSession session;
+
+        private final String hostname;
+
+        private final NamedLockFactory namedLockFactory;
+
+        private final long time;
+
+        private final TimeUnit timeUnit;
+
+        private final boolean shared;
+
+        private final Map<String, NamedLock> locks = new LinkedHashMap<>();
+
+        private AdaptedLockSyncContext( final RepositorySystemSession session,
+                                        final String hostname,
+                                        final NamedLockFactory namedLockFactory,
+                                        final long time,
+                                        final TimeUnit timeUnit,
+                                        final boolean shared )
+        {
+            this.session = session;
+            this.hostname = hostname;
+            this.namedLockFactory = namedLockFactory;
+            this.time = time;
+            this.timeUnit = timeUnit;
+            this.shared = shared;
+        }
+
+        @Override
+        public void acquire( Collection<? extends Artifact> artifacts,
+                             Collection<? extends Metadata> metadatas )
+        {
+            // Deadlock prevention: https://stackoverflow.com/a/16780988/696632
+            // We must acquire multiple locks always in the same order!
+            Collection<String> keys = new TreeSet<>();
+            if ( artifacts != null )
+            {
+                for ( Artifact artifact : artifacts )
+                {
+                    // TODO Should we include extension and classifier too?
+                    String key = "artifact:" + artifact.getGroupId() + ":"
+                            + artifact.getArtifactId() + ":" + artifact.getBaseVersion();
+                    keys.add( key );
+                }
+            }
+
+            if ( metadatas != null )
+            {
+                for ( Metadata metadata : metadatas )
+                {
+                    StringBuilder key = new StringBuilder( "metadata:" );
+                    if ( !metadata.getGroupId().isEmpty() )
+                    {
+                        key.append( metadata.getGroupId() );
+                        if ( !metadata.getArtifactId().isEmpty() )
+                        {
+                            key.append( ':' ).append( metadata.getArtifactId() );
+                            if ( !metadata.getVersion().isEmpty() )
+                            {
+                                key.append( ':' ).append( metadata.getVersion() );
+                            }
+                        }
+                    }
+                    keys.add( key.toString() );
+                }
+            }
+
+            if ( keys.isEmpty() )
+            {
+                return;
+            }
+
+            String discriminator = createDiscriminator();
+            LOGGER.trace( "Using key discriminator '{}' during this session", discriminator );
+
+            LOGGER.trace( "Need {} {} lock(s) for {}", keys.size(), shared ? "read" : "write", keys );
+            int acquiredLockCount = 0;
+            int reacquiredLockCount = 0;
+            boolean doLock;
+            for ( String key : keys )
+            {
+                NamedLock namedLock = locks.get( key );
+                if ( namedLock == null )
+                {
+                    namedLock = namedLockFactory.getLock( KEY_PREFIX + discriminator + ":" + key );
+                    locks.put( key, namedLock );
+                    acquiredLockCount++;
+                    doLock = true;
+                }
+                else
+                {
+                    reacquiredLockCount++;

Review comment:
       So IIUC, acquire method is no more invoked with Artifact/Metadata that was once invoked with?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on a change in pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#discussion_r611770309



##########
File path: maven-resolver-named-locks/src/main/java/org/eclipse/aether/named/NamedLock.java
##########
@@ -0,0 +1,71 @@
+package org.eclipse.aether.named;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * A named lock, functionally similar to existing JVM and other implementations. Must support boxing (reentrancy), but
+ * no lock upgrade is supported. Usual pattern to use this lock:
+ * <pre>
+ *   try (NamedLock lock = factory.getLock("resourceName")) {
+ *     if (lock.lockExclusively(10L, Timeunit.SECONDS)) {
+ *       try {
+ *         ... exclusive access to "resourceName" resource gained here
+ *       }
+ *       finally {
+ *         lock.unlock();
+ *       }
+ *     }
+ *     else {
+ *       ... failed to gain access within specified time, handle it
+ *     }
+ *   }
+ * </pre>
+ */
+public interface NamedLock
+    extends AutoCloseable
+{
+  /**
+   * Returns this instance name, never null.
+   */
+  String name();
+
+  /**
+   * Tries to lock shared, may block for given time. If successful, returns {@code true}.
+   */
+  boolean lockShared( long time, TimeUnit unit ) throws InterruptedException;
+
+  /**
+   * Tries to lock exclusively, may block for given time. If successful, returns {@code true}.
+   */
+  boolean lockExclusively( long time, TimeUnit unit ) throws InterruptedException;

Review comment:
       um, no hard stance here. Maybe, maybe not. My reasoning for "maybe not" is that in that case developer "may assume" and expect same behaviour as from Java `Lock`... I like to keep things explicit, and this resemblance as is not is IMHO completely enough 😄 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-822066751


   @michael-o pls try now


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas edited a comment on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas edited a comment on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-751683148


   Howdy @rmannibucau 
   For now I consider both HZ and Redisson as "lab" implementation still, due these:
   * for HZ to work we either must use deprecated HZ 3.x call (HazelcastInstance#getSemaphore), or have a remote CP cluster set up (here, setup is somewhat similar to Redisson: you must have some remote "thing", server, cluster set up beforehand)
   * for Redisson, no clue how to set up tests (any ideas? can we use docker on Jenkins?)
   
   So for start, I'd focus on local (JVM local) locks and the two "extra" (again, for testing purposes: global and nolock) implementations. As they are pretty much in place. Given this PR does not include any of HZ or Redisson code into resolver (they are separate modules, it leaves it to integrator), I think we still have time to solve both questions, that IMO are valid and actually sounds useful (generic props for configuration).


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] Tibor17 commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
Tibor17 commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-811832259


   @hboutemy 
   @cstamas 
   @michael-o 
   Some long time ago I was talking about the following isea in our Slack.
   It was about atomic move for the artifact. Maybe the lock file as well.
   Can we utilize this?
   `java.nio.file.Files.move(Path source, Path target, CopyOption... options)` where opion would be `StandardCopyOption.ATOMIC_MOVE`
   This means that we would download the artifact file apart. After it is done, move it or fail. I don't know if the file lock is necessary but I guess it is not in this case. Pls check it out.
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] Tibor17 commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
Tibor17 commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-817372645


   Hey guys,
   
   I did not want to participate because the impl and API is too complicated.
   We all have experiences but it is a signal for me that if I start implementing my own Lock then there must be something wrong with me. I did it with Java's `LockSupport` parking and unparking the Threads and it was somehow working but rather used Java's lock. Here it is similar and I think it is due to the API. The concept starts with the `Collection` passed to the method `acquire`:
   
   ```
    try {
        syncContext.acquire( artifacts, metadatas );
        // work with the artifacts and metadatas
    } finally {
        syncContext.close();
    }
   ```
   
   It would be more simple to use make the parallelism at one layer below, this means the collection may become a stream but the lock would be in the thread pool. It may be so simple that you create the Artifact and push it to the queue of `ThreadPoolExecutor`.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] Tibor17 edited a comment on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
Tibor17 edited a comment on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-812088775


   You have a plenty of commits in here and I saw [a lock for file](https://github.com/apache/maven-resolver/pull/77/commits/6d5581510f613b9e2f8c774c6691a358f6eb04d1#diff-21b7caf08c41a67c6c1bc684bab997836c29c2d9b31f685aea128c543158dc14R69). My goal was to avoid the lock.
   -- for explaining why it was related.
   Cheers
   Tibor


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-resolver] cstamas commented on pull request #77: [MRESOLVER-145] SyncContext implementations

Posted by GitBox <gi...@apache.org>.
cstamas commented on pull request #77:
URL: https://github.com/apache/maven-resolver/pull/77#issuecomment-818646120


   @michael-o just my 5 cents: "long running PRs" (this one is slowly 1/2 year old :smile: ) suffer from very same issues as "long running feature branches": is easy to become stale, forgotten, fall into oblivion... I don't think we need to "fix" last straw on every line of code here, in this PR (comments are becoming unmanageable huge and long threads). You already did tremendous work on improving original PR (you pointed out places for simplifying, tidy up and removing "non logical" bits), so IMO let's merge this and then we can continue "step by step" (or "baby steps" as one would say) improving overall code base. Solving _everything at once_ will take this linger even more.... 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org