Source Code Cross Referenced for HttpConnectionMetricsImpl.java in  » Net » httpcomponents-core-4.0-beta1 » org » apache » http » impl » 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 » Net » httpcomponents core 4.0 beta1 » org.apache.http.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $HeadURL: https://svn.apache.org/repos/asf/httpcomponents/httpcore/tags/4.0-beta1/module-main/src/main/java/org/apache/http/impl/HttpConnectionMetricsImpl.java $
003:         * $Revision: 548031 $
004:         * $Date: 2007-06-17 13:28:38 +0200 (Sun, 17 Jun 2007) $
005:         *
006:         * ====================================================================
007:         * Licensed to the Apache Software Foundation (ASF) under one
008:         * or more contributor license agreements.  See the NOTICE file
009:         * distributed with this work for additional information
010:         * regarding copyright ownership.  The ASF licenses this file
011:         * to you under the Apache License, Version 2.0 (the
012:         * "License"); you may not use this file except in compliance
013:         * with the License.  You may obtain a copy of the License at
014:         *
015:         *   http://www.apache.org/licenses/LICENSE-2.0
016:         *
017:         * Unless required by applicable law or agreed to in writing,
018:         * software distributed under the License is distributed on an
019:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
020:         * KIND, either express or implied.  See the License for the
021:         * specific language governing permissions and limitations
022:         * under the License.
023:         * ====================================================================
024:         *
025:         * This software consists of voluntary contributions made by many
026:         * individuals on behalf of the Apache Software Foundation.  For more
027:         * information on the Apache Software Foundation, please see
028:         * <http://www.apache.org/>.
029:         *
030:         */
031:
032:        package org.apache.http.impl;
033:
034:        import java.util.HashMap;
035:        import org.apache.http.HttpConnectionMetrics;
036:        import org.apache.http.io.HttpTransportMetrics;
037:
038:        /**
039:         * Implementation of the metrics interface.
040:         */
041:        public class HttpConnectionMetricsImpl implements  HttpConnectionMetrics {
042:
043:            public static final String REQUEST_COUNT = "http.request-count";
044:            public static final String RESPONSE_COUNT = "http.response-count";
045:            public static final String SENT_BYTES_COUNT = "http.sent-bytes-count";
046:            public static final String RECEIVED_BYTES_COUNT = "http.received-bytes-count";
047:
048:            private final HttpTransportMetrics inTransportMetric;
049:            private final HttpTransportMetrics outTransportMetric;
050:            private long requestCount = 0;
051:            private long responseCount = 0;
052:
053:            /**
054:             * The cache map for all metrics values.
055:             */
056:            private HashMap metricsCache;
057:
058:            public HttpConnectionMetricsImpl(
059:                    final HttpTransportMetrics inTransportMetric,
060:                    final HttpTransportMetrics outTransportMetric) {
061:                super ();
062:                this .inTransportMetric = inTransportMetric;
063:                this .outTransportMetric = outTransportMetric;
064:            }
065:
066:            /* ------------------  Public interface method -------------------------- */
067:
068:            public long getReceivedBytesCount() {
069:                if (this .inTransportMetric != null) {
070:                    return this .inTransportMetric.getBytesTransferred();
071:                } else {
072:                    return -1;
073:                }
074:            }
075:
076:            public long getSentBytesCount() {
077:                if (this .outTransportMetric != null) {
078:                    return this .outTransportMetric.getBytesTransferred();
079:                } else {
080:                    return -1;
081:                }
082:            }
083:
084:            public long getRequestCount() {
085:                return this .requestCount;
086:            }
087:
088:            public void incrementRequestCount() {
089:                this .requestCount++;
090:            }
091:
092:            public long getResponseCount() {
093:                return this .responseCount;
094:            }
095:
096:            public void incrementResponseCount() {
097:                this .responseCount++;
098:            }
099:
100:            public Object getMetric(final String metricName) {
101:                Object value = null;
102:                if (this .metricsCache != null) {
103:                    value = this .metricsCache.get(metricName);
104:                }
105:                if (value == null) {
106:                    if (REQUEST_COUNT.equals(metricName)) {
107:                        value = new Long(requestCount);
108:                    } else if (RESPONSE_COUNT.equals(metricName)) {
109:                        value = new Long(responseCount);
110:                    } else if (RECEIVED_BYTES_COUNT.equals(metricName)) {
111:                        if (this .inTransportMetric != null) {
112:                            return new Long(this .inTransportMetric
113:                                    .getBytesTransferred());
114:                        } else {
115:                            return null;
116:                        }
117:                    } else if (SENT_BYTES_COUNT.equals(metricName)) {
118:                        if (this .outTransportMetric != null) {
119:                            return new Long(this .outTransportMetric
120:                                    .getBytesTransferred());
121:                        } else {
122:                            return null;
123:                        }
124:                    }
125:                }
126:                return value;
127:            }
128:
129:            public void setMetric(final String metricName, Object obj) {
130:                if (this .metricsCache == null) {
131:                    this .metricsCache = new HashMap();
132:                }
133:                this .metricsCache.put(metricName, obj);
134:            }
135:
136:            public void reset() {
137:                if (this .outTransportMetric != null) {
138:                    this .outTransportMetric.reset();
139:                }
140:                if (this .inTransportMetric != null) {
141:                    this .inTransportMetric.reset();
142:                }
143:                this .requestCount = 0;
144:                this .responseCount = 0;
145:                this.metricsCache = null;
146:            }
147:
148:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.