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.HashMap;
19 import java.util.Iterator;
20 import java.util.Map;
21
22 /***
23 * @author jmccrindle
24 */
25 public class DefaultRemoteHost implements RemoteHost {
26
27 private String name = null;
28 private Map agentsMap = new HashMap();
29
30 public DefaultRemoteHost() {
31
32 }
33
34 /***
35 * @param name
36 * @param agents
37 */
38 public DefaultRemoteHost(String name) {
39 this.name = name;
40 }
41
42 /***
43 * @param name The name to set.
44 */
45 public void setName(String name) {
46 this.name = name;
47 }
48
49
50
51
52 public String getName() {
53 return name;
54 }
55
56
57
58
59 public Iterator getAgents() {
60 return agentsMap.values().iterator();
61 }
62
63 /***
64 * @return Returns the agentsMap.
65 */
66 public Map getAgentsMap() {
67 return agentsMap;
68 }
69
70 public RemoteAgentAtHost getAgentAtHost(String name) {
71 return (RemoteAgentAtHost) agentsMap.get(name);
72 }
73
74 /***
75 * @param agentsMap The agentsMap to set.
76 */
77 public void setAgentsMap(Map agentsMap) {
78 this.agentsMap = agentsMap;
79 }
80
81
82
83
84 public boolean isUp() {
85 for (Iterator agentIterator = agentsMap.values().iterator(); agentIterator.hasNext();) {
86 RemoteAgentAtHost remoteAgent = (RemoteAgentAtHost) agentIterator.next();
87 if(!remoteAgent.isUp()) return false;
88 }
89 return true;
90 }
91
92
93
94
95 public String toString() {
96 return "{" + name + ", " + agentsMap.toString() + "}";
97 }
98
99
100
101
102 public RemoteAgentAtHost getAgent(String agent) {
103 return (RemoteAgentAtHost) agentsMap.get(agent);
104 }
105
106 public CompositeStatistics getCompositeStatistics() {
107 int total, up, down;
108 total = up = down = 0;
109 for (Iterator agentIterator = this.getAgents(); agentIterator.hasNext();) {
110 RemoteAgentAtHost agentAtHost = (RemoteAgentAtHost) agentIterator.next();
111 total++;
112 if(agentAtHost.isUp()) up++; else down++;
113 }
114 return new DefaultCompositeStatistics(total, up, down);
115 }
116
117 }