001: /**
002: * Sequoia: Database clustering technology.
003: * Copyright (C) 2002-2004 French National Institute For Research In Computer
004: * Science And Control (INRIA).
005: * Contact: sequoia@continuent.org
006: *
007: * Licensed under the Apache License, Version 2.0 (the "License");
008: * you may not use this file except in compliance with the License.
009: * You may obtain a copy of the License at
010: *
011: * http://www.apache.org/licenses/LICENSE-2.0
012: *
013: * Unless required by applicable law or agreed to in writing, software
014: * distributed under the License is distributed on an "AS IS" BASIS,
015: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016: * See the License for the specific language governing permissions and
017: * limitations under the License.
018: *
019: * Initial developer(s): Nicolas Modrzyk.
020: * Contributor(s): Emmanuel Cecchet.
021: */package org.continuent.sequoia.controller.cache.result.entries;
022:
023: import java.util.Date;
024:
025: import org.continuent.sequoia.controller.backend.result.ControllerResultSet;
026: import org.continuent.sequoia.controller.requests.SelectRequest;
027:
028: /**
029: * A <code>CacheEntry</code> that is to be recognized as Relaxed entry.
030: *
031: * @author <a href="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
032: * @author <a href="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
033: * @version 1.0
034: */
035: public class ResultCacheEntryRelaxed extends AbstractResultCacheEntry {
036: private long timeout;
037: private long deadline;
038: private boolean keepIfNotDirty;
039:
040: /**
041: * Create a new Relaxed Query Cache entry
042: *
043: * @param request Select request to cache
044: * @param result ResultSet to cache
045: * @param timeout timeout in ms for this entry
046: * @param keepIfNotDirty true if entry must be kept in cache if not dirty once
047: * timeout has expired
048: */
049: public ResultCacheEntryRelaxed(SelectRequest request,
050: ControllerResultSet result, long timeout,
051: boolean keepIfNotDirty) {
052: super (request, result);
053: this .timeout = timeout;
054: this .deadline = System.currentTimeMillis() + timeout;
055: this .keepIfNotDirty = keepIfNotDirty;
056: }
057:
058: /**
059: * @see org.continuent.sequoia.controller.cache.result.entries.AbstractResultCacheEntry#invalidate()
060: */
061: public void invalidate() {
062: state = CACHE_DIRTY;
063: }
064:
065: /**
066: * @see org.continuent.sequoia.controller.cache.result.entries.AbstractResultCacheEntry#getType()
067: */
068: public String getType() {
069: return "Relaxed";
070: }
071:
072: /**
073: * Get the expiration deadline
074: *
075: * @return the expiration deadline
076: */
077: public long getDeadline() {
078: return deadline;
079: }
080:
081: /**
082: * Set the expiration deadline
083: *
084: * @param deadline time in ms relative to current time
085: */
086: public void setDeadline(long deadline) {
087: this .deadline = deadline;
088: }
089:
090: /**
091: * Get the timeout for this entry.
092: *
093: * @return timeout in ms
094: */
095: public long getTimeout() {
096: return timeout;
097: }
098:
099: /**
100: * @see org.continuent.sequoia.controller.cache.result.entries.AbstractResultCacheEntry#toStringTable()
101: */
102: public String[] toStringTable() {
103: return new String[] { request.getUniqueKey(), getType(),
104: getState(), new Date(getDeadline()).toString(),
105: String.valueOf(getSizeOfResult()) };
106: }
107:
108: /**
109: * Should the entry must be kept in the cache if the entry is not dirty once
110: * the timeout has expired.
111: *
112: * @return true if yes
113: */
114: public boolean getKeepIfNotDirty() {
115: return keepIfNotDirty;
116: }
117:
118: }
|