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 package org.apache.hc.client5.http.async;
28
29 import java.io.IOException;
30 import java.util.concurrent.atomic.AtomicInteger;
31
32 import org.apache.hc.client5.http.HttpRoute;
33 import org.apache.hc.client5.http.protocol.HttpClientContext;
34 import org.apache.hc.core5.annotation.Contract;
35 import org.apache.hc.core5.annotation.Internal;
36 import org.apache.hc.core5.annotation.ThreadingBehavior;
37 import org.apache.hc.core5.concurrent.CancellableDependency;
38 import org.apache.hc.core5.http.HttpException;
39 import org.apache.hc.core5.http.HttpRequest;
40 import org.apache.hc.core5.http.nio.AsyncEntityProducer;
41 import org.apache.hc.core5.util.Args;
42 import org.apache.hc.core5.util.TimeValue;
43
44
45
46
47
48
49 @Contract(threading = ThreadingBehavior.STATELESS)
50 public interface AsyncExecChain {
51
52
53
54
55
56
57 final class Scope {
58
59 public final String exchangeId;
60 public final HttpRoute route;
61 public final HttpRequest originalRequest;
62 public final CancellableDependency cancellableDependency;
63 public final HttpClientContext clientContext;
64 public final AsyncExecRuntime execRuntime;
65 public final Scheduler scheduler;
66 public final AtomicInteger execCount;
67
68
69
70
71 public Scope(
72 final String exchangeId,
73 final HttpRoute route,
74 final HttpRequest originalRequest,
75 final CancellableDependency cancellableDependency,
76 final HttpClientContext clientContext,
77 final AsyncExecRuntime execRuntime,
78 final Scheduler scheduler,
79 final AtomicInteger execCount) {
80 this.exchangeId = Args.notBlank(exchangeId, "Exchange id");
81 this.route = Args.notNull(route, "Route");
82 this.originalRequest = Args.notNull(originalRequest, "Original request");
83 this.cancellableDependency = Args.notNull(cancellableDependency, "Dependency");
84 this.clientContext = clientContext != null ? clientContext : HttpClientContext.create();
85 this.execRuntime = Args.notNull(execRuntime, "Exec runtime");
86 this.scheduler = scheduler;
87 this.execCount = execCount != null ? execCount : new AtomicInteger(1);
88 }
89
90
91
92
93
94 @Deprecated
95 public Scope(
96 final String exchangeId,
97 final HttpRoute route,
98 final HttpRequest originalRequest,
99 final CancellableDependency cancellableDependency,
100 final HttpClientContext clientContext,
101 final AsyncExecRuntime execRuntime) {
102 this(exchangeId, route, originalRequest, cancellableDependency, clientContext, execRuntime,
103 null, new AtomicInteger(1));
104 }
105
106 }
107
108
109
110
111
112
113 interface Scheduler {
114
115
116
117
118
119
120
121
122
123
124
125 void scheduleExecution(
126 HttpRequest request,
127 AsyncEntityProducer entityProducer,
128 AsyncExecChain.Scope scope,
129 AsyncExecCallback asyncExecCallback,
130 TimeValue delay);
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146 @Internal
147 default void scheduleExecution(
148 HttpRequest request,
149 AsyncEntityProducer entityProducer,
150 AsyncExecChain.Scope scope,
151 AsyncExecChain chain,
152 AsyncExecCallback asyncExecCallback,
153 TimeValue delay) {
154 scheduleExecution(request, entityProducer, scope, asyncExecCallback, delay);
155 }
156
157 }
158
159
160
161
162
163
164
165
166
167
168 void proceed(
169 HttpRequest request,
170 AsyncEntityProducer entityProducer,
171 Scope scope,
172 AsyncExecCallback asyncExecCallback) throws HttpException, IOException;
173
174 }