Skip to content

Commit e33520f

Browse files
authored
Merge pull request #102 from abrami/main
adding Timeouts
2 parents 214536c + 8a8ebb7 commit e33520f

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/main/java/org/texttechnologylab/DockerUnifiedUIMAInterface/driver/DUUIPipelineComponent.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public class DUUIPipelineComponent {
7171

7272
private static String sourceView = "sourceView";
7373
private static String targetView = "targetView";
74+
private static String timeout = "timeout";
7475

7576
private String getVersion() throws URISyntaxException, IOException {
7677
ClassLoader classLoader = DUUIPipelineComponent.class.getClassLoader();
@@ -505,11 +506,17 @@ public DUUIPipelineComponent withSourceView(String viewName) {
505506
return this;
506507
}
507508

509+
508510
public DUUIPipelineComponent withTargetView(String viewName) {
509511
_options.put(targetView, viewName);
510512
return this;
511513
}
512514

515+
public DUUIPipelineComponent withTimeout(long lLong) {
516+
_options.put(timeout, String.valueOf(lLong));
517+
return this;
518+
}
519+
513520
public static DUUIPipelineComponent fromJson(String json) throws URISyntaxException, IOException {
514521
JSONObject jobj = new JSONObject(json);
515522

@@ -656,4 +663,8 @@ public DUUIPipelineComponent withSegmentationStrategy(DUUISegmentationStrategy s
656663
public DUUISegmentationStrategy getSegmentationStrategy() {
657664
return this.segmentationStrategy;
658665
}
666+
667+
public long getTimeout() {
668+
return Long.valueOf(_options.getOrDefault(timeout, "60l"));
669+
}
659670
}

src/main/java/org/texttechnologylab/DockerUnifiedUIMAInterface/driver/IDUUIInstantiatedPipelineComponent.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,12 @@ public static void process(JCas jc, IDUUIInstantiatedPipelineComponent comp, DUU
143143
long annotatorStart = serializeEnd;
144144
int tries = 0;
145145
HttpResponse<byte[]> resp = null;
146-
while(tries < 10) {
146+
while (tries < 3) {
147147
tries++;
148148
try {
149149
HttpRequest request = HttpRequest.newBuilder()
150150
.uri(URI.create(queue.getValue0().generateURL() + DUUIComposer.V1_COMPONENT_ENDPOINT_PROCESS))
151+
.timeout(Duration.ofSeconds(comp.getPipelineComponent().getTimeout()))
151152
.POST(HttpRequest.BodyPublishers.ofByteArray(ok))
152153
.version(HttpClient.Version.HTTP_1_1)
153154
.build();
@@ -160,7 +161,7 @@ public static void process(JCas jc, IDUUIInstantiatedPipelineComponent comp, DUU
160161
}
161162
}
162163
if(resp==null) {
163-
throw new IOException("Could not reach endpoint after 10 tries!");
164+
throw new IOException("Could not reach endpoint after 3 tries!");
164165
}
165166

166167

0 commit comments

Comments
 (0)