1 /*
2 * #%L
3 * Bitrepository Monitoring Service
4 * %%
5 * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark
6 * %%
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation, either version 2.1 of the
10 * License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Lesser Public License for more details.
16 *
17 * You should have received a copy of the GNU General Lesser Public
18 * License along with this program. If not, see
19 * <http://www.gnu.org/licenses/lgpl-2.1.html>.
20 * #L%
21 */
22 package org.bitrepository.monitoringservice.status;
23
24 import javax.xml.datatype.XMLGregorianCalendar;
25
26 import org.bitrepository.bitrepositoryelements.ResultingStatus;
27
28 /**
29 * Class to encapsulate the status of a component.
30 */
31 public class ComponentStatus {
32 /** The number of missing replies.*/
33 private int numberOfMissingReplies;
34 /** The current status code.*/
35 private ComponentStatusCode status;
36 /** The date for the latest reply.*/
37 private XMLGregorianCalendar lastReply;
38 /** The status information of the latest reply.*/
39 private String info;
40 /** Indication whether an alarm has been sent due to the components status */
41 private Boolean alarmed;
42
43
44 /**
45 * Constructor
46 */
47 public ComponentStatus() {
48 numberOfMissingReplies = 0;
49 status = ComponentStatusCode.UNKNOWN;
50 lastReply = null;
51 info = "No status received yet.";
52 alarmed = false;
53 }
54
55 /**
56 * Update the status of a component with the given results.
57 */
58 public void updateStatus(ResultingStatus resultingStatus) {
59 numberOfMissingReplies = 0;
60 status = ComponentStatusCode.valueOf(resultingStatus.getStatusInfo().getStatusCode().toString());
61 lastReply = resultingStatus.getStatusTimestamp();
62 info = resultingStatus.getStatusInfo().getStatusText();
63 alarmed = false;
64 }
65
66 /**
67 * Add another missing reply.
68 */
69 public void updateReplys() {
70 numberOfMissingReplies++;
71 }
72
73 /**
74 * Marks the component as unresponsive.
75 */
76 public void markAsUnresponsive() {
77 status = ComponentStatusCode.UNRESPONSIVE;
78 }
79
80 /**
81 * @return The number of missing replies in a row.
82 */
83 public int getNumberOfMissingReplies() {
84 return numberOfMissingReplies;
85 }
86
87 /**
88 * @return The code for the latest reply.
89 */
90 public ComponentStatusCode getStatus() {
91 return status;
92 }
93
94 /**
95 * @return The date for the latest reply.
96 */
97 public XMLGregorianCalendar getLastReply() {
98 return lastReply;
99 }
100
101 /**
102 * @return The latest status message.
103 */
104 public String getInfo() {
105 return info;
106 }
107
108 public Boolean hasAlarmed() {
109 return alarmed;
110 }
111
112 public void alarmed() {
113 alarmed = true;
114 }
115 }