forked from docker-java/docker-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrackingDockerHttpClient.java
More file actions
91 lines (72 loc) · 2.25 KB
/
Copy pathTrackingDockerHttpClient.java
File metadata and controls
91 lines (72 loc) · 2.25 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package com.github.dockerjava.cmd;
import com.github.dockerjava.transport.DockerHttpClient;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
class TrackingDockerHttpClient implements DockerHttpClient {
static final Set<TrackedResponse> ACTIVE_RESPONSES = Collections.newSetFromMap(new ConcurrentHashMap<>());
private final DockerHttpClient delegate;
TrackingDockerHttpClient(DockerHttpClient delegate) {
this.delegate = delegate;
}
@Override
public Response execute(Request request) {
return new TrackedResponse(delegate.execute(request)) {
{
synchronized (ACTIVE_RESPONSES) {
ACTIVE_RESPONSES.add(this);
}
}
@Override
public void close() {
synchronized (ACTIVE_RESPONSES) {
ACTIVE_RESPONSES.remove(this);
}
super.close();
}
};
}
@Override
public void close() throws IOException {
delegate.close();
}
static class TrackedResponse implements Response {
private static class AllocatedAt extends Exception {
public AllocatedAt(String message) {
super(message);
}
}
final Exception allocatedAt = new AllocatedAt(this.toString());
private final Response delegate;
TrackedResponse(Response delegate) {
this.delegate = delegate;
}
@Override
public int getStatusCode() {
return delegate.getStatusCode();
}
@Override
public Map<String, List<String>> getHeaders() {
return delegate.getHeaders();
}
@Override
public InputStream getBody() {
return delegate.getBody();
}
@Override
public void close() {
delegate.close();
}
@Override
@Nullable
public String getHeader(@Nonnull String name) {
return delegate.getHeader(name);
}
}
}