-
Notifications
You must be signed in to change notification settings - Fork 7
/
BackgroundInfo.java
122 lines (106 loc) · 3.18 KB
/
BackgroundInfo.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
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
/*
* Made with all the love in the world
* by scireum in Remshalden, Germany
*
* Copyright by scireum GmbH
* http://www.scireum.de - [email protected]
*/
package sirius.biz.cluster;
import sirius.kernel.di.std.ConfigValue;
import sirius.kernel.health.Exceptions;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/**
* Contains information about all background jobs or processes running on a node.
*/
public class BackgroundInfo {
@ConfigValue("product.baseUrl")
private static String productBaseUrl;
private final String nodeName;
private final boolean bleeding;
private final String uptime;
private final String version;
private final String detailedVersion;
private final int activeBackgroundTasks;
protected final Map<String, BackgroundJobInfo> jobs = new HashMap<>();
protected BackgroundInfo(String nodeName,
boolean bleeding,
int activeBackgroundTasks,
String uptime,
String version,
String detailedVersion) {
this.nodeName = nodeName;
this.bleeding = bleeding;
this.uptime = uptime;
this.version = version;
this.detailedVersion = detailedVersion;
this.activeBackgroundTasks = activeBackgroundTasks;
}
/**
* Builds the node-pinned URL for this node.
*
* @return the node-pinned URL for this node
*/
public String buildNodeUrl() {
try {
URI baseUri = new URI(productBaseUrl);
return new URI(baseUri.getScheme(),
baseUri.getUserInfo(),
nodeName + "." + baseUri.getHost(),
baseUri.getPort(),
null,
null,
null).toString();
} catch (URISyntaxException exception) {
Exceptions.ignore(exception);
}
return "";
}
/**
* Returns the name of the node.
*
* @return the name of the node
*/
public String getNodeName() {
return nodeName;
}
/**
* Returns the uptime of the node.
*
* @return the uptime of the node
*/
public String getUptime() {
return uptime;
}
public boolean isBleeding() {
return bleeding;
}
public String getVersion() {
return version;
}
public String getDetailedVersion() {
return detailedVersion;
}
public int getActiveBackgroundTasks() {
return activeBackgroundTasks;
}
/**
* Provides a map of all background jobs running on a node.
*
* @return a map of all background jobs using the name as key
*/
public Map<String, BackgroundJobInfo> getJobs() {
return Collections.unmodifiableMap(jobs);
}
/**
* Checks if there is a valid value for the uptime.
*
* @return true if the value is not null and set to something different of "-"
*/
public boolean hasUptime() {
return uptime != null && !"-".equals(uptime);
}
}