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