KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > rift > coad > lib > bean > BeanCacheEntry


1 /*
2  * MessageService: The message service daemon
3  * Copyright (C) 2006 Rift IT Contracting
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * BeanCacheEntry.java
20  */

21
22 // package paths
23
package com.rift.coad.lib.bean;
24
25 // java imports
26
import java.util.Date JavaDoc;
27
28 // coadunation imports
29
import com.rift.coad.lib.cache.CacheEntry;
30
31 /**
32  * The bean cache entry is responsible for
33  *
34  * @author Brett Chaldecott
35  */

36 public class BeanCacheEntry {
37     // the classes private member variables
38
private long timeout = 0;
39     private Object JavaDoc cacheKey = null;
40     private Object JavaDoc wrappedObject = null;
41     private CacheEntry cacheEntry = null;
42     private Object JavaDoc proxy = null;
43     private CacheEntry beanHandler = null;
44     
45     
46     /**
47      * The constructor of the BeanCacheEntry object.
48      *
49      * @param timeout The time out value.
50      * @param cacheKey The cache key that uniqly identifies this object.
51      * @param wrapperObject The wrapper object reference.
52      * @param cacheEntry The new entry to add to the cache.
53      */

54     public BeanCacheEntry(long timeout, Object JavaDoc cacheKey, Object JavaDoc wrappedObject,
55             CacheEntry cacheEntry) {
56         this.timeout = timeout;
57         this.cacheKey = cacheKey;
58         this.wrappedObject = wrappedObject;
59         this.cacheEntry = cacheEntry;
60     }
61     
62     
63     /**
64      * The constructor of the BeanCacheEntry object.
65      *
66      * @param timeout The time out period.
67      * @param cacheKey The cache key that uniqly identifies this object.
68      * @param proxy The proxy object.
69      * @param beanHandler The handler to perform the search for.
70      */

71     public BeanCacheEntry(long timeout,Object JavaDoc cacheKey, Object JavaDoc wrappedObject,
72             Object JavaDoc proxy, CacheEntry beanHandler) {
73         this.timeout = timeout;
74         this.cacheKey = cacheKey;
75         this.wrappedObject = wrappedObject;
76         this.proxy = proxy;
77         this.beanHandler = beanHandler;
78     }
79     
80     
81     /**
82      * This method returns the cache key object.
83      *
84      * @return The cache key object.
85      */

86     public Object JavaDoc getCacheKey() {
87         return cacheKey;
88     }
89     
90     
91     /**
92      * This method returns the wrapped object.
93      *
94      * @return The wrapped object.
95      */

96     public Object JavaDoc getWrappedObject() {
97         return wrappedObject;
98     }
99     
100     
101     /**
102      * This method returns the cache entry that this object wrapps.
103      */

104     public CacheEntry getCacheEntry() {
105         return cacheEntry;
106     }
107     
108     
109     /**
110      * This method sets the cache entry.
111      *
112      * @param cacheEntry The new cache entry to set.
113      */

114     public void setCacheEntry(CacheEntry cacheEntry) {
115         this.cacheEntry = cacheEntry;
116     }
117     
118     
119     /**
120      * This methos returns the proxy object.
121      *
122      * @return The proxy object.
123      */

124     public Object JavaDoc getProxy() {
125         return proxy;
126     }
127     
128     
129     /**
130      * This method sets the proxy object.
131      *
132      * @param proxy The proxy object value to set.
133      */

134     public void setProxy(Object JavaDoc proxy) {
135         this.proxy = proxy;
136     }
137     
138     
139     /**
140      * This method retrieves the bean handler object.
141      *
142      * @return The bean handler reference.
143      */

144     public CacheEntry getBeanHandler() {
145         return beanHandler;
146     }
147     
148     
149     /**
150      * This method sets the bean handler flag.
151      *
152      * @param beanHandler The bean handler to set.
153      */

154     public void setBeanHandler(CacheEntry beanHandler) {
155         this.beanHandler = beanHandler;
156     }
157     
158     
159     /**
160      * This method sets the last touch time
161      */

162     public void touch() {
163         if (cacheEntry != null){
164             cacheEntry.touch();
165         }
166         if (beanHandler != null) {
167             beanHandler.touch();
168         }
169     }
170     
171     
172     /**
173      * This method returns true if this object is expired.
174      *
175      * @return TRUE if expired, FALSE if not.
176      * @param expiryDate The expiry date.
177      */

178     public boolean isExpired(Date JavaDoc expiryDate) {
179         Date JavaDoc calculatedExpiryTime = new Date JavaDoc(expiryDate.getTime() - timeout);
180         if ((((cacheEntry != null) &&
181                 (cacheEntry.isExpired(calculatedExpiryTime))) ||
182                 (cacheEntry == null)) && ( (beanHandler == null) ||
183                 ((beanHandler != null) &&
184                 (beanHandler.isExpired(calculatedExpiryTime))) ) ) {
185             return true;
186         }
187         return false;
188     }
189     
190     
191     /**
192      * Call the cache entries to release
193      */

194     public void cacheRelease() {
195         if (cacheEntry != null){
196             cacheEntry.cacheRelease();
197         }
198         if (beanHandler != null) {
199             beanHandler.cacheRelease();
200         }
201     }
202 }
203
Popular Tags