Source Code Cross Referenced for AgentLoadRatePlugin.java in  » Science » Cougaar12_4 » org » cougaar » core » thread » 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.thread 
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.thread;
028:
029:        import java.util.Collection;
030:        import java.util.HashMap;
031:        import java.util.Iterator;
032:        import java.util.List;
033:        import java.util.Map;
034:        import java.util.RandomAccess;
035:
036:        import org.cougaar.core.component.ServiceBroker;
037:        import org.cougaar.core.plugin.ComponentPlugin;
038:        import org.cougaar.core.qos.metrics.Constants;
039:        import org.cougaar.core.qos.metrics.DecayingHistory;
040:        import org.cougaar.core.qos.metrics.Metric;
041:        import org.cougaar.core.qos.metrics.MetricImpl;
042:        import org.cougaar.core.qos.metrics.MetricsUpdateService;
043:        import org.cougaar.core.service.ThreadService;
044:
045:        /**
046:         * This Plugin collects the load history for the Agent in which it's
047:         * loaded, and uplaads that data to the metrics service.  It
048:         * uses the {@link AgentLoadService} to collect the raw date and should
049:         * be loaded at LOW priority to ensure that the service is available.
050:         *
051:         * In the <a
052:         * href="../../../../../OnlineManual/MetricsService/sensors.html">Sensor
053:         * Data Flow</a> pattern this class plays the role of <b>Rate
054:         * Converter</b> for load data (CPU load average, CPU) for Agents,
055:         * Nodes and Services.
056:         *
057:         * @see AgentLoadSensorPlugin
058:         * @see org.cougaar.core.qos.metrics.AgentLoadServlet
059:         */
060:        public class AgentLoadRatePlugin extends ComponentPlugin implements 
061:                Runnable, Constants {
062:            private static final int BASE_PERIOD = 10; //10SecAVG
063:
064:            private class AgentLoadHistory extends DecayingHistory {
065:                private static final double CREDIBILITY = SECOND_MEAS_CREDIBILITY;
066:
067:                String agentKey;
068:                String mjipsKey;
069:                String loadavgKey;
070:
071:                AgentLoadHistory(String name) {
072:                    super (10, 3, BASE_PERIOD);
073:                    if (name.startsWith("Service"))
074:                        agentKey = name;
075:                    else if (name.startsWith("NodeTotal_"))
076:                        agentKey = "Node" + KEY_SEPR + name.substring(10);
077:                    else
078:                        agentKey = "Agent" + KEY_SEPR + name;
079:                    mjipsKey = (agentKey + KEY_SEPR + CPU_LOAD_MJIPS).intern();
080:                    addKey(mjipsKey);
081:                    loadavgKey = (agentKey + KEY_SEPR + CPU_LOAD_AVG).intern();
082:                    addKey(loadavgKey);
083:                }
084:
085:                public void newAddition(KeyMap keys,
086:                        DecayingHistory.SnapShot now_raw,
087:                        DecayingHistory.SnapShot last_raw) {
088:                    AgentLoadService.AgentLoad now = (AgentLoadService.AgentLoad) now_raw;
089:                    AgentLoadService.AgentLoad last = (AgentLoadService.AgentLoad) last_raw;
090:                    double deltaT = now.timestamp - last.timestamp;
091:                    double deltaLoad = now.loadAvgIntegrator
092:                            - last.loadAvgIntegrator;
093:                    double deltaMJips = now.loadMjipsIntegrator
094:                            - last.loadMjipsIntegrator;
095:
096:                    //Must match the Metrics Constants for CPU_LOAD_AVG_1XXX_SEC_AVG
097:                    String lKey = keys.getKey(loadavgKey);
098:                    Metric lData = new MetricImpl(
099:                            new Double(deltaLoad / deltaT), CREDIBILITY,
100:                            "threads/sec", "AgentLoadSensor");
101:                    metricsUpdateService.updateValue(lKey, lData);
102:
103:                    //Must match the Metrics Constants for CPU_LOAD_MJIPS_1XXX_SEC_AVG
104:                    String mKey = keys.getKey(mjipsKey);
105:                    Metric mData = new MetricImpl(new Double(deltaMJips
106:                            / deltaT), CREDIBILITY, "mjips", "AgentLoadSensor");
107:                    metricsUpdateService.updateValue(mKey, mData);
108:                }
109:
110:            }
111:
112:            private AgentLoadService agentLoadService;
113:            private MetricsUpdateService metricsUpdateService;
114:            private Schedulable schedulable;
115:            private Map<String, AgentLoadHistory> histories;
116:
117:            public AgentLoadRatePlugin() {
118:                histories = new HashMap<String, AgentLoadHistory>();
119:            }
120:
121:            // Local
122:            AgentLoadHistory findOrMakeHistory(String agent) {
123:                AgentLoadHistory history = histories.get(agent);
124:                if (history == null) {
125:                    history = new AgentLoadHistory(agent);
126:                    histories.put(agent, history);
127:                }
128:                return history;
129:            }
130:
131:            // Component
132:            public void load() {
133:                super .load();
134:
135:                ServiceBroker sb = getServiceBroker();
136:                agentLoadService = (AgentLoadService) sb.getService(this ,
137:                        AgentLoadService.class, null);
138:                if (agentLoadService == null) {
139:                    throw new RuntimeException(
140:                            "Can't find AgentLoadService. This plugin must be loaded at Low priority");
141:                }
142:
143:                metricsUpdateService = (MetricsUpdateService) sb.getService(
144:                        this , MetricsUpdateService.class, null);
145:
146:                ThreadService tsvc = (ThreadService) sb.getService(this ,
147:                        ThreadService.class, null);
148:                schedulable = tsvc.getThread(this , this , "AgentLoadRate");
149:                schedulable.schedule(5000, BASE_PERIOD * 1000);
150:                sb.releaseService(this , ThreadService.class, tsvc);
151:            }
152:
153:            // Schedulable body
154:            public void run() {
155:                Collection agentLoadSnapshot = agentLoadService
156:                        .snapshotRecords();
157:                boolean useItr;
158:                Iterator itr;
159:                List l;
160:                if (agentLoadSnapshot instanceof  List
161:                        && agentLoadSnapshot instanceof  RandomAccess) {
162:                    useItr = false;
163:                    itr = null;
164:                    l = (List) agentLoadSnapshot;
165:                } else {
166:                    useItr = true;
167:                    itr = agentLoadSnapshot.iterator();
168:                    l = null;
169:                }
170:                for (int i = 0, n = agentLoadSnapshot.size(); i < n; i++) {
171:                    AgentLoadService.AgentLoad record = (AgentLoadService.AgentLoad) (useItr ? itr
172:                            .next()
173:                            : l.get(i));
174:                    String agent = record.name;
175:                    AgentLoadHistory history = findOrMakeHistory(agent);
176:                    history.add(record);
177:                }
178:            }
179:
180:            // Plugin
181:            protected void setupSubscriptions() {
182:            }
183:
184:            protected void execute() {
185:            }
186:
187:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.