KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > controller > cache > result > rules > RelaxedCaching


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2005 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Nicolas Modrzyk
22  * Contributor(s): Emmanuel Cecchet.
23  */

24
25 package org.objectweb.cjdbc.controller.cache.result.rules;
26
27 import org.objectweb.cjdbc.common.sql.SelectRequest;
28 import org.objectweb.cjdbc.common.xml.DatabasesXmlTags;
29 import org.objectweb.cjdbc.controller.cache.result.AbstractResultCache;
30 import org.objectweb.cjdbc.controller.cache.result.CacheBehavior;
31 import org.objectweb.cjdbc.controller.cache.result.entries.AbstractResultCacheEntry;
32 import org.objectweb.cjdbc.controller.cache.result.entries.ResultCacheEntryRelaxed;
33 import org.objectweb.cjdbc.controller.virtualdatabase.ControllerResultSet;
34
35 /**
36  * RelaxedCaching means we set a timeout value for this entry, and when expired
37  * we keep in the cache if no write has modified the corresponding result, we
38  * wait for the same amount of time again. RelaxedCaching may provide stale
39  * data. The timeout defines the maximum staleness of a cache entry. It means
40  * that the cache may return an entry that is out of date. timeout: is a value
41  * in seconds and 0 means no timeout (always in the cache) keepIfNotDirty: if
42  * true the entry is kept in the cache and the timeout is reset, if false, the
43  * entry is removed from the cache after the timeout has expired even if the
44  * entry was not affected by a write.
45  *
46  * @author <a HREF="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
47  * @author <a HREF="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
48  * @version 1.0
49  */

50 public class RelaxedCaching extends CacheBehavior
51 {
52   private long timeout;
53   private boolean keepIfNotDirty;
54
55   /**
56    * Create new RelaxedCaching action
57    *
58    * @param timeout before we check the validity of an entry
59    * @param keepIfNotDirty true if non-dirty entries must be kept in the cache
60    */

61   public RelaxedCaching(boolean keepIfNotDirty, long timeout)
62   {
63     this.keepIfNotDirty = keepIfNotDirty;
64     this.timeout = timeout;
65   }
66
67   /**
68    * @see org.objectweb.cjdbc.controller.cache.result.CacheBehavior#getCacheEntry(SelectRequest,
69    * ControllerResultSet, AbstractResultCache)
70    */

71   public AbstractResultCacheEntry getCacheEntry(SelectRequest sqlQuery,
72       ControllerResultSet result, AbstractResultCache cache)
73   {
74     return new ResultCacheEntryRelaxed(sqlQuery, result, timeout,
75         keepIfNotDirty);
76   }
77
78   /**
79    * @see org.objectweb.cjdbc.common.xml.XmlComponent#getXml()
80    */

81   public String JavaDoc getXml()
82   {
83     return "<" + DatabasesXmlTags.ELT_RelaxedCaching + " "
84         + DatabasesXmlTags.ATT_timeout + "=\"" + timeout / 1000 + "\" "
85         + DatabasesXmlTags.ATT_keepIfNotDirty + "=\"" + keepIfNotDirty + "\"/>";
86   }
87
88 }
Popular Tags