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 DefaultRemoteAgent implements RemoteAgent {
27
28 private String name = null;
29 private Map hostsMap = new ConcurrentHashMap();
30
31 /***
32 * @param agent
33 */
34 public DefaultRemoteAgent(String agent) {
35 this.name = agent;
36 }
37
38
39
40
41 public String getName() {
42 return name;
43 }
44
45
46
47
48 public Iterator getHosts() {
49 return hostsMap.values().iterator();
50 }
51
52 public RemoteAgentAtHost getHost(String host) {
53 return (RemoteAgentAtHost) hostsMap.get(host);
54 }
55
56 /***
57 * @return
58 */
59 public Map getHostsMap() {
60 return hostsMap;
61 }
62
63 public boolean isUp() {
64 for (Iterator agentIterator = hostsMap.values().iterator(); agentIterator.hasNext();) {
65 RemoteAgentAtHost remoteAgent = (RemoteAgentAtHost) agentIterator.next();
66 if(!remoteAgent.isUp()) return false;
67 }
68 return true;
69 }
70
71 public CompositeStatistics getCompositeStatistics() {
72 int total, up, down;
73 total = up = down = 0;
74 for (Iterator hostIterator = this.getHosts(); hostIterator.hasNext();) {
75 RemoteAgentAtHost agentAtHost = (RemoteAgentAtHost) hostIterator.next();
76 total++;
77 if(agentAtHost.isUp()) up++; else down++;
78 }
79 return new DefaultCompositeStatistics(total, up, down);
80 }
81
82
83
84
85 public String toString() {
86 return "{" + name + ", " + hostsMap.toString() + "}";
87 }
88
89 }