-
Notifications
You must be signed in to change notification settings - Fork 331
Expand file tree
/
Copy pathInferredProxyContext.java
More file actions
53 lines (44 loc) · 1.53 KB
/
InferredProxyContext.java
File metadata and controls
53 lines (44 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package datadog.trace.bootstrap.instrumentation.api;
import datadog.context.Context;
import datadog.context.ContextKey;
import datadog.context.ImplicitContextKeyed;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
public class InferredProxyContext implements ImplicitContextKeyed {
public static final ContextKey<InferredProxyContext> CONTEXT_KEY =
ContextKey.named("inferred-proxy-key");
private final Map<String, String> inferredProxy;
public static InferredProxyContext fromContext(Context context) {
return context.get(CONTEXT_KEY);
}
public InferredProxyContext(Map<String, String> contextInfo) {
this.inferredProxy =
(contextInfo == null || contextInfo.isEmpty())
? new HashMap<>()
: new HashMap<>(contextInfo);
}
public InferredProxyContext() {
this.inferredProxy = new HashMap<>();
}
public Map<String, String> getInferredProxyContext() {
return Collections.unmodifiableMap(inferredProxy);
}
public void putInferredProxyInfo(String key, String value) {
inferredProxy.put(key, value);
}
public void removeInferredProxyInfo(String key) {
inferredProxy.remove(key);
}
/**
* Creates a new context with this value under its chosen key.
*
* @param context the context to copy the original values from.
* @return the new context with the implicitly keyed value.
* @see Context#with(ImplicitContextKeyed)
*/
@Override
public Context storeInto(Context context) {
return context.with(CONTEXT_KEY, this);
}
}