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