-
Notifications
You must be signed in to change notification settings - Fork 5
/
DistributedVerticle.java
58 lines (47 loc) · 1.64 KB
/
DistributedVerticle.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package org.genericsystem.ir;
import java.util.concurrent.atomic.AtomicInteger;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.AsyncResult;
import io.vertx.core.Handler;
public class DistributedVerticle extends AbstractVerticle {
public static final String BASE_PATH = System.getenv("HOME") + "/git/genericsystem2015/gs-cv/";
protected static final String FILENAME = "filename";
protected static final String JSON_OBJECT = "jsonObject";
protected static final String TYPE = "type";
protected static final String IP = "IP";
private static AtomicInteger currentExecutions = new AtomicInteger();
public static void incrementExecutions() {
currentExecutions.incrementAndGet();
}
public static void decrementExecutions() {
currentExecutions.decrementAndGet();
}
public static int getExecutionsCount() {
return currentExecutions.intValue();
}
public static int getMaxExecutions() {
// TODO: Add some logic here…
return 4;
}
@Override
public void start() throws Exception {
vertx.deployVerticle(new PdfConverterVerticle());
vertx.deployVerticle(new ClassifierVerticle());
vertx.deployVerticle(new OcrWorkerVerticle());
}
public static void main(String[] args) {
Handler<AsyncResult<String>> completionHandler = ar -> {
if (ar.failed())
throw new IllegalStateException(ar.cause());
};
Tools.deployOnCluster(vertx -> {
vertx.deployVerticle(new HttpServerVerticle(), complete -> {
if (complete.failed())
throw new IllegalStateException(complete.cause());
for (int i = 0; i < getMaxExecutions(); ++i) {
vertx.deployVerticle(new DistributedVerticle(), completionHandler);
}
});
});
}
}