001: /*
002: * MessageService: The message service daemon
003: * Copyright (C) 2006 Rift IT Contracting
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
018: *
019: * BeanCacheEntry.java
020: */
021:
022: // package paths
023: package com.rift.coad.lib.bean;
024:
025: // java imports
026: import java.util.Date;
027:
028: // coadunation imports
029: import com.rift.coad.lib.cache.CacheEntry;
030:
031: /**
032: * The bean cache entry is responsible for
033: *
034: * @author Brett Chaldecott
035: */
036: public class BeanCacheEntry {
037: // the classes private member variables
038: private long timeout = 0;
039: private Object cacheKey = null;
040: private Object wrappedObject = null;
041: private CacheEntry cacheEntry = null;
042: private Object proxy = null;
043: private CacheEntry beanHandler = null;
044:
045: /**
046: * The constructor of the BeanCacheEntry object.
047: *
048: * @param timeout The time out value.
049: * @param cacheKey The cache key that uniqly identifies this object.
050: * @param wrapperObject The wrapper object reference.
051: * @param cacheEntry The new entry to add to the cache.
052: */
053: public BeanCacheEntry(long timeout, Object cacheKey,
054: Object wrappedObject, CacheEntry cacheEntry) {
055: this .timeout = timeout;
056: this .cacheKey = cacheKey;
057: this .wrappedObject = wrappedObject;
058: this .cacheEntry = cacheEntry;
059: }
060:
061: /**
062: * The constructor of the BeanCacheEntry object.
063: *
064: * @param timeout The time out period.
065: * @param cacheKey The cache key that uniqly identifies this object.
066: * @param proxy The proxy object.
067: * @param beanHandler The handler to perform the search for.
068: */
069: public BeanCacheEntry(long timeout, Object cacheKey,
070: Object wrappedObject, Object proxy, CacheEntry beanHandler) {
071: this .timeout = timeout;
072: this .cacheKey = cacheKey;
073: this .wrappedObject = wrappedObject;
074: this .proxy = proxy;
075: this .beanHandler = beanHandler;
076: }
077:
078: /**
079: * This method returns the cache key object.
080: *
081: * @return The cache key object.
082: */
083: public Object getCacheKey() {
084: return cacheKey;
085: }
086:
087: /**
088: * This method returns the wrapped object.
089: *
090: * @return The wrapped object.
091: */
092: public Object getWrappedObject() {
093: return wrappedObject;
094: }
095:
096: /**
097: * This method returns the cache entry that this object wrapps.
098: */
099: public CacheEntry getCacheEntry() {
100: return cacheEntry;
101: }
102:
103: /**
104: * This method sets the cache entry.
105: *
106: * @param cacheEntry The new cache entry to set.
107: */
108: public void setCacheEntry(CacheEntry cacheEntry) {
109: this .cacheEntry = cacheEntry;
110: }
111:
112: /**
113: * This methos returns the proxy object.
114: *
115: * @return The proxy object.
116: */
117: public Object getProxy() {
118: return proxy;
119: }
120:
121: /**
122: * This method sets the proxy object.
123: *
124: * @param proxy The proxy object value to set.
125: */
126: public void setProxy(Object proxy) {
127: this .proxy = proxy;
128: }
129:
130: /**
131: * This method retrieves the bean handler object.
132: *
133: * @return The bean handler reference.
134: */
135: public CacheEntry getBeanHandler() {
136: return beanHandler;
137: }
138:
139: /**
140: * This method sets the bean handler flag.
141: *
142: * @param beanHandler The bean handler to set.
143: */
144: public void setBeanHandler(CacheEntry beanHandler) {
145: this .beanHandler = beanHandler;
146: }
147:
148: /**
149: * This method sets the last touch time
150: */
151: public void touch() {
152: if (cacheEntry != null) {
153: cacheEntry.touch();
154: }
155: if (beanHandler != null) {
156: beanHandler.touch();
157: }
158: }
159:
160: /**
161: * This method returns true if this object is expired.
162: *
163: * @return TRUE if expired, FALSE if not.
164: * @param expiryDate The expiry date.
165: */
166: public boolean isExpired(Date expiryDate) {
167: Date calculatedExpiryTime = new Date(expiryDate.getTime()
168: - timeout);
169: if ((((cacheEntry != null) && (cacheEntry
170: .isExpired(calculatedExpiryTime))) || (cacheEntry == null))
171: && ((beanHandler == null) || ((beanHandler != null) && (beanHandler
172: .isExpired(calculatedExpiryTime))))) {
173: return true;
174: }
175: return false;
176: }
177:
178: /**
179: * Call the cache entries to release
180: */
181: public void cacheRelease() {
182: if (cacheEntry != null) {
183: cacheEntry.cacheRelease();
184: }
185: if (beanHandler != null) {
186: beanHandler.cacheRelease();
187: }
188: }
189: }
|