-
Notifications
You must be signed in to change notification settings - Fork 5
/
RunScriptVerticle.java
38 lines (32 loc) · 1.27 KB
/
RunScriptVerticle.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package org.genericsystem.watch;
import org.genericsystem.cv.DidjvuScript;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.eventbus.MessageConsumer;
import io.vertx.core.logging.Logger;
import io.vertx.core.logging.LoggerFactory;
@Deprecated
public class RunScriptVerticle extends AbstractVerticle {
private static Logger log = LoggerFactory.getLogger(ClassifierVerticle.class);
public static void main(String[] args) {
VerticleDeployer.deployVerticle(new RunScriptVerticle());
}
@Override
public void start() throws Exception {
MessageConsumer<String> consumer = vertx.eventBus().consumer(VerticleDeployer.IMAGE_ADDED_TO_CLASS_ADDRESS);
consumer.handler(message -> vertx.executeBlocking(future -> {
String imagePath = message.body();
System.out.println(">>>> New classified image: " + imagePath);
int exitValue = DidjvuScript.runDidjvuScript(imagePath);
if (exitValue == 0) {
vertx.eventBus().publish(VerticleDeployer.IMAGE_TO_OCR, imagePath);
future.complete();
} else {
log.warn("Shell script execution failed on " + imagePath + " , exit value: " + exitValue + ".");
future.fail("Shell script execution failed on " + imagePath + ".");
}
}, res -> {
if (res.failed())
throw new IllegalStateException(res.cause());
}));
}
}