From a56f1006bda417474544e566a577a1778fba41a4 Mon Sep 17 00:00:00 2001
From: Pawel Piech
+ * Note: Called while holding a lock to "this". No new request will start until + * this call returns. + *
*/ @ThreadSafe abstract protected void canceled(); @@ -94,10 +100,16 @@ public abstract class AbstractCachenull
, and status to
- * {@link #INVALID_STATUS}. Equivalent to reset(null, INVALID_STATUS)
- *
- * @see #reset(Object, IStatus)
- */
+
+ /**
+ * Resets the cache with a data value null
and an error
+ * status with code {@link IDsfStatusConstants#INVALID_STATE}.
+ *
+ * @see #reset(Object, IStatus)
+ */
protected void reset() {
- reset(null, INVALID_STATUS);
+ if (!fValid) {
+ throw new IllegalStateException("Cache is not valid. Cache can be reset only when it's in a valid state"); //$NON-NLS-1$
+ }
+ fValid = false;
}
- /**
- * Resets the cache, setting its data to [data], and status to [status].
- * Resetting the cache puts it in the invalid state and cancels any current
- * pending requests to the data source.
- *
- * - * The cache should be reset when the data source has issued an event - * indicating that the source data has changed but data may still be - * retrieved. Clients may need to re-request data following a cache reset. - * - * @param data - * The data that should be returned to any client that calls - * {@link #getData()} despite the invalid state - * @status The status that should be returned to any client that calls - * {@link #getStatus()()} despite the invalid state - * @see #reset() - * @see #set(Object, IStatus) - */ - protected void reset(V data, IStatus status) { - doSet(data, status, false); - } - - /** - * Puts the cache into the valid state, given it new data and status. - * - * This method should be called when the subclass has received a response - * for updated data from the source. Note that such a response may be an - * error. That does not make the cache invalid. Invalid strictly means that - * the cache's data has either gone stale or that it's in the initial unset - * state. - * - * @param data - * The data that should be returned to any clients waiting for - * cache data and for clients requesting data, until the cache is - * invalidated via one of the reset methods. - * @status The status that should be returned to any clients waiting for - * cache data and for clients requesting status, until the cache is - * invalidated via one of the reset methods. - * - * @see #reset() - * @see #reset(Object, IStatus) - */ + /** + * Resets the cache then disables it. When a cache is disabled it means + * that it is valid and requests to the data source will not be sent. + *
+ * This method should be called when the data source has issued an event + * indicating that the source data has changed and future requests for + * data will return the given data and status. Once the source data + * becomes available again, clients should call {@link #reset()}. + *
+ * @param data The data that should be returned to any clients waiting for + * cache data and for clients requesting data until the cache is reset again. + * @status The status that should be returned to any clients waiting for + * cache data and for clients requesting data until the cache is reset again. + * + * @see #reset(Object, IStatus) + */ protected void set(V data, IStatus status) { - doSet(data, status, true); + assert fExecutor.getDsfExecutor().isInExecutorThread(); + + fData = data; + fStatus = status; + fValid = true; + + Object waiting = null; + synchronized(this) { + waiting = fWaitingList; + fWaitingList = null; + } + if (waiting != null) { + if (waiting instanceof RequestMonitor) { + completeWaitingRm((RequestMonitor)waiting); + } else if (waiting instanceof RequestMonitor[]) { + RequestMonitor[] waitingList = (RequestMonitor[])waiting; + for (int i = 0; i < waitingList.length; i++) { + if (waitingList[i] != null) { + completeWaitingRm(waitingList[i]); + } + } + } + waiting = null; + } } } diff --git a/dsf/org.eclipse.cdt.dsf/src/org/eclipse/cdt/dsf/concurrent/RangeCache.java b/dsf/org.eclipse.cdt.dsf/src/org/eclipse/cdt/dsf/concurrent/RangeCache.java new file mode 100644 index 00000000000..f65e1bef08f --- /dev/null +++ b/dsf/org.eclipse.cdt.dsf/src/org/eclipse/cdt/dsf/concurrent/RangeCache.java @@ -0,0 +1,286 @@ +/******************************************************************************* + * Copyright (c) 2010 Wind River Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.dsf.concurrent; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; + +/** + * Cache for retrieving ranges of elements from an asynchronous data source. + * Clients of this cache should call {@link #getRange(long, int)} to get a cache + * for that given range of elements. Sub-classes must implement {@link #retrieve(long, int, DataRequestMonitor)} + * to retrieve data from the asynchronous data source. + * @since 2.2 + */ +abstract public class RangeCachenull
if the given status
+ * parameter contains an error. In this case all requests in the given
+ * range will return the error.
+ *
+ * @param offset Offset of the given data to set to cache.
+ * @param count Count of the given data to set to cache.
+ * @param data List of elements to set to cache. Can be null
.
+ * @param status Status object to set to cache.
+ */
+ protected void set(long offset, int count, List