Source Code Cross Referenced for ScopeEventListenerImpl.java in  » Cache » OSCache » com » opensymphony » oscache » extra » 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
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Cache » OSCache » com.opensymphony.oscache.extra 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2002-2003 by OpenSymphony
003:         * All rights reserved.
004:         */
005:        package com.opensymphony.oscache.extra;
006:
007:        import com.opensymphony.oscache.base.events.ScopeEvent;
008:        import com.opensymphony.oscache.base.events.ScopeEventListener;
009:        import com.opensymphony.oscache.base.events.ScopeEventType;
010:
011:        /**
012:         * Implementation of a ScopeEventListener that keeps track of the scope flush events.
013:         * We are not using any synchronized so that this does not become a bottleneck.
014:         * The consequence is that on retrieving values, the operations that are
015:         * currently being done won't be counted.
016:         *
017:         * @version        $Revision: 254 $
018:         * @author <a href="mailto:abergevin@pyxis-tech.com">Alain Bergevin</a>
019:         */
020:        public class ScopeEventListenerImpl implements  ScopeEventListener {
021:            /**
022:             * Scope names
023:             */
024:            public static final String[] SCOPE_NAMES = { null, "page",
025:                    "request", "session", "application" };
026:
027:            /**
028:             * Number of known scopes
029:             */
030:            public static final int NB_SCOPES = SCOPE_NAMES.length - 1;
031:
032:            /**
033:             * Page scope number
034:             */
035:            public static final int PAGE_SCOPE = 1;
036:
037:            /**
038:             * Request scope number
039:             */
040:            public static final int REQUEST_SCOPE = 2;
041:
042:            /**
043:             * Session scope number
044:             */
045:            public static final int SESSION_SCOPE = 3;
046:
047:            /**
048:             * Application scope number
049:             */
050:            public static final int APPLICATION_SCOPE = 4;
051:
052:            /**
053:             * Flush counter for all scopes.
054:             * Add one to the number of scope because the array is being used
055:             * from position 1 instead of 0 for convenience
056:             */
057:            private int[] scopeFlushCount = new int[NB_SCOPES + 1];
058:
059:            public ScopeEventListenerImpl() {
060:            }
061:
062:            /**
063:             * Gets the flush count for scope {@link ScopeEventListenerImpl#APPLICATION_SCOPE}.
064:             * <p>
065:             * @return The total number of application flush
066:             */
067:            public int getApplicationScopeFlushCount() {
068:                return scopeFlushCount[APPLICATION_SCOPE];
069:            }
070:
071:            /**
072:             * Gets the flush count for scope {@link ScopeEventListenerImpl#PAGE_SCOPE}.
073:             * @return The total number of page flush
074:             */
075:            public int getPageScopeFlushCount() {
076:                return scopeFlushCount[PAGE_SCOPE];
077:            }
078:
079:            /**
080:             * Gets the flush count for scope {@link ScopeEventListenerImpl#REQUEST_SCOPE}.
081:             * @return The total number of request flush
082:             */
083:            public int getRequestScopeFlushCount() {
084:                return scopeFlushCount[REQUEST_SCOPE];
085:            }
086:
087:            /**
088:             * Gets the flush count for scope {@link ScopeEventListenerImpl#SESSION_SCOPE}.
089:             * @return The total number of session flush
090:             */
091:            public int getSessionScopeFlushCount() {
092:                return scopeFlushCount[SESSION_SCOPE];
093:            }
094:
095:            /**
096:             * Returns the total flush count.
097:             * @return The total number of scope flush
098:             */
099:            public int getTotalScopeFlushCount() {
100:                int total = 0;
101:
102:                for (int count = 1; count <= NB_SCOPES; count++) {
103:                    total += scopeFlushCount[count];
104:                }
105:
106:                return total;
107:            }
108:
109:            /**
110:             * Handles all the scope flush events.
111:             * @param event The scope event
112:             */
113:            public void scopeFlushed(ScopeEvent event) {
114:                // Get the event type and process it
115:                ScopeEventType eventType = event.getEventType();
116:
117:                if (eventType == ScopeEventType.ALL_SCOPES_FLUSHED) {
118:                    // All 4 scopes were flushed, increment the counters
119:                    for (int count = 1; count <= NB_SCOPES; count++) {
120:                        scopeFlushCount[count]++;
121:                    }
122:                } else if (eventType == ScopeEventType.SCOPE_FLUSHED) {
123:                    // Get back the scope from the event and increment the flush count
124:                    scopeFlushCount[event.getScope()]++;
125:                } else {
126:                    // Unknown event!
127:                    throw new IllegalArgumentException(
128:                            "Unknown Scope Event type received");
129:                }
130:            }
131:
132:            /**
133:             * Returns all the flush counter in a string form.
134:             */
135:            public String toString() {
136:                StringBuffer returnString = new StringBuffer("Flush count for ");
137:
138:                for (int count = 1; count <= NB_SCOPES; count++) {
139:                    returnString.append("scope " + SCOPE_NAMES[count] + " = "
140:                            + scopeFlushCount[count] + ", ");
141:                }
142:
143:                // Remove the last 2 chars, which are ", "
144:                returnString.setLength(returnString.length() - 2);
145:
146:                return returnString.toString();
147:            }
148:        }
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.