Source Code Cross Referenced for SysStatHandler.java in  » Science » Cougaar12_4 » org » cougaar » qos » qrs » sysstat » 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.qos.qrs.sysstat 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * <copyright>
003:         *  
004:         *  Copyright 2002-2007 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.qos.qrs.sysstat;
028:
029:        import java.lang.management.ManagementFactory;
030:        import java.lang.management.OperatingSystemMXBean;
031:        import java.lang.reflect.Method;
032:        import java.util.Map;
033:
034:        import org.cougaar.qos.qrs.Constants;
035:        import org.cougaar.qos.qrs.DataValue;
036:        import org.cougaar.qos.qrs.Logging;
037:        import org.cougaar.util.log.Logger;
038:
039:        abstract public class SysStatHandler implements  Constants {
040:            static final String PROVENANCE = "ProcessStats";
041:
042:            // As of 1.5, the various MXBeans might help with system status.
043:            // For now we only use the OS bean, and only for load-average.
044:            private static final OperatingSystemMXBean OSMXBean = ManagementFactory
045:                    .getOperatingSystemMXBean();
046:
047:            //  getSystemLoadAverage() is new in 1.6, so use reflection for now
048:            private static final Object[] NO_ARGS = {};
049:            private static Method getLoadAvg;
050:            static {
051:                try {
052:                    Class<?>[] NO_ARG_PTYPES = {};
053:                    getLoadAvg = OSMXBean.getClass().getMethod(
054:                            "getSystemLoadAverage", NO_ARG_PTYPES);
055:                } catch (Exception e) {
056:                    // ignore
057:                }
058:            }
059:
060:            abstract protected void initialize(String host, int pid);
061:
062:            abstract protected void getData(Map<String, DataValue> map);
063:
064:            protected double parseValue(String string)
065:                    throws NumberFormatException {
066:                return Double.parseDouble(string);
067:            }
068:
069:            public Double getLoadAvgFromOS() {
070:                if (getLoadAvg != null) {
071:                    Logger logger = Logging.getLogger(getClass());
072:                    logger
073:                            .info("OperatingSystemMXBean#getSystemLoadAverage() is available");
074:                    try {
075:                        return (Double) getLoadAvg.invoke(OSMXBean, NO_ARGS);
076:                    } catch (Exception e) {
077:                        logger
078:                                .error("OperatingSystemMXBean#getSystemLoadAverage() failed: "
079:                                        + e.getMessage());
080:                    }
081:                }
082:                return null;
083:            }
084:
085:            // TODO: Make more use of MXBeans!
086:
087:            public static SysStatHandler getHandler(String kind, String host,
088:                    int pid) throws NoSysStatHandler {
089:                SysStatHandler handler = null;
090:                String name = System.getProperty("os.name");
091:                if (kind.equals("Jips")) {
092:                    handler = new Jips();
093:                } else if (kind.equals("CPUCount")) {
094:                    handler = new CPUCount();
095:                } else if (name.equals("Windows NT")) {
096:                    // NT handlers
097:                    // None so far
098:                } else if (name.equals("Windows XP")) {
099:                    if (kind.equals("LoadAverage")) {
100:                        handler = new XPLoadAverage();
101:                    } else if (kind.equals("Sockets")) {
102:                        handler = new XPSockStat();
103:                    } else if (kind.equals("Memory")) {
104:                        handler = new XPMemory();
105:                    }
106:                } else if (name.equals("Mac OS X")) {
107:                    // MacOSX handlers
108:                    if (kind.equals("LoadAverage")) {
109:                        handler = new MacOSXLoadAverage();
110:                    } else if (kind.equals("ProcessStats")) {
111:                        handler = new ProcessStats();
112:                    }
113:                } else if (name.equals("Linux")) {
114:                    // Linux handlers
115:                    if (kind.equals("CPU")) {
116:                        handler = new LinuxCPUInfo();
117:                    } else if (kind.equals("Memory")) {
118:                        handler = new LinuxMemory();
119:                    } else if (kind.equals("LoadAverage")) {
120:                        handler = new LinuxLoadAverage();
121:                    } else if (kind.equals("Sockets")) {
122:                        handler = new LinuxSockStat();
123:                    } else if (kind.equals("ProcessStats")) {
124:                        handler = new ProcessStats();
125:                    }
126:                } else if (name.equals("SunOS")) {
127:                    // Solaris handlers
128:                    if (kind.equals("LoadAverage")) {
129:                        handler = new SunOSLoadAverage();
130:                    } else if (kind.equals("ProcessStats")) {
131:                        handler = new ProcessStats();
132:                    }
133:                }
134:
135:                if (handler == null) {
136:                    throw new NoSysStatHandler("No handler for " + kind
137:                            + " on platform " + name);
138:                }
139:
140:                handler.initialize(host, pid);
141:                return handler;
142:            }
143:
144:            public static class NoSysStatHandler extends Exception {
145:                NoSysStatHandler(String message) {
146:                    super(message);
147:                }
148:            }
149:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.