WorkflowView.java
5.69 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.workflow.exec.Workflow
* com.day.crx.statistics.PathBuilder
* javax.jcr.Node
* javax.jcr.Property
* javax.jcr.RepositoryException
* javax.jcr.Session
*/
package com.day.cq.workflow.impl.statistics;
import com.day.cq.workflow.exec.Workflow;
import com.day.cq.workflow.impl.statistics.AbstractWorkflowView;
import com.day.cq.workflow.impl.statistics.WorkflowPathViewBuilder;
import com.day.crx.statistics.PathBuilder;
import java.util.Date;
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
public class WorkflowView
extends AbstractWorkflowView {
private static final String TOTAL_TIME = "totalTime";
private static final String TOTAL_COUNT = "totalCount";
private static final String ABORTED_WORKFLOWS = "abortedWorkflows";
private static final String RUNNING_WORKFLOWS = "runningWorkflows";
private static final String SUSPENDED_WORKFLOWS = "suspendedWorkflows";
private static final String COMPLETED_WORKFLOWS = "completedWorkflows";
private static final String MAX_THROUGHPUT_TIME = "maxThroughputTime";
private static final String MIN_THROUGHPUT_TIME = "minThroughputTime";
private Object eventType;
private long executionTime = 0;
public WorkflowView(String pathPrefix, Workflow workflow, Object eventType) {
super(pathPrefix);
this.eventType = eventType;
if (workflow != null && eventType.equals("WorkflowCompleted")) {
this.executionTime = this.getTime(workflow);
}
}
protected PathBuilder getPathBuilder() {
return new WorkflowPathViewBuilder();
}
public void write(Node node) throws RepositoryException {
if (this.eventType.equals("WorkflowStarted")) {
this.updateCount(node, "runningWorkflows", true);
} else if (this.eventType.equals("WorkflowResumed")) {
this.updateCount(node, "runningWorkflows", true);
this.updateCount(node, "suspendedWorkflows", false);
} else if (this.eventType.equals("WorkflowAborted")) {
this.updateCount(node, "runningWorkflows", false);
this.updateCount(node, "abortedWorkflows", true);
} else if (this.eventType.equals("WorkflowCompleted")) {
this.setMaxThroughput(node, this.executionTime);
this.setMinThroughput(node, this.executionTime);
this.updateCount(node, "runningWorkflows", false);
this.updateCount(node, "completedWorkflows", true);
this.setTotalTime(node, this.executionTime);
this.updateCount(node, "totalCount", true);
} else if (this.eventType.equals("WorkflowSuspended")) {
this.updateCount(node, "runningWorkflows", false);
this.updateCount(node, "suspendedWorkflows", true);
}
}
public long getMinThroughputTime(Session session) {
return this.get(session, "minThroughputTime");
}
public long getMaxThroughputTime(Session session) {
return this.get(session, "maxThroughputTime");
}
public long getNumOfCompleted(Session session) {
return this.get(session, "completedWorkflows");
}
public long getNumOfSuspended(Session session) {
return this.get(session, "suspendedWorkflows");
}
public long getNumOfAborted(Session session) {
return this.get(session, "abortedWorkflows");
}
public long getTotalCount(Session session) {
return this.get(session, "totalCount");
}
public long getTotalTime(Session session) {
return this.get(session, "totalTime");
}
public long getNumOfRunning(Session session) {
return this.get(session, "runningWorkflows");
}
public long getAverageThroughputTime(Session session) {
long count = this.get(session, "totalCount");
long time = this.get(session, "totalTime");
return count == 0 ? 0 : time / count;
}
private void setTotalTime(Node node, long executionTime) throws RepositoryException {
long totalTime = 0;
if (node.hasProperty("totalTime")) {
totalTime = node.getProperty("totalTime").getLong();
}
node.setProperty("totalTime", totalTime + executionTime);
}
private void setMaxThroughput(Node node, long executionTime) throws RepositoryException {
long maxThroughput = 0;
if (node.hasProperty("maxThroughputTime")) {
maxThroughput = node.getProperty("maxThroughputTime").getLong();
}
if (executionTime > maxThroughput) {
node.setProperty("maxThroughputTime", executionTime);
}
}
private void setMinThroughput(Node node, long executionTime) throws RepositoryException {
long minThroughput = -1;
if (node.hasProperty("minThroughputTime")) {
minThroughput = node.getProperty("minThroughputTime").getLong();
}
if (executionTime < minThroughput || minThroughput < 0) {
node.setProperty("minThroughputTime", executionTime);
}
}
private void updateCount(Node node, String propName, boolean doIncrement) throws RepositoryException {
long count = 0;
if (node.hasProperty(propName)) {
count = node.getProperty(propName).getLong();
}
count = doIncrement ? ++count : --count;
node.setProperty(propName, count > 0 ? count : 0);
}
private long getTime(Workflow instance) {
long startTime = instance.getTimeStarted() != null ? instance.getTimeStarted().getTime() : 0;
long endTime = instance.getTimeEnded() != null ? instance.getTimeEnded().getTime() : startTime;
return endTime - startTime;
}
}