|
37 | 37 | import com.linecorp.bot.jackson.ModelObjectMapper;
|
38 | 38 |
|
39 | 39 | import okhttp3.Dispatcher;
|
| 40 | +import okhttp3.EventListener; |
40 | 41 | import okhttp3.Interceptor;
|
41 | 42 | import okhttp3.OkHttpClient;
|
42 | 43 | import okhttp3.Request;
|
@@ -89,6 +90,13 @@ public ApiClientBuilder(URI apiEndPoint, Class<T> clientClass, ExceptionBuilder
|
89 | 90 | */
|
90 | 91 | private List<Interceptor> additionalInterceptors = new ArrayList<>();
|
91 | 92 |
|
| 93 | + /** |
| 94 | + * Custom EventListener |
| 95 | + * |
| 96 | + * <p>You can add your own EventListener. |
| 97 | + */ |
| 98 | + private EventListener eventListener; |
| 99 | + |
92 | 100 | private Proxy proxy;
|
93 | 101 |
|
94 | 102 | private HttpAuthenticator proxyAuthenticator;
|
@@ -141,6 +149,11 @@ public ApiClientBuilder<T> addInterceptor(HttpInterceptor interceptor) {
|
141 | 149 | return this;
|
142 | 150 | }
|
143 | 151 |
|
| 152 | + public ApiClientBuilder<T> setEventListener(EventListener eventListener) { |
| 153 | + this.eventListener = eventListener; |
| 154 | + return this; |
| 155 | + } |
| 156 | + |
144 | 157 | /**
|
145 | 158 | * The maximum number of requests to execute concurrently.
|
146 | 159 | * Default: 64
|
@@ -230,6 +243,10 @@ public T build() {
|
230 | 243 | }
|
231 | 244 | });
|
232 | 245 |
|
| 246 | + if (this.eventListener != null) { |
| 247 | + okHttpClientBuilder.eventListener(this.eventListener); |
| 248 | + } |
| 249 | + |
233 | 250 | if (this.proxy != null) {
|
234 | 251 | okHttpClientBuilder.proxy(this.proxy);
|
235 | 252 | }
|
@@ -262,6 +279,7 @@ public String toString() {
|
262 | 279 | + ", readTimeout=" + readTimeout
|
263 | 280 | + ", writeTimeout=" + writeTimeout
|
264 | 281 | + ", additionalInterceptors=" + additionalInterceptors
|
| 282 | + + ", eventListener=" + eventListener |
265 | 283 | + ", maxRequests=" + maxRequests
|
266 | 284 | + ", maxRequestsPerHost=" + maxRequestsPerHost
|
267 | 285 | + '}';
|
|
0 commit comments