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 2022/11/12 09:40:08 UTC

[GitHub] [maven-resolver] slawekjaranowski commented on a diff in pull request #219: [MRESOLVER-291] Undo params use

slawekjaranowski commented on code in PR #219:
URL: https://github.com/apache/maven-resolver/pull/219#discussion_r1020730578


##########
maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/named/NamedLockFactoryAdapterFactoryImpl.java:
##########
@@ -0,0 +1,255 @@
+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 javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.aether.MultiRuntimeException;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.impl.RepositorySystemLifecycle;
+import org.eclipse.aether.internal.impl.synccontext.named.providers.DiscriminatingNameMapperProvider;
+import org.eclipse.aether.internal.impl.synccontext.named.providers.FileGAVNameMapperProvider;
+import org.eclipse.aether.internal.impl.synccontext.named.providers.FileHashingGAVNameMapperProvider;
+import org.eclipse.aether.internal.impl.synccontext.named.providers.GAVNameMapperProvider;
+import org.eclipse.aether.internal.impl.synccontext.named.providers.StaticNameMapperProvider;
+import org.eclipse.aether.named.NamedLockFactory;
+import org.eclipse.aether.named.providers.FileLockNamedLockFactory;
+import org.eclipse.aether.named.providers.LocalReadWriteLockNamedLockFactory;
+import org.eclipse.aether.named.providers.LocalSemaphoreNamedLockFactory;
+import org.eclipse.aether.named.providers.NoopNamedLockFactory;
+import org.eclipse.aether.spi.locator.Service;
+import org.eclipse.aether.spi.locator.ServiceLocator;
+import org.eclipse.aether.util.ConfigUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * Default implementation of {@link NamedLockFactoryAdapterFactory}. By default, this implementation creates
+ * instance of adapter for each call. In turn, on shutdown it cleanly invokes shutdown method of all existing named
+ * lock factories. If different behavior needed, override the {@link #getAdapter(RepositorySystemSession)} method.
+ * <p>
+ * This class most members and methods are protected, and is meant to be extended if needed to customize its behavior.
+ * Exception from this are private static constants and initializers, mostly meant to provide out of the box
+ * defaults and to be used when no Eclipse Sisu component container used.
+ *
+ * @since 1.9.1
+ */
+@Singleton
+@Named
+public class NamedLockFactoryAdapterFactoryImpl implements NamedLockFactoryAdapterFactory, Service
+{
+    private static final String DEFAULT_FACTORY_NAME = LocalReadWriteLockNamedLockFactory.NAME;
+
+    private static final String DEFAULT_NAME_MAPPER_NAME = GAVNameMapperProvider.NAME;
+
+    private static final Map<String, NamedLockFactory> FACTORIES;
+
+    private static final Map<String, NameMapper> NAME_MAPPERS;
+
+    static
+    {
+        HashMap<String, NamedLockFactory> factories = new HashMap<>();
+        factories.put( NoopNamedLockFactory.NAME, new NoopNamedLockFactory() );
+        factories.put( LocalReadWriteLockNamedLockFactory.NAME, new LocalReadWriteLockNamedLockFactory() );
+        factories.put( LocalSemaphoreNamedLockFactory.NAME, new LocalSemaphoreNamedLockFactory() );
+        factories.put( FileLockNamedLockFactory.NAME, new FileLockNamedLockFactory() );
+        FACTORIES = factories;
+
+        HashMap<String, NameMapper> mappers = new HashMap<>();
+        mappers.put( StaticNameMapperProvider.NAME, new StaticNameMapperProvider().get() );
+        mappers.put( GAVNameMapperProvider.NAME, new GAVNameMapperProvider().get() );
+        mappers.put( DiscriminatingNameMapperProvider.NAME, new DiscriminatingNameMapperProvider().get() );
+        mappers.put( FileGAVNameMapperProvider.NAME, new FileGAVNameMapperProvider().get() );
+        mappers.put( FileHashingGAVNameMapperProvider.NAME, new FileHashingGAVNameMapperProvider().get() );
+        NAME_MAPPERS = mappers;
+    }

Review Comment:
   It is only used in no sisu environment, so can be lazy created.
   We can save a little memory usage and time needed to load class.
   I know it is not big consumption here, but when many classes have similar it can have impact.



-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

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