-
Notifications
You must be signed in to change notification settings - Fork 5
/
DistributedVerticle.java
83 lines (70 loc) · 2.61 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
71
72
73
74
75
76
77
78
79
80
81
82
83
package org.genericsystem.watch.gamma;
import java.util.concurrent.atomic.AtomicInteger;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Vertx;
import io.vertx.core.VertxOptions;
import io.vertx.core.eventbus.EventBusOptions;
import io.vertx.core.spi.cluster.ClusterManager;
import io.vertx.spi.cluster.hazelcast.HazelcastClusterManager;
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 TYPE = "type";
protected static final String IP = "IP";
private final String 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;
}
private DistributedVerticle(String ip) {
this.ip = ip;
}
@Override
public void start() throws Exception {
vertx.deployVerticle(new PdfConverterVerticle(ip));
vertx.deployVerticle(new ClassifierVerticle(ip));
}
public static void main(String[] args) {
ClusterManager mgr = new HazelcastClusterManager();
VertxOptions vertxOptions = new VertxOptions().setClustered(true).setClusterManager(mgr);
vertxOptions.setEventBusOptions(new EventBusOptions()).setClustered(true);
String ip = LocalNet.getIpAddress();
vertxOptions.setClusterHost(ip);
vertxOptions.setMaxWorkerExecuteTime(Long.MAX_VALUE);
Vertx.clusteredVertx(vertxOptions, res -> {
if (res.failed())
throw new IllegalStateException(res.cause());
Vertx vertx = res.result();
vertx.deployVerticle(new HttpServerVerticle(), complete -> {
if (complete.failed())
throw new IllegalStateException(complete.cause());
vertx.deployVerticle(new DistributedVerticle(ip), result -> {
if (complete.failed())
throw new IllegalStateException(complete.cause());
});
vertx.deployVerticle(new DistributedVerticle(ip), result -> {
if (complete.failed())
throw new IllegalStateException(complete.cause());
});
vertx.deployVerticle(new DistributedVerticle(ip), result -> {
if (complete.failed())
throw new IllegalStateException(complete.cause());
});
vertx.deployVerticle(new DistributedVerticle(ip), result -> {
if (complete.failed())
throw new IllegalStateException(complete.cause());
});
});
});
}
}