Skip to content

Commit

Permalink
feature: allow overwriting the default request timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippHeuer committed Apr 15, 2019
1 parent fb72c33 commit 2875f00
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
Expand Up @@ -14,6 +14,7 @@
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.Wither;
import lombok.extern.slf4j.Slf4j;

/**
Expand All @@ -30,6 +31,12 @@ public class TwitchHelixBuilder extends TwitchAPIBuilder<TwitchHelixBuilder> {
*/
private String baseUrl = "https://api.twitch.tv/helix";

/**
* Default Timeout
*/
@Wither
private Integer timeout = 5000;

/**
* Initialize the builder
*
Expand Down Expand Up @@ -62,8 +69,8 @@ public TwitchHelix build() {
.logger(new Logger.ErrorLogger())
.errorDecoder(new TwitchHelixErrorDecoder(new JacksonDecoder()))
.requestInterceptor(new TwitchClientIdInterceptor(this))
.retryer(new Retryer.Default(1, 10000, 3))
.options(new Request.Options(5000, 15000))
.options(new Request.Options(timeout / 3, timeout))
.retryer(new Retryer.Default(500, timeout, 2))
.target(TwitchHelix.class, baseUrl);

// register with serviceMediator
Expand Down
Expand Up @@ -13,6 +13,7 @@
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.Wither;
import lombok.extern.slf4j.Slf4j;

@Slf4j
Expand All @@ -26,6 +27,12 @@ public class TwitchKrakenBuilder extends TwitchAPIBuilder<TwitchKrakenBuilder> {
*/
private String baseUrl = "https://api.twitch.tv/kraken";

/**
* Default Timeout
*/
@Wither
private Integer timeout = 5000;

/**
* Initialize the builder
*
Expand All @@ -50,8 +57,8 @@ public TwitchKraken build() {
.errorDecoder(new TwitchKrakenErrorDecoder(new JacksonDecoder()))
.logLevel(Logger.Level.BASIC)
.requestInterceptor(new TwitchClientIdInterceptor(this))
.retryer(new Retryer.Default(1, 10000, 3))
.options(new Request.Options(5000, 15000))
.options(new Request.Options(timeout / 3, timeout))
.retryer(new Retryer.Default(500, timeout, 2))
.target(TwitchKraken.class, baseUrl);

// register with serviceMediator
Expand Down
Expand Up @@ -41,6 +41,12 @@ public class TwitchClientBuilder extends TwitchAPIBuilder<TwitchClientBuilder> {
@Wither
private String redirectUrl = "http://localhost";

/**
* Default Timeout
*/
@Wither
private Integer timeout = 5000;

/**
* Enabled: Helix
*/
Expand Down Expand Up @@ -152,6 +158,7 @@ public TwitchClient build() {
.withClientSecret(getClientSecret())
.withEventManager(eventManager)
.withUserAgent(userAgent)
.withTimeout(timeout)
.build();
}

Expand All @@ -163,6 +170,7 @@ public TwitchClient build() {
.withClientSecret(getClientSecret())
.withEventManager(eventManager)
.withUserAgent(userAgent)
.withTimeout(timeout)
.build();
}

Expand Down

0 comments on commit 2875f00

Please sign in to comment.