KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > continuent > sequoia > controller > cache > result > entries > ResultCacheEntryRelaxed


1 /**
2  * Sequoia: Database clustering technology.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: sequoia@continuent.org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  * Initial developer(s): Nicolas Modrzyk.
20  * Contributor(s): Emmanuel Cecchet.
21  */

22
23 package org.continuent.sequoia.controller.cache.result.entries;
24
25 import java.util.Date JavaDoc;
26
27 import org.continuent.sequoia.controller.backend.result.ControllerResultSet;
28 import org.continuent.sequoia.controller.requests.SelectRequest;
29
30 /**
31  * A <code>CacheEntry</code> that is to be recognized as Relaxed entry.
32  *
33  * @author <a HREF="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
34  * @author <a HREF="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
35  * @version 1.0
36  */

37 public class ResultCacheEntryRelaxed extends AbstractResultCacheEntry
38 {
39   private long timeout;
40   private long deadline;
41   private boolean keepIfNotDirty;
42
43   /**
44    * Create a new Relaxed Query Cache entry
45    *
46    * @param request Select request to cache
47    * @param result ResultSet to cache
48    * @param timeout timeout in ms for this entry
49    * @param keepIfNotDirty true if entry must be kept in cache if not dirty once
50    * timeout has expired
51    */

52   public ResultCacheEntryRelaxed(SelectRequest request,
53       ControllerResultSet result, long timeout, boolean keepIfNotDirty)
54   {
55     super(request, result);
56     this.timeout = timeout;
57     this.deadline = System.currentTimeMillis() + timeout;
58     this.keepIfNotDirty = keepIfNotDirty;
59   }
60
61   /**
62    * @see org.continuent.sequoia.controller.cache.result.entries.AbstractResultCacheEntry#invalidate()
63    */

64   public void invalidate()
65   {
66     state = CACHE_DIRTY;
67   }
68
69   /**
70    * @see org.continuent.sequoia.controller.cache.result.entries.AbstractResultCacheEntry#getType()
71    */

72   public String JavaDoc getType()
73   {
74     return "Relaxed";
75   }
76
77   /**
78    * Get the expiration deadline
79    *
80    * @return the expiration deadline
81    */

82   public long getDeadline()
83   {
84     return deadline;
85   }
86
87   /**
88    * Set the expiration deadline
89    *
90    * @param deadline time in ms relative to current time
91    */

92   public void setDeadline(long deadline)
93   {
94     this.deadline = deadline;
95   }
96
97   /**
98    * Get the timeout for this entry.
99    *
100    * @return timeout in ms
101    */

102   public long getTimeout()
103   {
104     return timeout;
105   }
106
107   /**
108    * @see org.continuent.sequoia.controller.cache.result.entries.AbstractResultCacheEntry#toStringTable()
109    */

110   public String JavaDoc[] toStringTable()
111   {
112     return new String JavaDoc[]{request.getUniqueKey(), getType(), getState(),
113         new Date JavaDoc(getDeadline()).toString(), String.valueOf(getSizeOfResult())};
114   }
115
116   /**
117    * Should the entry must be kept in the cache if the entry is not dirty once
118    * the timeout has expired.
119    *
120    * @return true if yes
121    */

122   public boolean getKeepIfNotDirty()
123   {
124     return keepIfNotDirty;
125   }
126
127 }
Popular Tags