1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.opencastproject.serviceregistry.api;
23
24 import java.util.Date;
25
26 import javax.xml.bind.annotation.XmlAccessType;
27 import javax.xml.bind.annotation.XmlAccessorType;
28 import javax.xml.bind.annotation.XmlElement;
29 import javax.xml.bind.annotation.XmlRootElement;
30 import javax.xml.bind.annotation.XmlType;
31
32
33
34
35 @XmlAccessorType(XmlAccessType.NONE)
36 @XmlType(name = "service", namespace = "http://serviceregistry.opencastproject.org")
37 @XmlRootElement(name = "service", namespace = "http://serviceregistry.opencastproject.org")
38 public class JaxbServiceRegistration implements ServiceRegistration {
39
40 @XmlElement(name = "type")
41 protected String serviceType;
42
43 @XmlElement(name = "host")
44 protected String host;
45
46 @XmlElement(name = "path")
47 protected String path;
48
49 @XmlElement(name = "active")
50 protected boolean active;
51
52 @XmlElement(name = "online")
53 protected boolean online;
54
55 @XmlElement(name = "maintenance")
56 protected boolean maintenanceMode;
57
58 @XmlElement(name = "jobproducer")
59 protected boolean jobProducer;
60
61
62 @XmlElement(name = "onlinefrom")
63 protected Date onlineFrom;
64
65 @XmlElement(name = "service_state")
66 protected ServiceState serviceState;
67
68 @XmlElement(name = "state_changed")
69 protected Date stateChanged;
70
71 @XmlElement(name = "error_state_trigger")
72 protected int errorStateTrigger;
73
74 @XmlElement(name = "warning_state_trigger")
75 protected int warningStateTrigger;
76
77
78
79
80 public JaxbServiceRegistration() {
81 this.online = true;
82 this.active = true;
83 this.maintenanceMode = false;
84 this.onlineFrom = new Date();
85 this.serviceState = ServiceState.NORMAL;
86 this.stateChanged = new Date();
87 }
88
89
90
91
92
93
94 public JaxbServiceRegistration(ServiceRegistration serviceRegistration) {
95 this.host = serviceRegistration.getHost();
96 this.jobProducer = serviceRegistration.isJobProducer();
97 this.maintenanceMode = serviceRegistration.isInMaintenanceMode();
98 this.active = serviceRegistration.isActive();
99 this.online = serviceRegistration.isOnline();
100 this.onlineFrom = serviceRegistration.getOnlineFrom();
101 this.path = serviceRegistration.getPath();
102 this.serviceType = serviceRegistration.getServiceType();
103 this.serviceState = serviceRegistration.getServiceState();
104 this.stateChanged = serviceRegistration.getStateChanged();
105 this.warningStateTrigger = serviceRegistration.getWarningStateTrigger();
106 this.errorStateTrigger = serviceRegistration.getErrorStateTrigger();
107 }
108
109
110
111
112
113
114
115
116
117 public JaxbServiceRegistration(String serviceType, String host, String path) {
118 this();
119 this.serviceType = serviceType;
120 this.host = host;
121 this.path = path;
122 }
123
124
125
126
127
128
129
130
131
132
133 public JaxbServiceRegistration(String serviceType, String host, String path, boolean jobProducer) {
134 this();
135 this.serviceType = serviceType;
136 this.host = host;
137 this.path = path;
138 this.jobProducer = jobProducer;
139 }
140
141
142
143
144
145
146 @Override
147 public String getHost() {
148 return host;
149 }
150
151
152
153
154
155 public void setHost(String host) {
156 this.host = host;
157 }
158
159
160
161
162
163
164 @Override
165 public String getServiceType() {
166 return serviceType;
167 }
168
169
170
171
172
173 public void setServiceType(String serviceType) {
174 this.serviceType = serviceType;
175 }
176
177
178
179
180
181
182 @Override
183 public boolean isInMaintenanceMode() {
184 return maintenanceMode;
185 }
186
187
188
189
190
191
192 public void setInMaintenanceMode(boolean maintenanceMode) {
193 this.maintenanceMode = maintenanceMode;
194 }
195
196
197
198
199
200
201 @Override
202 public boolean isActive() {
203 return active;
204 }
205
206 public void setActive(boolean active) {
207 this.active = active;
208 }
209
210
211
212
213
214
215 @Override
216 public boolean isOnline() {
217 return online;
218 }
219
220
221
222
223
224
225 public void setOnline(boolean online) {
226 if (online && !isOnline()) {
227 setOnlineFrom(new Date());
228 }
229 this.online = online;
230 }
231
232
233
234
235
236
237 @Override
238 public String getPath() {
239 return path;
240 }
241
242
243
244
245
246 public void setPath(String path) {
247 this.path = path;
248 }
249
250
251
252
253
254
255 @Override
256 public boolean isJobProducer() {
257 return jobProducer;
258 }
259
260
261
262
263
264
265
266 public void setJobProducer(boolean jobProducer) {
267 this.jobProducer = jobProducer;
268 }
269
270
271
272
273
274
275
276 @Override
277 public Date getOnlineFrom() {
278 return onlineFrom;
279 }
280
281
282
283
284
285
286
287 public void setOnlineFrom(Date onlineFrom) {
288 this.onlineFrom = onlineFrom;
289 }
290
291
292
293
294
295
296
297 @Override
298 public ServiceState getServiceState() {
299 return serviceState;
300 }
301
302
303
304
305
306
307
308 public void setServiceState(ServiceState state) {
309 this.serviceState = state;
310 }
311
312
313
314
315
316
317
318
319
320
321 public void setServiceState(ServiceState state, int triggerJobSignature) {
322
323 setServiceState(state);
324 setStateChanged(new Date());
325 if (state == ServiceState.WARNING) {
326 setWarningStateTrigger(triggerJobSignature);
327 } else if (state == ServiceState.ERROR) {
328 setErrorStateTrigger(triggerJobSignature);
329 }
330 }
331
332
333
334
335
336
337 @Override
338 public Date getStateChanged() {
339 return stateChanged;
340 }
341
342
343
344
345
346
347
348 public void setStateChanged(Date stateChanged) {
349 this.stateChanged = stateChanged;
350 }
351
352
353
354
355
356
357 @Override
358 public int getErrorStateTrigger() {
359 return errorStateTrigger;
360 }
361
362
363
364
365
366
367
368 public void setErrorStateTrigger(int jobSignature) {
369 this.errorStateTrigger = jobSignature;
370 }
371
372
373
374
375
376
377 @Override
378 public int getWarningStateTrigger() {
379 return warningStateTrigger;
380 }
381
382
383
384
385
386
387
388 public void setWarningStateTrigger(int jobSignature) {
389 this.warningStateTrigger = jobSignature;
390 }
391
392
393
394
395
396
397 @Override
398 public int hashCode() {
399 return toString().hashCode();
400 }
401
402
403
404
405
406
407 @Override
408 public boolean equals(Object obj) {
409 if (!(obj instanceof ServiceRegistration)) {
410 return false;
411 }
412 ServiceRegistration registration = (ServiceRegistration) obj;
413 return getHost().equals(registration.getHost()) && getServiceType().equals(registration.getServiceType());
414 }
415
416
417
418
419
420
421 @Override
422 public String toString() {
423 return getServiceType() + "@" + getHost();
424 }
425
426 }