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 this.online = online;
229 }
230
231
232
233
234
235
236 @Override
237 public String getPath() {
238 return path;
239 }
240
241
242
243
244
245 public void setPath(String path) {
246 this.path = path;
247 }
248
249
250
251
252
253
254 @Override
255 public boolean isJobProducer() {
256 return jobProducer;
257 }
258
259
260
261
262
263
264
265 public void setJobProducer(boolean jobProducer) {
266 this.jobProducer = jobProducer;
267 }
268
269
270
271
272
273
274
275 @Override
276 public Date getOnlineFrom() {
277 return onlineFrom;
278 }
279
280
281
282
283
284
285
286 public void setOnlineFrom(Date onlineFrom) {
287 this.onlineFrom = onlineFrom;
288 }
289
290
291
292
293
294
295
296 @Override
297 public ServiceState getServiceState() {
298 return serviceState;
299 }
300
301
302
303
304
305
306
307 public void setServiceState(ServiceState state) {
308 this.serviceState = state;
309 }
310
311
312
313
314
315
316
317
318
319
320 public void setServiceState(ServiceState state, int triggerJobSignature) {
321
322 setServiceState(state);
323 setStateChanged(new Date());
324 if (state == ServiceState.WARNING) {
325 setWarningStateTrigger(triggerJobSignature);
326 } else if (state == ServiceState.ERROR) {
327 setErrorStateTrigger(triggerJobSignature);
328 }
329 }
330
331
332
333
334
335
336 @Override
337 public Date getStateChanged() {
338 return stateChanged;
339 }
340
341
342
343
344
345
346
347 public void setStateChanged(Date stateChanged) {
348 this.stateChanged = stateChanged;
349 }
350
351
352
353
354
355
356 @Override
357 public int getErrorStateTrigger() {
358 return errorStateTrigger;
359 }
360
361
362
363
364
365
366
367 public void setErrorStateTrigger(int jobSignature) {
368 this.errorStateTrigger = jobSignature;
369 }
370
371
372
373
374
375
376 @Override
377 public int getWarningStateTrigger() {
378 return warningStateTrigger;
379 }
380
381
382
383
384
385
386
387 public void setWarningStateTrigger(int jobSignature) {
388 this.warningStateTrigger = jobSignature;
389 }
390
391
392
393
394
395
396 @Override
397 public int hashCode() {
398 return toString().hashCode();
399 }
400
401
402
403
404
405
406 @Override
407 public boolean equals(Object obj) {
408 if (!(obj instanceof ServiceRegistration))
409 return false;
410 ServiceRegistration registration = (ServiceRegistration) obj;
411 return getHost().equals(registration.getHost()) && getServiceType().equals(registration.getServiceType());
412 }
413
414
415
416
417
418
419 @Override
420 public String toString() {
421 return getServiceType() + "@" + getHost();
422 }
423
424 }