Source Code Cross Referenced for GLMStimulatorResponseData.java in  » Science » Cougaar12_4 » org » cougaar » glm » servlet » 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.glm.servlet 
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.glm.servlet;
028:
029:        import java.io.IOException;
030:        import java.io.Serializable;
031:        import java.util.HashMap;
032:        import java.util.Iterator;
033:        import java.util.Map;
034:        import java.util.TreeSet;
035:
036:        import org.cougaar.planning.servlet.data.xml.XMLWriter;
037:        import org.cougaar.planning.servlet.data.xml.XMLable;
038:
039:        /** 
040:         * <pre>
041:         * Represents the returned data from a stimulator request 
042:         *
043:         * Sample output is :
044:         *
045:         * <results totalTime="0:06:069">
046:         *  <task id="1" time="0:00:090"/>
047:         *  <task id="2" time="0:02:994"/>
048:         *  <task id="3" time="0:02:985"/>
049:         * </results>
050:         *
051:         * </pre>
052:         */
053:        public class GLMStimulatorResponseData implements  XMLable, Serializable {
054:            public String totalTime;
055:            public Map taskTimes = new HashMap();
056:            private static double log10 = Math.log(10.0);
057:            private static double log5 = Math.log(5.0);
058:            private static double log2 = Math.log(2.0);
059:            private static long[] pwr10 = new long[30];
060:            private static final int NBUCKETS = pwr10.length * 3;
061:            static {
062:                long m = 1L;
063:                for (int i = 0; i < pwr10.length; i++) {
064:                    pwr10[i] = m;
065:                    m *= 10L;
066:                }
067:            }
068:            /** Response-time histogram buckets **/
069:            public int[] buckets = new int[NBUCKETS];
070:
071:            /** The maximum used bucket number **/
072:            public int maxBucket = 0;
073:            /** The minimum used bucket number **/
074:            public int minBucket = NBUCKETS - 1;
075:
076:            /**
077:             * Gets the index of the histogram bucket for the given elapsed
078:             * time. The buckets cover the range 0..1, 1..2, 2..5, 5..10, etc.
079:             **/
080:            private static int getBucket(long elapsed) {
081:                if (elapsed < 1)
082:                    return 0;
083:                int i = (int) Math.floor(Math.log(elapsed) / log10); // 1 or less should be 0
084:                if (i >= pwr10.length)
085:                    return NBUCKETS - 1;
086:                int b = (int) (elapsed / pwr10[i]);
087:                switch (b) {
088:                case 0:
089:                case 1:
090:                    return i * 3 + 0;
091:                case 2:
092:                case 3:
093:                case 4:
094:                    return i * 3 + 1;
095:                case 5:
096:                case 6:
097:                case 7:
098:                case 8:
099:                case 9:
100:                    return i * 3 + 2;
101:                }
102:                return i * 3;
103:            }
104:
105:            /**
106:             * Record the time to handle a task.
107:             * @param uid the task UID
108:             * @param time the time string to be printed
109:             * @param elapsed the numeric elapsed time for histogram
110:             **/
111:            public void addTaskAndTime(String uid, String time, long elapsed) {
112:                taskTimes.put(uid, time);
113:                int bucket = getBucket(elapsed);
114:                maxBucket = Math.max(maxBucket, bucket);
115:                minBucket = Math.min(maxBucket, bucket);
116:                buckets[bucket]++;
117:            }
118:
119:            /**
120:             * Write this class out to the Writer in XML format
121:             * @param w output Writer
122:             **/
123:            public void toXML(XMLWriter w) throws IOException {
124:                w.optagln("response");
125:                w.optagln("results", "totalTime", totalTime);
126:                for (Iterator iter = new TreeSet(taskTimes.keySet()).iterator(); iter
127:                        .hasNext();) {
128:                    Object key = iter.next();
129:                    w.sitagln("task", "id", (String) key, "time",
130:                            (String) taskTimes.get(key));
131:                }
132:                w.cltagln("results");
133:                w.optagln("histogram", "minBucket", String.valueOf(minBucket),
134:                        "maxBucket", String.valueOf(maxBucket));
135:                long bucketMin = 0L;
136:                for (int bucket = 0; bucket <= maxBucket; bucket++) {
137:                    long bucketMax = pwr10[bucket / 3];
138:                    switch (bucket % 3) {
139:                    case 0:
140:                        bucketMax *= 2L;
141:                        break;
142:                    case 1:
143:                        bucketMax *= 5L;
144:                        break;
145:                    case 2:
146:                        bucketMax *= 10L;
147:                        break;
148:                    }
149:                    if (bucket >= minBucket) {
150:                        w.sitagln("bucket", "elapsedTime", bucketMin + ".."
151:                                + bucketMax, "count", String
152:                                .valueOf(buckets[bucket]));
153:                    }
154:                    bucketMin = bucketMax;
155:                }
156:                w.cltagln("histogram");
157:                w.cltagln("response");
158:            }
159:
160:            public String toString() {
161:                StringBuffer buf = new StringBuffer();
162:                buf
163:                        .append("\n************************* Testing Summary *************************\n");
164:                buf.append("         Task UID             Time \n");
165:                for (Iterator iter = taskTimes.keySet().iterator(); iter
166:                        .hasNext();) {
167:                    Object key = iter.next();
168:                    buf.append("          " + key + "                       "
169:                            + (String) taskTimes.get(key) + "\n");
170:                }
171:                buf.append("\n         Total Time: " + totalTime);
172:                buf.append("\n Histogram");
173:                long bucketMin = 0L;
174:                for (int bucket = 0; bucket < NBUCKETS; bucket++) {
175:                    long bucketMax = pwr10[bucket / 3];
176:                    switch (bucket % 3) {
177:                    case 0:
178:                        bucketMax *= 2L;
179:                        break;
180:                    case 1:
181:                        bucketMax *= 5L;
182:                        break;
183:                    case 2:
184:                        bucketMax *= 10L;
185:                        break;
186:                    }
187:                    buf.append("\n").append(bucketMin).append("..").append(
188:                            bucketMax).append(':').append(buckets[bucket]);
189:                    bucketMin = bucketMax;
190:                }
191:                buf
192:                        .append("\n*******************************************************************\n");
193:
194:                return buf.toString();
195:            }
196:
197:            public static void main(String[] args) {
198:                for (int i = 0; i < args.length; i++) {
199:                    System.out.println(args[i] + ": "
200:                            + getBucket(new Long(args[i]).longValue()));
201:                }
202:            }
203:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.