View Javadoc
1   package org.eclipse.aether.internal.impl.synccontext.named;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.eclipse.aether.named.NamedLockFactory;
23  import org.eclipse.aether.named.providers.FileLockNamedLockFactory;
24  import org.eclipse.aether.named.providers.LocalReadWriteLockNamedLockFactory;
25  import org.eclipse.aether.named.providers.LocalSemaphoreNamedLockFactory;
26  import org.eclipse.aether.named.providers.NoopNamedLockFactory;
27  
28  import javax.inject.Inject;
29  import javax.inject.Named;
30  import javax.inject.Singleton;
31  import java.util.HashMap;
32  import java.util.Map;
33  
34  /**
35   * Simple selector implementation that uses {@link LocalReadWriteLockNamedLockFactory} and {@link GAVNameMapper} as
36   * default name lock factory and name mapper.
37   *
38   * @since 1.7.3
39   */
40  @Singleton
41  @Named
42  public final class SimpleNamedLockFactorySelector
43      extends NamedLockFactorySelectorSupport
44  {
45      private static final Map<String, NamedLockFactory> FACTORIES;
46  
47      private static final Map<String, NameMapper> NAME_MAPPERS;
48  
49      static
50      {
51          FACTORIES = new HashMap<>();
52          FACTORIES.put( NoopNamedLockFactory.NAME, new NoopNamedLockFactory() );
53          FACTORIES.put( LocalReadWriteLockNamedLockFactory.NAME, new LocalReadWriteLockNamedLockFactory() );
54          FACTORIES.put( LocalSemaphoreNamedLockFactory.NAME, new LocalSemaphoreNamedLockFactory() );
55          FACTORIES.put( FileLockNamedLockFactory.NAME, new FileLockNamedLockFactory() );
56  
57          NAME_MAPPERS = new HashMap<>();
58          NAME_MAPPERS.put( StaticNameMapper.NAME, new StaticNameMapper() );
59          NAME_MAPPERS.put( GAVNameMapper.NAME, new GAVNameMapper() );
60          NAME_MAPPERS.put( DiscriminatingNameMapper.NAME, new DiscriminatingNameMapper( new GAVNameMapper() ) );
61          NAME_MAPPERS.put( FileGAVNameMapper.NAME, new FileGAVNameMapper() );
62      }
63  
64      /**
65       * Default constructor for ServiceLocator.
66       */
67      public SimpleNamedLockFactorySelector()
68      {
69          this( FACTORIES, NAME_MAPPERS );
70      }
71  
72      @Inject
73      public SimpleNamedLockFactorySelector( final Map<String, NamedLockFactory> factories,
74                                             final Map<String, NameMapper> nameMappers )
75      {
76          super(
77              factories,
78              LocalReadWriteLockNamedLockFactory.NAME,
79              nameMappers,
80              GAVNameMapper.NAME
81          );
82      }
83  }