Source Code Cross Referenced for RemoteAgentServlet.java in  » Science » Cougaar12_4 » org » cougaar » core » qos » metrics » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Science » Cougaar12_4 » org.cougaar.core.qos.metrics 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * <copyright>
003:         *  
004:         *  Copyright 1997-2004 BBNT Solutions, LLC
005:         *  under sponsorship of the Defense Advanced Research Projects
006:         *  Agency (DARPA).
007:         * 
008:         *  You can redistribute this software and/or modify it under the
009:         *  terms of the Cougaar Open Source License as published on the
010:         *  Cougaar Open Source Website (www.cougaar.org).
011:         * 
012:         *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013:         *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014:         *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015:         *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016:         *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017:         *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018:         *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019:         *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020:         *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021:         *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022:         *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023:         *  
024:         * </copyright>
025:         */
026:
027:        package org.cougaar.core.qos.metrics;
028:
029:        import java.io.PrintWriter;
030:        import java.net.InetAddress;
031:        import java.util.Iterator;
032:        import java.util.Set;
033:
034:        import javax.servlet.http.HttpServletRequest;
035:
036:        import org.cougaar.core.component.ServiceBroker;
037:        import org.cougaar.core.mts.AgentStatusService;
038:        import org.cougaar.core.mts.MessageAddress;
039:        import org.cougaar.core.service.wp.AddressEntry;
040:
041:        /**
042:         * This Servlet displays a summary of all interactions between any
043:         * Agent on this Node and the Agents they talk to (remote or loca).
044:         */
045:        public class RemoteAgentServlet extends MetricsServlet implements 
046:                Constants {
047:
048:            private static final String TOPOLOGY = "topology";
049:            private static String localHost;
050:
051:            static {
052:                try {
053:                    InetAddress localAddr = InetAddress.getLocalHost();
054:                    localHost = localAddr.getHostAddress();
055:                } catch (java.net.UnknownHostException uhe) {
056:                    localHost = "127.0.0.1";
057:                }
058:            }
059:
060:            private AgentStatusService agentStatusService;
061:
062:            public RemoteAgentServlet(ServiceBroker sb) {
063:                super (sb);
064:
065:                agentStatusService = (AgentStatusService) sb.getService(this ,
066:                        AgentStatusService.class, null);
067:            }
068:
069:            public String getPath() {
070:                return "/metrics/remote/agents";
071:            }
072:
073:            public String getTitle() {
074:                return "Remote Agent Status for Node " + getNodeID();
075:            }
076:
077:            private String canonicalizeAddress(String hostname) {
078:                try {
079:                    InetAddress addr = InetAddress.getByName(hostname);
080:                    return addr.getHostAddress();
081:                } catch (java.net.UnknownHostException uhe) {
082:                    return hostname;
083:                }
084:            }
085:
086:            public void printPage(HttpServletRequest request, PrintWriter out) {
087:                if (agentStatusService == null)
088:                    return;
089:                // Get list of All Agents in society
090:                Set matches = agentStatusService.getRemoteAgents();
091:                if (matches == null)
092:                    return;
093:
094:                // Space between the intro and the content
095:                out.print("<br><br>");
096:
097:                //Header Row
098:                out.print("<table border=3 cellpadding=2 rules=groups>\n");
099:                out
100:                        .print("<colgroup span=1><colgroup span=3><colgroup span=1><colgroup span=2><colgroup span=1><colgroup span=2>");
101:                out.print("<tr>");
102:                out.print("<th>AGENTS</th>");
103:                out.print("<th>SpokeTo</th>");
104:                out.print("<th>HeardFrom</th>");
105:                out.print("<th>SpokeErr</th>");
106:                out.print("<th>Queue</th>");
107:                out.print("<th>MsgTo</th>");
108:                out.print("<th>MsgFrom</th>");
109:                out.print("<th>eMJIPS</th>");
110:                out.print("<th>mKbps</th>");
111:                out.print("<th>eKbps</th>");
112:                out.print("</tr>");
113:
114:                //Rows
115:                Iterator itr = matches.iterator();
116:                while (itr.hasNext()) {
117:                    MessageAddress agent = (MessageAddress) itr.next();
118:                    String name = agent.getAddress();
119:
120:                    AgentStatusService.AgentState state = agentStatusService
121:                            .getRemoteAgentState(agent);
122:                    String agentHost = null;
123:                    try {
124:                        // -1 means don't block
125:                        AddressEntry entry = wpService.get(name, TOPOLOGY, -1);
126:                        if (entry == null) {
127:                            agentHost = localHost;
128:                        } else {
129:                            agentHost = entry.getURI().getHost();
130:                        }
131:                        agentHost = canonicalizeAddress(agentHost);
132:                    } catch (Exception ex1) {
133:                    }
134:
135:                    String agentPath = "Agent(" + name + ")" + PATH_SEPR;
136:                    String destPath = "Node(" + getNodeID() + ")" + PATH_SEPR
137:                            + "Destination(" + name + ")" + PATH_SEPR;
138:                    String ipFlowPath = "IpFlow(" + localHost + "," + agentHost
139:                            + ")" + PATH_SEPR;
140:                    // Get Metrics
141:                    Metric eMJIPS = metricsService.getValue(agentPath
142:                            + "EffectiveMJips");
143:
144:                    int qLength = 0;
145:                    double qCredibility = NO_CREDIBILITY;
146:                    String qProvenance = "none";
147:                    if (state != null) {
148:                        qLength = state.queueLength;
149:                        qCredibility = SECOND_MEAS_CREDIBILITY;
150:                        qProvenance = "AgentStatusService";
151:                    }
152:
153:                    Metric queue = new MetricImpl(new Integer(qLength),
154:                            qCredibility, "none", qProvenance);
155:
156:                    Metric msgTo = metricsService.getValue(destPath + MSG_TO
157:                            + "(" + _10_SEC_AVG + ")");
158:                    Metric msgFrom = metricsService.getValue(destPath
159:                            + MSG_FROM + "(" + _10_SEC_AVG + ")");
160:                    // 	    Metric bytesTo= metricsService.getValue(destPath
161:                    // 						    +BYTES_TO+
162:                    // 						    "(" +_10_SEC_AVG+ ")");
163:                    // 	    Metric bytesFrom = metricsService.getValue(destPath
164:                    // 						       +BYTES_FROM+
165:                    // 						       "(" +_10_SEC_AVG+ ")");
166:                    Metric eMbps = metricsService.getValue(ipFlowPath
167:                            + "CapacityUnused");
168:                    Metric mMbps = metricsService.getValue(ipFlowPath
169:                            + "CapacityMax");
170:
171:                    if (queue == null)
172:                        queue = new MetricImpl(new Double(0.00), 0, "units",
173:                                "test");
174:
175:                    Metric heard = metricsService.getValue(agentPath
176:                            + "LastHeard");
177:                    if (heard == null) {
178:                        heard = new MetricImpl(new Double(0.00), 0, "units",
179:                                "test");
180:                    }
181:
182:                    Metric spoke = metricsService.getValue(agentPath
183:                            + "LastSpoke");
184:                    if (spoke == null) {
185:                        spoke = new MetricImpl(new Double(0.00), 0, "units",
186:                                "test");
187:                    }
188:
189:                    Metric error = metricsService.getValue(agentPath
190:                            + "LastSpokeError");
191:                    if (error == null) {
192:                        error = new MetricImpl(new Double(0.00), 0, "units",
193:                                "test");
194:                    }
195:
196:                    if (msgTo == null)
197:                        msgTo = new MetricImpl(new Double(0.00), 0, "units",
198:                                "test");
199:
200:                    if (msgFrom == null)
201:                        msgFrom = new MetricImpl(new Double(0.00), 0, "units",
202:                                "test");
203:
204:                    if (eMbps == null)
205:                        eMbps = new MetricImpl(new Double(0.00), 0, "units",
206:                                "test");
207:
208:                    if (mMbps == null)
209:                        mMbps = new MetricImpl(new Double(0.00), 0, "units",
210:                                "test");
211:
212:                    //output Row
213:                    out.print("<tr><td>");
214:                    out.print(name);
215:                    out.print("</td>");
216:                    ServletUtilities.valueTable(spoke, 0.0, 30.0, true, f3_0,
217:                            out);
218:                    ServletUtilities.valueTable(heard, 0.0, 30.0, true, f3_0,
219:                            out);
220:                    ServletUtilities.valueTable(error, 0.0, 60.0, false, f3_0,
221:                            out);
222:                    ServletUtilities.valueTable(queue, 0.0, 1.0, true, f4_2,
223:                            out);
224:                    ServletUtilities.valueTable(msgTo, 0.0, 1.0, true, f4_2,
225:                            out);
226:                    ServletUtilities.valueTable(msgFrom, 0.0, 1.0, true, f4_2,
227:                            out);
228:                    ServletUtilities.valueTable(eMJIPS, 10.0, 400.0, false,
229:                            f3_0, out);
230:                    ServletUtilities.valueTable(mMbps, 0.0, 0.10, false, f6_3,
231:                            out);
232:                    ServletUtilities.valueTable(eMbps, 0.0, 0.10, false, f6_3,
233:                            out);
234:                    out.print("</tr>\n");
235:                }
236:                out.print("</table>");
237:            }
238:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.