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