1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.aether.transport.http;
20
21 import java.io.Closeable;
22
23 import org.apache.http.conn.HttpClientConnectionManager;
24 import org.eclipse.aether.RepositorySystemSession;
25 import org.eclipse.aether.repository.RemoteRepository;
26 import org.eclipse.aether.transport.http.GlobalState.CompoundKey;
27
28
29
30
31
32 final class LocalState implements Closeable {
33 private final GlobalState global;
34
35 private final HttpClientConnectionManager connMgr;
36
37 private final CompoundKey userTokenKey;
38
39 private volatile Object userToken;
40
41 private final CompoundKey expectContinueKey;
42
43 private volatile Boolean expectContinue;
44
45 private volatile Boolean webDav;
46
47 LocalState(RepositorySystemSession session, RemoteRepository repo, ConnMgrConfig connMgrConfig) {
48 global = GlobalState.get(session);
49 userToken = this;
50 if (global == null) {
51 connMgr = GlobalState.newConnectionManager(connMgrConfig);
52 userTokenKey = null;
53 expectContinueKey = null;
54 } else {
55 connMgr = global.getConnectionManager(connMgrConfig);
56 userTokenKey = new CompoundKey(repo.getId(), repo.getUrl(), repo.getAuthentication(), repo.getProxy());
57 expectContinueKey = new CompoundKey(repo.getUrl(), repo.getProxy());
58 }
59 }
60
61 public HttpClientConnectionManager getConnectionManager() {
62 return connMgr;
63 }
64
65 public Object getUserToken() {
66 if (userToken == this) {
67 userToken = (global != null) ? global.getUserToken(userTokenKey) : null;
68 }
69 return userToken;
70 }
71
72 public void setUserToken(Object userToken) {
73 this.userToken = userToken;
74 if (global != null) {
75 global.setUserToken(userTokenKey, userToken);
76 }
77 }
78
79 public boolean isExpectContinue() {
80 if (expectContinue == null) {
81 expectContinue =
82 !Boolean.FALSE.equals((global != null) ? global.getExpectContinue(expectContinueKey) : null);
83 }
84 return expectContinue;
85 }
86
87 public void setExpectContinue(boolean enabled) {
88 expectContinue = enabled;
89 if (global != null) {
90 global.setExpectContinue(expectContinueKey, enabled);
91 }
92 }
93
94 public Boolean getWebDav() {
95 return webDav;
96 }
97
98 public void setWebDav(boolean webDav) {
99 this.webDav = webDav;
100 }
101
102 @Override
103 public void close() {
104 if (global == null) {
105 connMgr.shutdown();
106 }
107 }
108 }