@@ -44,6 +44,7 @@ public class IotaAPICore {
44
44
private IotaAPIService service ;
45
45
private String protocol , host , port ;
46
46
private IotaLocalPoW localPoW ;
47
+ private int timeOut ;
47
48
48
49
/**
49
50
* Build the API core.
@@ -55,6 +56,7 @@ protected IotaAPICore(Builder<?> builder) {
55
56
host = builder .host ;
56
57
port = builder .port ;
57
58
localPoW = builder .localPoW ;
59
+ timeOut = builder .timeOut ;
58
60
postConstruct ();
59
61
}
60
62
@@ -106,7 +108,7 @@ private void postConstruct() {
106
108
107
109
// Create OkHttpBuilder
108
110
final OkHttpClient client = new OkHttpClient .Builder ()
109
- .readTimeout (5000 , TimeUnit .SECONDS )
111
+ .readTimeout (timeOut , TimeUnit .SECONDS )
110
112
.addInterceptor (new Interceptor () {
111
113
@ Override
112
114
public okhttp3 .Response intercept (Chain chain ) throws IOException {
@@ -120,7 +122,7 @@ public okhttp3.Response intercept(Chain chain) throws IOException {
120
122
return chain .proceed (newRequest );
121
123
}
122
124
})
123
- .connectTimeout (5000 , TimeUnit .SECONDS )
125
+ .connectTimeout (timeOut , TimeUnit .SECONDS )
124
126
.build ();
125
127
126
128
// use client to create Retrofit service
@@ -639,6 +641,7 @@ public String getPort() {
639
641
640
642
@ SuppressWarnings ("unchecked" )
641
643
public static class Builder <T extends Builder <T >> {
644
+ public int timeOut = 5 ;
642
645
String protocol , host , port ;
643
646
IotaLocalPoW localPoW ;
644
647
private FileReader fileReader = null ;
@@ -717,5 +720,15 @@ public T localPoW(IotaLocalPoW localPoW) {
717
720
this .localPoW = localPoW ;
718
721
return (T ) this ;
719
722
}
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
+ }
720
733
}
721
734
}
0 commit comments