-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathGearmanServerConfiguration.java
More file actions
248 lines (206 loc) · 7.94 KB
/
GearmanServerConfiguration.java
File metadata and controls
248 lines (206 loc) · 7.94 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
package net.johnewart.gearman.server.config;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.health.HealthCheck;
import com.codahale.metrics.health.HealthCheckRegistry;
import net.johnewart.gearman.common.interfaces.JobHandleFactory;
import net.johnewart.gearman.engine.core.JobManager;
import net.johnewart.gearman.engine.core.UniqueIdFactory;
import net.johnewart.gearman.engine.metrics.MetricsEngine;
import net.johnewart.gearman.engine.metrics.QueueMetrics;
import net.johnewart.gearman.engine.queue.factories.JobQueueFactory;
import net.johnewart.gearman.engine.storage.ExceptionStorageEngine;
import net.johnewart.gearman.engine.util.LocalJobHandleFactory;
import net.johnewart.gearman.engine.util.LocalUniqueIdFactory;
import net.johnewart.gearman.server.cluster.config.ClusterConfiguration;
import net.johnewart.gearman.server.cluster.core.ClusterJobManager;
import net.johnewart.gearman.server.cluster.queue.factories.HazelcastJobQueueFactory;
import net.johnewart.gearman.server.cluster.util.HazelcastJobHandleFactory;
import net.johnewart.gearman.server.cluster.util.HazelcastUniqueIdFactory;
import net.johnewart.gearman.server.util.JobQueueMonitor;
import net.johnewart.gearman.server.util.SnapshottingJobQueueMonitor;
import org.slf4j.LoggerFactory;
public class GearmanServerConfiguration implements ServerConfiguration {
private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(GearmanServerConfiguration.class);
private int port;
private int httpPort;
private boolean enableSSL;
private boolean debugging;
private String hostName;
private JobQueueFactory jobQueueFactory;
private JobManager jobManager;
private JobQueueMonitor jobQueueMonitor;
private ExceptionStorageEngine exceptionStorageEngine;
private PersistenceEngineConfiguration persistenceEngine;
private ClusterConfiguration clusterConfiguration;
private ExceptionStoreConfiguration exceptionStoreConfiguration;
private JobHandleFactory jobHandleFactory;
private UniqueIdFactory uniqueIdFactory;
private MetricRegistry metricRegistry;
private QueueMetrics queueMetrics;
private HealthCheckRegistry healthCheckRegistry;
private final Object configLock = new Object();
private String logLevel = "ERROR";
public void setPort(int port) {
this.port = port;
}
public void setHttpPort(int httpPort) {
this.httpPort = httpPort;
}
public boolean isEnableSSL() {
return enableSSL;
}
public void setEnableSSL(boolean enableSSL) {
this.enableSSL = enableSSL;
}
public void setLogLevel(String logLevel){
this.logLevel = logLevel;
if(!debugging) {
Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
root.setLevel(Level.toLevel(this.logLevel));
}
}
public void setDebugging(boolean debugging) {
this.debugging = debugging;
Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
if(debugging) {
root.setLevel(Level.DEBUG);
}
}
public PersistenceEngineConfiguration getPersistenceEngine() {
return persistenceEngine;
}
public void setPersistenceEngine(PersistenceEngineConfiguration persistenceEngine) {
this.persistenceEngine = persistenceEngine;
}
public void setHostName(String hostName) {
this.hostName = hostName;
}
public void setJobQueueFactory(JobQueueFactory jobQueueFactory) {
this.jobQueueFactory = jobQueueFactory;
}
public void setJobManager(JobManager jobManager) {
this.jobManager = jobManager;
}
public void setJobQueueMonitor(SnapshottingJobQueueMonitor jobQueueMonitor) {
this.jobQueueMonitor = jobQueueMonitor;
}
public void setExceptionStore(ExceptionStoreConfiguration exceptionStoreConfiguration) {
this.exceptionStoreConfiguration = exceptionStoreConfiguration;
}
public ExceptionStoreConfiguration getExceptionStore() {
return exceptionStoreConfiguration;
}
@Override
public int getPort() {
return port;
}
@Override
public int getHttpPort() {
return httpPort;
}
@Override
public boolean isSSLEnabled() {
return enableSSL;
}
@Override
public boolean isDebugging() {
return debugging;
}
@Override
public String getHostName() {
if (hostName == null) {
hostName = "localhost";
}
return hostName;
}
@Override
public JobQueueFactory getJobQueueFactory() {
if (jobQueueFactory == null && getPersistenceEngine() != null) {
jobQueueFactory = getPersistenceEngine().getJobQueueFactory(getMetricRegistry());
}
return jobQueueFactory;
}
@Override
public JobManager getJobManager() {
if(jobManager == null) {
jobManager = new JobManager(getJobQueueFactory(),
getJobHandleFactory(),
getUniqueIdFactory(),
getExceptionStorageEngine(),
getQueueMetrics());
}
return jobManager;
}
@Override
public JobQueueMonitor getJobQueueMonitor() {
if (jobQueueMonitor == null) {
jobQueueMonitor = new SnapshottingJobQueueMonitor(getQueueMetrics());
}
return jobQueueMonitor;
}
@Override
public JobHandleFactory getJobHandleFactory() {
if (jobHandleFactory == null) {
jobHandleFactory = new LocalJobHandleFactory(getHostName());
}
return jobHandleFactory;
}
@Override
public UniqueIdFactory getUniqueIdFactory() {
if (uniqueIdFactory == null) {
uniqueIdFactory = new LocalUniqueIdFactory();
}
return uniqueIdFactory;
}
@Override
public MetricRegistry getMetricRegistry()
{
if (metricRegistry == null)
{
metricRegistry = new MetricRegistry();
}
return metricRegistry;
}
public QueueMetrics getQueueMetrics() {
synchronized (configLock) {
if (queueMetrics == null) {
queueMetrics = new MetricsEngine(getMetricRegistry());
}
}
return queueMetrics;
}
public ExceptionStorageEngine getExceptionStorageEngine() {
if(exceptionStorageEngine == null && getExceptionStore() != null) {
this.exceptionStorageEngine = getExceptionStore().getExceptionStorageEngine();
}
return exceptionStorageEngine;
}
public ClusterConfiguration getCluster() {
return clusterConfiguration;
}
// Setting the cluster configuration forces some settings...
public void setCluster(ClusterConfiguration clusterConfiguration) {
this.clusterConfiguration = clusterConfiguration;
this.jobQueueFactory = new HazelcastJobQueueFactory(clusterConfiguration.getHazelcastInstance());
this.jobHandleFactory = new HazelcastJobHandleFactory(clusterConfiguration.getHazelcastInstance(), getHostName());
this.uniqueIdFactory = new HazelcastUniqueIdFactory(clusterConfiguration.getHazelcastInstance());
this.jobManager = new ClusterJobManager(jobQueueFactory, jobHandleFactory, uniqueIdFactory, clusterConfiguration.getHazelcastInstance(), queueMetrics);
this.jobQueueMonitor = new SnapshottingJobQueueMonitor(queueMetrics);
}
public HealthCheckRegistry getHealthCheckRegistry()
{
if (healthCheckRegistry == null)
{
healthCheckRegistry = new HealthCheckRegistry();
if (persistenceEngine != null) {
HealthCheck dataStoreHealthcheck = persistenceEngine.getHealthCheck();
if (dataStoreHealthcheck != null) {
healthCheckRegistry.register(persistenceEngine.getEngine(), dataStoreHealthcheck);
}
}
}
return healthCheckRegistry;
}
}