Skip to content

Allow setting a custom EventListener in ApiClientBuilder #1621

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.linecorp.bot.jackson.ModelObjectMapper;

import okhttp3.Dispatcher;
import okhttp3.EventListener;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
Expand Down Expand Up @@ -89,6 +90,13 @@ public ApiClientBuilder(URI apiEndPoint, Class<T> clientClass, ExceptionBuilder
*/
private List<Interceptor> additionalInterceptors = new ArrayList<>();

/**
* Custom EventListener
*
* <p>You can add your own EventListener.
*/
private EventListener eventListener;

private Proxy proxy;

private HttpAuthenticator proxyAuthenticator;
Expand Down Expand Up @@ -141,6 +149,11 @@ public ApiClientBuilder<T> addInterceptor(HttpInterceptor interceptor) {
return this;
}

public ApiClientBuilder<T> setEventListener(EventListener eventListener) {
this.eventListener = eventListener;
return this;
}

/**
* The maximum number of requests to execute concurrently.
* Default: 64
Expand Down Expand Up @@ -230,6 +243,10 @@ public T build() {
}
});

if (this.eventListener != null) {
okHttpClientBuilder.eventListener(this.eventListener);
}

if (this.proxy != null) {
okHttpClientBuilder.proxy(this.proxy);
}
Expand Down Expand Up @@ -262,6 +279,7 @@ public String toString() {
+ ", readTimeout=" + readTimeout
+ ", writeTimeout=" + writeTimeout
+ ", additionalInterceptors=" + additionalInterceptors
+ ", eventListener=" + eventListener
+ ", maxRequests=" + maxRequests
+ ", maxRequestsPerHost=" + maxRequestsPerHost
+ '}';
Expand Down