KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

39 public class ResultCacheEntryEager extends AbstractResultCacheEntry
40 {
41   private AbstractResultCache cache;
42   private long timeout;
43   private long deadline;
44
45   /**
46    * Create a new Eager Query Cache entry
47    *
48    * @param cache The query cache we belong to
49    * @param request Select request to cache
50    * @param result ResultSet to cache
51    * @param timeout The timeout to use for the deadline (0 for no timeout)
52    */

53   public ResultCacheEntryEager(AbstractResultCache cache,
54       SelectRequest request, ControllerResultSet result, long timeout)
55   {
56     super(request, result);
57     this.cache = cache;
58     if (timeout > 0)
59       this.deadline = System.currentTimeMillis() + timeout;
60     else
61       this.deadline = NO_DEADLINE;
62   }
63
64   /**
65    * @see org.continuent.sequoia.controller.cache.result.entries.AbstractResultCacheEntry#invalidate()
66    */

67   public void invalidate()
68   {
69     state = CACHE_INVALID;
70     if (cache != null)
71       cache.removeFromCache(request);
72     if (result != null)
73       result = null;
74     cache = null;
75   }
76
77   /**
78    * @see org.continuent.sequoia.controller.cache.result.entries.AbstractResultCacheEntry#getType()
79    */

80   public String JavaDoc getType()
81   {
82     return "Eager";
83   }
84
85   /**
86    * @see org.continuent.sequoia.controller.cache.result.entries.AbstractResultCacheEntry#toStringTable()
87    */

88   public String JavaDoc[] toStringTable()
89   {
90     return new String JavaDoc[]{request.getUniqueKey(), getType(), getState(),
91         new Date JavaDoc(getDeadline()).toString(), String.valueOf(getSizeOfResult())};
92   }
93
94   /**
95    * Returns the deadline value.
96    *
97    * @return Returns the deadline.
98    */

99   public long getDeadline()
100   {
101     return deadline;
102   }
103
104   /**
105    * Returns the timeout value.
106    *
107    * @return Returns the timeout.
108    */

109   public long getTimeout()
110   {
111     return timeout;
112   }
113 }
Popular Tags