Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorUwe Stieber2012-05-15 05:25:02 +0000
committerUwe Stieber2012-05-15 05:25:02 +0000
commit5d78417ff522726cdf9994149a1c450e72daaad7 (patch)
tree61eee332a2dd975645e8e56bb859be5e395865f6 /tests
parentab0b851b8e126a2df791a64c496394213f48f473 (diff)
downloadorg.eclipse.tcf-5d78417ff522726cdf9994149a1c450e72daaad7.tar.gz
org.eclipse.tcf-5d78417ff522726cdf9994149a1c450e72daaad7.tar.xz
org.eclipse.tcf-5d78417ff522726cdf9994149a1c450e72daaad7.zip
Releng: Fix copyright header not at start of file
Diffstat (limited to 'tests')
-rw-r--r--tests/plugins/org.eclipse.tcf.debug.test/src/org/eclipse/tcf/debug/test/util/AbstractCache.java137
-rw-r--r--tests/plugins/org.eclipse.tcf.debug.test/src/org/eclipse/tcf/debug/test/util/CallbackCache.java96
2 files changed, 115 insertions, 118 deletions
diff --git a/tests/plugins/org.eclipse.tcf.debug.test/src/org/eclipse/tcf/debug/test/util/AbstractCache.java b/tests/plugins/org.eclipse.tcf.debug.test/src/org/eclipse/tcf/debug/test/util/AbstractCache.java
index 843ab035c..f24920923 100644
--- a/tests/plugins/org.eclipse.tcf.debug.test/src/org/eclipse/tcf/debug/test/util/AbstractCache.java
+++ b/tests/plugins/org.eclipse.tcf.debug.test/src/org/eclipse/tcf/debug/test/util/AbstractCache.java
@@ -1,16 +1,15 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2012 Wind River Systems, Inc. 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.tcf.debug.test.util;
-/*******************************************************************************
- * Copyright (c) 2008, 2012 Wind River Systems, Inc. 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
- *******************************************************************************/
-
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CancellationException;
@@ -29,11 +28,11 @@ import org.eclipse.tcf.protocol.Protocol;
* access to the cache state and data.
* </p>
* @since 2.2
- */
-public abstract class AbstractCache<V> implements ICache<V> {
+ */
+public abstract class AbstractCache<V> implements ICache<V> {
private static final Throwable INVALID_STATUS = new Throwable("Cache invalid"); //$NON-NLS-1$
-
+
private class RequestCanceledListener implements Callback.ICanceledListener {
public void requestCanceled(final Callback canceledRm) {
invokeInDispatchThread(new Runnable() {
@@ -44,24 +43,24 @@ public abstract class AbstractCache<V> implements ICache<V> {
}
};
- private RequestCanceledListener fRequestCanceledListener = new RequestCanceledListener();
-
- private boolean fValid;
-
+ private RequestCanceledListener fRequestCanceledListener = new RequestCanceledListener();
+
+ private boolean fValid;
+
private V fData;
private Throwable fError = INVALID_STATUS;
-
- private Object fWaitingList;
+
+ private Object fWaitingList;
/**
* Sub-classes should override this method to retrieve the cache data from
* its source. The implementation should call {@link #set(Object, IStatus)}
* to store the newly retrieved data when it arrives (or an error, if one
* occurred retrieving the data)
- *
+ *
* @param rm
* Request monitor for completion of data retrieval.
- */
+ */
abstract protected void retrieve();
protected void invokeInDispatchThread(Runnable runnable) {
@@ -71,20 +70,20 @@ public abstract class AbstractCache<V> implements ICache<V> {
Protocol.invokeLater(runnable);
}
}
-
+
/**
- * Called to cancel a retrieve request. This method is called when
+ * Called to cancel a retrieve request. This method is called when
* clients of the cache no longer need data that was requested. <br>
- * Sub-classes should cancel and clean up requests to the asynchronous
- * data source.
- *
+ * Sub-classes should cancel and clean up requests to the asynchronous
+ * data source.
+ *
* <p>
* Note: Called while holding a lock to "this". No new request will start until
- * this call returns.
- * </p>
+ * this call returns.
+ * </p>
*/
abstract protected void canceled();
-
+
public boolean isValid() {
return fValid;
}
@@ -95,15 +94,15 @@ public abstract class AbstractCache<V> implements ICache<V> {
}
return fData;
}
-
+
public Throwable getError() {
if (!isValid()) {
throw new IllegalStateException("Cache is not valid. Cache status can be read only when cache is valid."); //$NON-NLS-1$
}
return fError;
}
-
- public void update(Callback rm) {
+
+ public void update(Callback rm) {
assert Protocol.isDispatchThread();
boolean first = false;
@@ -133,12 +132,12 @@ public abstract class AbstractCache<V> implements ICache<V> {
newWaitingList[1] = rm;
fWaitingList = newWaitingList;
}
- }
+ }
rm.addCancelListener(fRequestCanceledListener);
if (first && !isValid()) {
retrieve();
}
- }
+ }
private void completeWaitingRms() {
Object waiting = null;
@@ -146,7 +145,7 @@ public abstract class AbstractCache<V> implements ICache<V> {
waiting = fWaitingList;
fWaitingList = null;
}
- if (waiting != null) {
+ if (waiting != null) {
if (waiting instanceof Callback) {
completeWaitingRm((Callback)waiting);
} else if (waiting instanceof Callback[]) {
@@ -160,18 +159,18 @@ public abstract class AbstractCache<V> implements ICache<V> {
waiting = null;
}
}
-
+
private void completeWaitingRm(Callback rm) {
if (!isValid() && fError == null) {
rm.setError(INVALID_STATUS);
} else {
rm.setError(fError);
}
-
+
rm.removeCancelListener(fRequestCanceledListener);
- rm.done();
+ rm.done();
}
-
+
private void handleCanceledRm(final Callback rm) {
boolean found = false;
@@ -203,23 +202,23 @@ public abstract class AbstractCache<V> implements ICache<V> {
rm.setError(new CancellationException());
rm.done();
}
-
+
}
/**
- * Returns true if there are no clients waiting for this cache or if the
- * clients that are waiting, have already canceled their requests.
+ * Returns true if there are no clients waiting for this cache or if the
+ * clients that are waiting, have already canceled their requests.
* <p>
* Note: Calling this method may cause the client request monitors that were
* canceled to be completed with a cancel status. If all the client request
- * monitors were canceled, this method will also cause the {@link #canceled()}
- * method to be called. Both of these side effects will only happen
+ * monitors were canceled, this method will also cause the {@link #canceled()}
+ * method to be called. Both of these side effects will only happen
* asynchronously after <code>isCanceled()</code> returns.
- * </p>
- *
- * @return <code>true</code> if all clients waiting on this cache have been
- * canceled, or if there are no clients waiting at all.
- */
+ * </p>
+ *
+ * @return <code>true</code> if all clients waiting on this cache have been
+ * canceled, or if there are no clients waiting at all.
+ */
protected boolean isCanceled() {
Object waitingList = null;
synchronized (this) {
@@ -235,7 +234,7 @@ public abstract class AbstractCache<V> implements ICache<V> {
if (waitingList instanceof Callback) {
if ( ((Callback)waitingList).isCanceled() ) {
canceledRms = new ArrayList<Callback>(1);
- canceledRms.add((Callback)waitingList);
+ canceledRms.add((Callback)waitingList);
canceled = true;
} else {
canceled = false;
@@ -259,7 +258,7 @@ public abstract class AbstractCache<V> implements ICache<V> {
assert waitingList == null;
canceled = true;
}
-
+
if (canceledRms != null) {
final List<Callback> _canceledRms = canceledRms;
Protocol.invokeLater(new Runnable() {
@@ -270,10 +269,10 @@ public abstract class AbstractCache<V> implements ICache<V> {
}
});
}
-
+
return canceled;
}
-
+
/**
* Resets the cache, setting the data to null and the status to
* INVALID_STATUS. When in the invalid state, neither the data nor the
@@ -284,18 +283,18 @@ public abstract class AbstractCache<V> implements ICache<V> {
}
/**
- * Sets data and error values into the cache, and optionally puts in valid
- * state. Note that data may be null and status may be an error status.
- * 'Valid' simply means that our data is not stale. In other words, if the
- * request to the source encounters an error, the cache object becomes valid
- * all the same. The status indicates what error was encountered.
- *
+ * Sets data and error values into the cache, and optionally puts in valid
+ * state. Note that data may be null and status may be an error status.
+ * 'Valid' simply means that our data is not stale. In other words, if the
+ * request to the source encounters an error, the cache object becomes valid
+ * all the same. The status indicates what error was encountered.
+ *
* <p>
* This method is called internally, typically in response to having
* obtained the result from the asynchronous request to the source. The
* data/status will remain valid until the cache object receives an event
* notification from the source indicating otherwise.
- *
+ *
* @param data
* The data that should be returned to any clients waiting for
* cache data and for clients requesting data until the cache is
@@ -303,20 +302,20 @@ public abstract class AbstractCache<V> implements ICache<V> {
* @param error The status that should be returned to any clients waiting for
* cache data and for clients requesting data until the cache is
* invalidated
- * @param valid Whether the cache should bet set in valid state. If false,
- * any callback waiting for data are completed but the cache
+ * @param valid Whether the cache should bet set in valid state. If false,
+ * any callback waiting for data are completed but the cache
* is moved back to invalid state.
- *
+ *
* @see #reset
- */
+ */
public void set(V data, Throwable error, boolean valid) {
assert Protocol.isDispatchThread();
-
+
fData = data;
fError = error;
fValid = valid;
-
+
completeWaitingRms();
}
-
-}
+
+}
diff --git a/tests/plugins/org.eclipse.tcf.debug.test/src/org/eclipse/tcf/debug/test/util/CallbackCache.java b/tests/plugins/org.eclipse.tcf.debug.test/src/org/eclipse/tcf/debug/test/util/CallbackCache.java
index 0d873498e..4674de93b 100644
--- a/tests/plugins/org.eclipse.tcf.debug.test/src/org/eclipse/tcf/debug/test/util/CallbackCache.java
+++ b/tests/plugins/org.eclipse.tcf.debug.test/src/org/eclipse/tcf/debug/test/util/CallbackCache.java
@@ -1,100 +1,98 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2012 Wind River Systems, Inc. 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.tcf.debug.test.util;
-/*******************************************************************************
- * Copyright (c) 2008, 2012 Wind River Systems, Inc. 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
- *******************************************************************************/
-
-
-/**
+/**
* A general purpose cache, which caches the result of a single request.
* Sub classes need to implement {@link #retrieve(DataRequestMonitor)} to fetch
- * data from the data source. Clients are responsible for calling
- * {@link #disable()} and {@link #reset()} to manage the state of the cache in
+ * data from the data source. Clients are responsible for calling
+ * {@link #disable()} and {@link #reset()} to manage the state of the cache in
* response to events from the data source.
* <p>
- * This cache requires an executor to use. The executor is used to synchronize
- * access to the cache state and data.
+ * This cache requires an executor to use. The executor is used to synchronize
+ * access to the cache state and data.
* </p>
* @since 2.2
- */
-public abstract class CallbackCache<V> extends AbstractCache<V> {
+ */
+public abstract class CallbackCache<V> extends AbstractCache<V> {
protected DataCallback<V> fRm;
@Override
protected final void retrieve() {
- // Make sure to cancel the previous rm. This may lead to the rm being
+ // Make sure to cancel the previous rm. This may lead to the rm being
// canceled twice, but that's not harmful.
if (fRm != null) {
fRm.cancel();
}
-
+
fRm = new DataCallback<V>(null) {
- @Override
+ @Override
protected void handleCompleted() {
if (this == fRm) {
fRm = null;
CallbackCache.this.handleCompleted(getData(), getError(), isCanceled());
}
- }
-
+ }
+
@Override
public boolean isCanceled() {
return super.isCanceled() || CallbackCache.this.isCanceled();
}
- };
+ };
retrieve(fRm);
- }
-
- /**
- * Sub-classes should override this method to retrieve the cache data
- * from its source.
- *
+ }
+
+ /**
+ * Sub-classes should override this method to retrieve the cache data
+ * from its source.
+ *
* @param rm Request monitor for completion of data retrieval.
- */
- protected abstract void retrieve(DataCallback<V> rm);
+ */
+ protected abstract void retrieve(DataCallback<V> rm);
protected void handleCompleted(V data, Throwable error, boolean canceled) {
// If the requestor canceled the request, then leave the
// cache as is, regardless of how the retrieval completes.
// We want the cache to stay in the invalid state so that
// it remains functional. The request may have completed
- // successfully, but using it may produce inconsistent
+ // successfully, but using it may produce inconsistent
// results.
if (!canceled) {
set(data, error, true);
}
}
-
+
@Override
protected synchronized void canceled() {
- if (fRm != null) {
- fRm.cancel();
- }
- }
+ if (fRm != null) {
+ fRm.cancel();
+ }
+ }
@Override
public void set(V data, Throwable error, boolean valid) {
- if (fRm != null) {
- fRm.cancel();
- fRm = null;
- }
+ if (fRm != null) {
+ fRm.cancel();
+ fRm = null;
+ }
super.set(data, error, valid);
}
-
+
@Override
public void reset() {
- if (fRm != null) {
- fRm.cancel();
- fRm = null;
- }
+ if (fRm != null) {
+ fRm.cancel();
+ fRm = null;
+ }
super.reset();
}
-}
+}

Back to the top