Source Code Cross Referenced for AbstractExpiringCache.java in  » Database-ORM » ODAL » com » completex » objective » components » ocache » 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 » Database ORM » ODAL » com.completex.objective.components.ocache.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.completex.objective.components.ocache.impl;
002:
003:        import com.completex.objective.components.ocache.OdalCache;
004:        import com.completex.objective.util.TimeInterval;
005:
006:        /**
007:         * @author Gennady Krizhevsky
008:         */
009:        public abstract class AbstractExpiringCache implements  OdalCache {
010:
011:            public static final String TIME_PATTERN = "\\d\\d:\\d\\d:\\d\\d\\.\\d\\d\\d";
012:
013:            private String cacheFlushInterval;
014:            private String entryFlushInterval;
015:            private long cacheFlushIntervalMs = Long.MAX_VALUE;
016:            private long entryFlushIntervalMs = Long.MAX_VALUE;
017:
018:            private long cacheStartTime;
019:
020:            protected AbstractExpiringCache() {
021:                resetCacheStartTime();
022:            }
023:
024:            public final synchronized Object get(Object key) {
025:                ExpiringValue value = null;
026:                if (!isExpired()) {
027:                    value = doGet(key);
028:                    if (value != null) {
029:                        if (value.isExpired()) {
030:                            remove(key);
031:                            value = null;
032:                        }
033:                    }
034:                } else {
035:                    clear();
036:                    resetCacheStartTime();
037:                }
038:                return value == null ? null : value.value;
039:            }
040:
041:            private void resetCacheStartTime() {
042:                cacheStartTime = System.currentTimeMillis();
043:            }
044:
045:            protected abstract ExpiringValue doGet(Object key);
046:
047:            public final synchronized Object put(Object key, Object value) {
048:                return doPut(key, new ExpiringValue(entryFlushIntervalMs,
049:                        System.currentTimeMillis(), value));
050:            }
051:
052:            protected abstract Object doPut(Object key, Object value);
053:
054:            public boolean isExpired() {
055:                long lifeTime = System.currentTimeMillis() - cacheStartTime;
056:                return lifeTime >= cacheFlushIntervalMs;
057:            }
058:
059:            public long getCacheFlushIntervalMs() {
060:                return cacheFlushIntervalMs;
061:            }
062:
063:            public void setCacheFlushIntervalMs(long cacheFlushIntervalMs) {
064:                this .cacheFlushIntervalMs = cacheFlushIntervalMs;
065:            }
066:
067:            public long getEntryFlushIntervalMs() {
068:                return entryFlushIntervalMs;
069:            }
070:
071:            public void setEntryFlushIntervalMs(long entryFlushIntervalMs) {
072:                this .entryFlushIntervalMs = entryFlushIntervalMs;
073:            }
074:
075:            public long getCacheStartTime() {
076:                return cacheStartTime;
077:            }
078:
079:            public void setCacheStartTime(long cacheStartTime) {
080:                this .cacheStartTime = cacheStartTime;
081:            }
082:
083:            /**
084:             * Returns Cache Flush Interval in format: HH:mm:ss.SSS following standard
085:             * Java Date and Time Patterns (see Java API)
086:             *
087:             * @return Cache Flush Interval in format: HH:mm:ss.SSS following standard
088:             *         Java Date and Time Patterns (see Java API)
089:             */
090:            public String getCacheFlushInterval() {
091:                return cacheFlushInterval;
092:            }
093:
094:            /**
095:             * Sets Cache Flush Interval in format: HH:mm:ss.SSS following standard
096:             * Java Date and Time Patterns (see Java API)
097:             *
098:             * @param cacheFlushInterval
099:             */
100:            public void setCacheFlushInterval(String cacheFlushInterval) {
101:                this .cacheFlushInterval = cacheFlushInterval;
102:                TimeInterval timeInterval = new TimeInterval(
103:                        cacheFlushInterval, "cacheFlushInterval");
104:                this .cacheFlushIntervalMs = timeInterval.getIntervalMs();
105:            }
106:
107:            /**
108:             * Returns Cache Entry Flush Interval in format: HH:mm:ss.SSS following standard
109:             * Java Date and Time Patterns (see Java API)
110:             *
111:             * @return Cache Entry Flush Interval in format: HH:mm:ss.SSS following standard
112:             *         Java Date and Time Patterns (see Java API)
113:             */
114:            public String getEntryFlushInterval() {
115:                return entryFlushInterval;
116:            }
117:
118:            /**
119:             * Sets Cache Entry Flush Interval in format: HH:mm:ss.SSS following standard
120:             * Java Date and Time Patterns (see Java API)
121:             *
122:             * @param entryFlushInterval cache entry flush interval
123:             */
124:            public void setEntryFlushInterval(String entryFlushInterval) {
125:                this .entryFlushInterval = entryFlushInterval;
126:                TimeInterval timeInterval = new TimeInterval(
127:                        entryFlushInterval, "entryFlushInterval");
128:                this .entryFlushIntervalMs = timeInterval.getIntervalMs();
129:            }
130:
131:            /**
132:             * 
133:             */
134:            public static class ExpiringValue {
135:                private long entryLifeSpan;
136:                private long startTime;
137:                private Object value;
138:
139:                public ExpiringValue(long entryLifeSpan, long startTime,
140:                        Object value) {
141:                    this .entryLifeSpan = entryLifeSpan;
142:                    this .startTime = startTime;
143:                    this .value = value;
144:                }
145:
146:                public long getStartTime() {
147:                    return startTime;
148:                }
149:
150:                public Object getValue() {
151:                    return value;
152:                }
153:
154:                public boolean isExpired() {
155:                    long lifeTime = System.currentTimeMillis() - startTime;
156:                    return lifeTime >= entryLifeSpan;
157:                }
158:            }
159:
160:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.