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 2021/03/27 21:46:39 UTC

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

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