Source Code Cross Referenced for MetricSnapshotPacket.java in  » Testing » PolePosition-0.20 » com » versant » core » metric » 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 » Testing » PolePosition 0.20 » com.versant.core.metric 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 1998 - 2005 Versant Corporation
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         * Versant Corporation - initial API and implementation
010:         */
011:        package com.versant.core.metric;
012:
013:        import com.versant.core.jdo.VersantPersistenceManagerFactory;
014:
015:        import java.util.Date;
016:        import java.io.Serializable;
017:        import java.io.PrintStream;
018:
019:        /**
020:         * A number of metric snapshots stored in parallel arrays (one array per metric).
021:         * 
022:         * @see VersantPersistenceManagerFactory#getMetrics()
023:         * @see com.versant.core.jdo.VersantPersistenceManagerFactory#getNewMetricSnapshots(int)
024:         */
025:        public final class MetricSnapshotPacket implements  Serializable,
026:                MetricDataSource {
027:
028:            private final Date[] dates; // date for each snapshot
029:            private final int[] ids; // unique ID for each snapshot
030:            private final int[][] buf; // the snapshot data in parallel arrays
031:
032:            public MetricSnapshotPacket(Date[] dates, int[] ids, int[][] buf) {
033:                this .dates = dates;
034:                this .ids = ids;
035:                this .buf = buf;
036:            }
037:
038:            /**
039:             * Get the number of snapshots.
040:             */
041:            public int getSize() {
042:                return ids.length;
043:            }
044:
045:            /**
046:             * Get the Date of each snapshot.
047:             */
048:            public Date[] getDates() {
049:                return dates;
050:            }
051:
052:            /**
053:             * Get the unique ID of each snapshot.
054:             */
055:            public int[] getIds() {
056:                return ids;
057:            }
058:
059:            /**
060:             * Get the snapshot data. There is one int[] per configured server metric
061:             * holding the data for all the snapshots in the packet.
062:             * @see com.versant.core.jdo.VersantPersistenceManagerFactory#getMetrics()
063:             */
064:            public int[][] getBuf() {
065:                return buf;
066:            }
067:
068:            /**
069:             * Get the ID of the most recent sample.
070:             */
071:            public int getMostRecentID() {
072:                return ids[ids.length - 1];
073:            }
074:
075:            /**
076:             * Get the Date of the most recent sample.
077:             */
078:            public Date getMostRecentDate() {
079:                return dates[dates.length - 1];
080:            }
081:
082:            /**
083:             * Get the value of sampleNo for the given metricIndex. If sampleNo is
084:             * before the first sample then return the first sample. If sampleNo is
085:             * after the last sample then return the last sample.
086:             */
087:            public int getSample(int sampleNo, int metricIndex) {
088:                if (sampleNo < 0)
089:                    sampleNo = 0;
090:                else if (sampleNo >= ids.length)
091:                    sampleNo = ids.length - 1;
092:                return buf[metricIndex][sampleNo];
093:            }
094:
095:            /**
096:             * Get the time in seconds between the two samples. The sampleNo's are
097:             * adjusted to fit in range.
098:             */
099:            public double getSeconds(int firstSampleNo, int lastSampleNo) {
100:                if (firstSampleNo < 0)
101:                    firstSampleNo = 0;
102:                if (lastSampleNo >= ids.length)
103:                    lastSampleNo = ids.length - 1;
104:                if (lastSampleNo > firstSampleNo) {
105:                    long diff = dates[lastSampleNo].getTime()
106:                            - dates[firstSampleNo].getTime();
107:                    return diff / 1000.0;
108:                } else {
109:                    return 0.0;
110:                }
111:            }
112:
113:            /**
114:             * Get the most recent sample in this packet for the metric using the
115:             * supplied calculation method. If calc < 0 then the default calculation
116:             * method for the metric is used.
117:             * @see Metric#CALC_AVERAGE
118:             * @see Metric#CALC_DELTA
119:             * @see Metric#CALC_DELTA_PER_SECOND
120:             * @see Metric#CALC_RAW
121:             */
122:            public double getMostRecentValue(Metric m, int calc) {
123:                int lastSampleNo = ids.length - 1;
124:                int firstSampleNo = lastSampleNo - 1;
125:                return m.get(this , firstSampleNo, lastSampleNo, calc < 0 ? m
126:                        .getDefaultCalc() : calc, getSeconds(firstSampleNo,
127:                        lastSampleNo));
128:            }
129:
130:            /**
131:             * Get the most recent sample in this packet for the metric using its
132:             * default calculation method.
133:             * @see #getMostRecentValue(Metric, int)
134:             */
135:            public double getMostRecentValue(Metric m) {
136:                return getMostRecentValue(m, -1);
137:            }
138:
139:            /**
140:             * Get the most recent raw int sample in this packet for the metric.
141:             * @see #getMostRecentValue(Metric, int)
142:             */
143:            public int getMostRecentSample(BaseMetric m) {
144:                return getSample(ids.length - 1, m.getIndex());
145:            }
146:
147:            /**
148:             * Dump raw sample data to out (for debugging).
149:             */
150:            public void dump(Metric[] all, int sampleNo, PrintStream out) {
151:                for (int i = 0; i < all.length; i++) {
152:                    if (all[i] instanceof  BaseMetric) {
153:                        BaseMetric m = (BaseMetric) all[i];
154:                        int mi = m.getIndex();
155:                        out.println(m + " buf[" + mi + "][" + sampleNo + "] = "
156:                                + buf[mi][sampleNo]);
157:                    }
158:                }
159:            }
160:
161:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.