-
Notifications
You must be signed in to change notification settings - Fork 5
/
VerticleDeployerFromWatchApp.java
87 lines (77 loc) · 3.08 KB
/
VerticleDeployerFromWatchApp.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
84
85
86
87
package org.genericsystem.watch;
import org.genericsystem.common.GSVertx;
import org.genericsystem.common.Root;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Future;
import io.vertx.core.Verticle;
/**
* This class allow the deployment of a series of verticles from a gs-reactor application (WatchApp).
*
* @author Pierrik Lassalas
*
*/
public class VerticleDeployerFromWatchApp extends AbstractVerticle {
private static final String gsPath = System.getenv("HOME") + "/genericsystem/gs-cv_model3/";
private static final DeploymentOptions OPTIONS_NORMAL = new DeploymentOptions();
private static final DeploymentOptions OPTIONS_WORKER = new DeploymentOptions().setWorker(true).setMaxWorkerExecuteTime(Long.MAX_VALUE);
private Root root;
// public VerticleDeployerFromWatchApp() {
// this.root = new Engine(gsPath, Doc.class, RefreshTimestamp.class, DocTimestamp.class, DocFilename.class, DocClass.class, ZoneGeneric.class, ZoneText.class, ZoneTimestamp.class, ImgFilter.class, LevDistance.class, MeanLevenshtein.class,
// Score.class);
// }
/**
* Constructor of this class.
*
* @param root
* - the engine (from the application deployed with gs-reactor)
*/
public VerticleDeployerFromWatchApp(Root root) {
this.root = root;
}
/**
* Deploy a single worker verticle.
*
* @param verticle
* - the verticle to deploy
* @param errorMessage
* - the error message that will be displayed if the deployment fails
* @throws IllegalStateException
* when the verticle can not be deployed
*/
public static void deployWorkerVerticle(Verticle verticle, String errorMessage) throws IllegalStateException {
GSVertx.vertx().getVertx().deployVerticle(verticle, OPTIONS_WORKER, res -> {
if (res.failed())
throw new IllegalStateException(errorMessage != null ? errorMessage : "Deployment of worker verticle failed.", res.cause());
});
}
/**
* Start the deployment of all other verticles from the GUI interface.
*/
public void doDeploy() {
GSVertx.vertx().getVertx().deployVerticle(this, OPTIONS_WORKER, res -> {
if (res.failed())
throw new IllegalStateException("Deployment of main verticle (" + deploymentID() + ") failed.", res.cause());
else
System.out.println("Main verticle (" + deploymentID() + ") deployed");
});
}
private void deployVerticle(Verticle verticle, boolean worker) throws IllegalStateException {
vertx.deployVerticle(verticle, worker ? OPTIONS_WORKER : OPTIONS_NORMAL, res -> {
if (res.failed())
throw new IllegalStateException("Deployment of verticle failed.", res.cause());
else
System.out.println("Verticle deployed");
});
}
@Override
public void start(Future<Void> startFuture) throws Exception {
deployVerticle(new MailWatcherVerticle(), true);
deployVerticle(new PdfsConverterVerticle(), true);
deployVerticle(new ClassifierVerticle(), true);
deployVerticle(new DezonerVerticle(), true);
deployVerticle(new AddImageToEngineVerticle(root), true);
deployVerticle(new OcrVerticle(root), true);
startFuture.complete();
}
}