-
Notifications
You must be signed in to change notification settings - Fork 5
/
DistributedVerticle.java
70 lines (55 loc) · 1.99 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
59
60
61
62
63
64
65
66
67
68
69
70
package org.genericsystem.ir;
import java.lang.invoke.MethodHandles;
import java.util.concurrent.atomic.AtomicInteger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.AsyncResult;
import io.vertx.core.Handler;
public class DistributedVerticle extends AbstractVerticle {
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
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 final int availProc = Runtime.getRuntime().availableProcessors();
private static AtomicInteger currentExecutions = new AtomicInteger();
static {
logger.debug("Available processors: {}", availProc);
}
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 availProc;
}
@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);
}
});
});
}
}