1 package org.eclipse.aether.internal.impl.synccontext;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import javax.inject.Inject;
23 import javax.inject.Named;
24 import javax.inject.Singleton;
25
26 import org.eclipse.aether.RepositorySystemSession;
27 import org.eclipse.aether.SyncContext;
28 import org.eclipse.aether.internal.impl.synccontext.named.NamedLockFactoryAdapter;
29 import org.eclipse.aether.internal.impl.synccontext.named.NamedLockFactoryAdapterFactory;
30 import org.eclipse.aether.spi.locator.Service;
31 import org.eclipse.aether.spi.locator.ServiceLocator;
32 import org.eclipse.aether.spi.synccontext.SyncContextFactory;
33
34 import static java.util.Objects.requireNonNull;
35
36
37
38
39
40
41
42 @Singleton
43 @Named
44 public final class DefaultSyncContextFactory
45 implements SyncContextFactory, Service
46 {
47 private static final String ADAPTER_KEY = DefaultSyncContextFactory.class.getName() + ".adapter";
48
49 private NamedLockFactoryAdapterFactory namedLockFactoryAdapterFactory;
50
51
52
53
54 @Inject
55 public DefaultSyncContextFactory( final NamedLockFactoryAdapterFactory namedLockFactoryAdapterFactory )
56 {
57 this.namedLockFactoryAdapterFactory = requireNonNull( namedLockFactoryAdapterFactory );
58 }
59
60
61
62
63
64
65 @Deprecated
66 public DefaultSyncContextFactory()
67 {
68
69 }
70
71 @Override
72 public void initService( final ServiceLocator locator )
73 {
74 this.namedLockFactoryAdapterFactory = requireNonNull(
75 locator.getService( NamedLockFactoryAdapterFactory.class ) );
76 }
77
78 @Override
79 public SyncContext newInstance( final RepositorySystemSession session, final boolean shared )
80 {
81 requireNonNull( session, "session cannot be null" );
82 NamedLockFactoryAdapter adapter = (NamedLockFactoryAdapter) session.getData().computeIfAbsent(
83 ADAPTER_KEY, () -> namedLockFactoryAdapterFactory.getAdapter( session ) );
84 return adapter.newInstance( session, shared );
85 }
86 }