1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jdiagnose.remote.system;
17
18 import java.util.Iterator;
19 import java.util.Map;
20
21 import org.jdiagnose.concurrent.ConcurrentHashMap;
22
23 /***
24 * @author jmccrindle
25 */
26 public class DefaultRemoteAgentAtHost implements RemoteAgentAtHost {
27
28 private String agent;
29 private String host;
30 private Map diagnosticsMap = new ConcurrentHashMap();
31
32 /***
33 * @param host
34 * @param agent
35 */
36 public DefaultRemoteAgentAtHost(String host, String agent) {
37 this.host = host;
38 this.agent = agent;
39 }
40
41
42
43
44 public String getAgent() {
45 return agent;
46 }
47
48
49
50
51 public String getHost() {
52
53 return host;
54 }
55
56
57
58
59 public Iterator getDiagnostics() {
60
61 return diagnosticsMap.values().iterator();
62 }
63
64 /***
65 * @param name
66 * @return
67 */
68 public RemoteDiagnostic getDiagnostic(String name) {
69 return (RemoteDiagnostic) diagnosticsMap.get(name);
70 }
71
72 /***
73 * @return
74 */
75 public Map getDiagnosticMap() {
76 return diagnosticsMap;
77 }
78
79
80
81
82 public boolean isUp() {
83 for (Iterator diagnosticIterator = diagnosticsMap.values().iterator(); diagnosticIterator.hasNext();) {
84 RemoteDiagnostic remoteDiagnostic = (RemoteDiagnostic) diagnosticIterator.next();
85 if(!remoteDiagnostic.isUp()) return false;
86 }
87 return true;
88 }
89
90 public CompositeStatistics getCompositeStatistics() {
91 int total, up, down;
92 total = up = down = 0;
93 for (Iterator diagnosticIterator = this.getDiagnostics(); diagnosticIterator.hasNext();) {
94 Monitorable monitorable = (Monitorable) diagnosticIterator.next();
95 total++;
96 if(monitorable.isUp()) up++; else down++;
97 }
98 return new DefaultCompositeStatistics(total, up, down);
99 }
100
101
102
103
104 public String toString() {
105 return "{" + host + ", " + agent + ", " + diagnosticsMap.toString() + "}";
106 }
107
108 }