This repository was archived by the owner on Aug 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathAbstractGraphUpdateJob.java
More file actions
72 lines (56 loc) · 2.02 KB
/
AbstractGraphUpdateJob.java
File metadata and controls
72 lines (56 loc) · 2.02 KB
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
package org.lab41.dendrite.jobs;
import com.tinkerpop.blueprints.Vertex;
import org.lab41.dendrite.metagraph.DendriteGraph;
import org.lab41.dendrite.metagraph.MetaGraph;
import org.lab41.dendrite.metagraph.models.JobMetadata;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public abstract class AbstractGraphUpdateJob extends AbstractJob<Void> {
static Logger logger = LoggerFactory.getLogger(AbstractGraphUpdateJob.class);
protected DendriteGraph graph;
public AbstractGraphUpdateJob(MetaGraph metaGraph, JobMetadata.Id jobId, DendriteGraph graph) {
super(metaGraph, jobId);
this.graph = graph;
}
@Override
public Void call() throws Exception {
logger.debug("Starting " + getClass().getSimpleName() + " analysis on "
+ graph.getId()
+ " job " + jobId
+ " " + Thread.currentThread().getName());
setJobName(jobId, getClass().getSimpleName());
setJobState(jobId, JobMetadata.RUNNING);
try {
try {
createIndices();
graph.commit();
} catch (Throwable t) {
graph.rollback();
throw t;
}
try {
updateGraph();
graph.commit();
} catch (Throwable t) {
graph.rollback();
throw t;
}
setJobState(jobId, JobMetadata.DONE);
} catch (Throwable t) {
setJobState(jobId, JobMetadata.ERROR, t.getMessage());
throw t;
}
logger.debug("Finished analysis on " + jobId);
return null;
}
protected abstract void updateGraph() throws Exception;
protected void createIndices() { }
protected void createVertexIndex(String key, Class cls) {
if (graph.getType(key) == null) {
graph.makeKey(key)
.dataType(cls)
.indexed(DendriteGraph.INDEX_NAME, Vertex.class)
.make();
}
}
}