@@ -44,6 +44,7 @@ public class IotaAPICore {
4444 private IotaAPIService service ;
4545 private String protocol , host , port ;
4646 private IotaLocalPoW localPoW ;
47+ private int timeOut ;
4748
4849 /**
4950 * Build the API core.
@@ -55,6 +56,7 @@ protected IotaAPICore(Builder<?> builder) {
5556 host = builder .host ;
5657 port = builder .port ;
5758 localPoW = builder .localPoW ;
59+ timeOut = builder .timeOut ;
5860 postConstruct ();
5961 }
6062
@@ -106,7 +108,7 @@ private void postConstruct() {
106108
107109 // Create OkHttpBuilder
108110 final OkHttpClient client = new OkHttpClient .Builder ()
109- .readTimeout (5000 , TimeUnit .SECONDS )
111+ .readTimeout (timeOut , TimeUnit .SECONDS )
110112 .addInterceptor (new Interceptor () {
111113 @ Override
112114 public okhttp3 .Response intercept (Chain chain ) throws IOException {
@@ -120,7 +122,7 @@ public okhttp3.Response intercept(Chain chain) throws IOException {
120122 return chain .proceed (newRequest );
121123 }
122124 })
123- .connectTimeout (5000 , TimeUnit .SECONDS )
125+ .connectTimeout (timeOut , TimeUnit .SECONDS )
124126 .build ();
125127
126128 // use client to create Retrofit service
@@ -639,6 +641,7 @@ public String getPort() {
639641
640642 @ SuppressWarnings ("unchecked" )
641643 public static class Builder <T extends Builder <T >> {
644+ public int timeOut = 5 ;
642645 String protocol , host , port ;
643646 IotaLocalPoW localPoW ;
644647 private FileReader fileReader = null ;
@@ -717,5 +720,15 @@ public T localPoW(IotaLocalPoW localPoW) {
717720 this .localPoW = localPoW ;
718721 return (T ) this ;
719722 }
723+
724+ /**
725+ * Sets the API timeout in seconds
726+ * @param timeOut the amount we wait for a response
727+ * @return
728+ */
729+ public T timeOut (int timeOut ) {
730+ this .timeOut = timeOut ;
731+ return (T ) this ;
732+ }
720733 }
721734}
0 commit comments