summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorScott Lewis2013-02-14 15:43:39 (EST)
committer Thomas Watson2013-02-14 16:14:11 (EST)
commitce9a763c246cc24ea504a41a1af624229a385c20 (patch)
treea100a773429535e5f2dfc5fa033abe4a3f73c892
parent850a150c8312b8695f6f2643c46342f91f4c9bf4 (diff)
downloadrt.equinox.bundles-ce9a763c246cc24ea504a41a1af624229a385c20.zip
rt.equinox.bundles-ce9a763c246cc24ea504a41a1af624229a385c20.tar.gz
rt.equinox.bundles-ce9a763c246cc24ea504a41a1af624229a385c20.tar.bz2
Bug 309247 - graduate org.eclipse.equinox.concurrent.future APIv20130214-211411I20130214-2011
-rw-r--r--bundles/org.eclipse.equinox.concurrent/.classpath2
-rw-r--r--bundles/org.eclipse.equinox.concurrent/.settings/org.eclipse.jdt.core.prefs16
-rw-r--r--bundles/org.eclipse.equinox.concurrent/META-INF/MANIFEST.MF7
-rw-r--r--bundles/org.eclipse.equinox.concurrent/build.properties4
-rw-r--r--bundles/org.eclipse.equinox.concurrent/pom.xml2
-rw-r--r--bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/AbstractExecutor.java40
-rw-r--r--bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/AbstractFuture.java34
-rw-r--r--bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/AbstractListenableFuture.java22
-rw-r--r--bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/FutureProgressMonitor.java42
-rw-r--r--bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/IExecutor.java77
-rw-r--r--bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/IFuture.java135
-rw-r--r--bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/IListenableFuture.java47
-rw-r--r--bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/IProgressRunnable.java32
-rw-r--r--bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/IRunnableExecutor.java25
-rw-r--r--bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/ISafeProgressRunner.java26
-rw-r--r--bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/ImmediateExecutor.java46
-rw-r--r--bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/SingleOperationFuture.java85
-rw-r--r--bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/SingleOperationListenableFuture.java98
-rw-r--r--bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/ThreadsExecutor.java77
-rw-r--r--bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/TimeoutException.java18
20 files changed, 562 insertions, 273 deletions
diff --git a/bundles/org.eclipse.equinox.concurrent/.classpath b/bundles/org.eclipse.equinox.concurrent/.classpath
index c2ce266..64c5e31 100644
--- a/bundles/org.eclipse.equinox.concurrent/.classpath
+++ b/bundles/org.eclipse.equinox.concurrent/.classpath
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/CDC-1.0%Foundation-1.0"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
diff --git a/bundles/org.eclipse.equinox.concurrent/.settings/org.eclipse.jdt.core.prefs b/bundles/org.eclipse.equinox.concurrent/.settings/org.eclipse.jdt.core.prefs
index b20e547..416f4fb 100644
--- a/bundles/org.eclipse.equinox.concurrent/.settings/org.eclipse.jdt.core.prefs
+++ b/bundles/org.eclipse.equinox.concurrent/.settings/org.eclipse.jdt.core.prefs
@@ -1,7 +1,11 @@
-#Fri Jan 23 14:28:15 CST 2009
eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.1
-org.eclipse.jdt.core.compiler.compliance=1.3
-org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
-org.eclipse.jdt.core.compiler.source=1.3
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/bundles/org.eclipse.equinox.concurrent/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.concurrent/META-INF/MANIFEST.MF
index 84a05b4..d706013 100644
--- a/bundles/org.eclipse.equinox.concurrent/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.concurrent/META-INF/MANIFEST.MF
@@ -2,13 +2,12 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.equinox.concurrent
-Bundle-Version: 1.0.300.qualifier
+Bundle-Version: 1.1.0.qualifier
Bundle-Vendor: %pluginProvider
-Bundle-RequiredExecutionEnvironment: CDC-1.0/Foundation-1.0,
- J2SE-1.3
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
Import-Package: org.eclipse.core.runtime;version="3.4.0";common=split,
org.osgi.framework;version="1.3.0",
org.osgi.util.tracker
Bundle-ActivationPolicy: lazy
Bundle-Localization: plugin
-Export-Package: org.eclipse.equinox.concurrent.future;version="1.0";x-internal:="true"
+Export-Package: org.eclipse.equinox.concurrent.future;version="1.1.0"
diff --git a/bundles/org.eclipse.equinox.concurrent/build.properties b/bundles/org.eclipse.equinox.concurrent/build.properties
index 52632e2..b6e9470 100644
--- a/bundles/org.eclipse.equinox.concurrent/build.properties
+++ b/bundles/org.eclipse.equinox.concurrent/build.properties
@@ -12,6 +12,4 @@ bin.includes = META-INF/,\
.,\
plugin.properties,\
about.html
-src.includes = plugin.properties,\
- about.html,\
- META-INF/
+src.includes = about.html
diff --git a/bundles/org.eclipse.equinox.concurrent/pom.xml b/bundles/org.eclipse.equinox.concurrent/pom.xml
index 652fc21..ff2ce7f 100644
--- a/bundles/org.eclipse.equinox.concurrent/pom.xml
+++ b/bundles/org.eclipse.equinox.concurrent/pom.xml
@@ -21,6 +21,6 @@
</parent>
<groupId>org.eclipse.equinox.bundles</groupId>
<artifactId>org.eclipse.equinox.concurrent</artifactId>
- <version>1.0.300-SNAPSHOT</version>
+ <version>1.1.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
diff --git a/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/AbstractExecutor.java b/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/AbstractExecutor.java
index c270d92..480b42c 100644
--- a/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/AbstractExecutor.java
+++ b/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/AbstractExecutor.java
@@ -1,24 +1,26 @@
/******************************************************************************
-* Copyright (c) 2009 EclipseSource 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:
-* EclipseSource - initial API and implementation
-******************************************************************************/
+ * Copyright (c) 2010, 2013 EclipseSource 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:
+ * EclipseSource - initial API and implementation
+ * Gunnar Wagenknecht - added support for generics
+ ******************************************************************************/
package org.eclipse.equinox.concurrent.future;
import org.eclipse.core.runtime.IProgressMonitor;
/**
* Abstract implementation of {@link IExecutor} and {@link IRunnableExecutor}.
- *
+ * @since 1.1
+ *
*/
public abstract class AbstractExecutor implements IRunnableExecutor, IExecutor {
public void execute(final Runnable runnable) {
- execute(new IProgressRunnable() {
+ execute(new IProgressRunnable<Object>() {
public Object run(IProgressMonitor monitor) throws Exception {
runnable.run();
return null;
@@ -26,15 +28,21 @@ public abstract class AbstractExecutor implements IRunnableExecutor, IExecutor {
}, null);
}
- public abstract IFuture execute(IProgressRunnable runnable, IProgressMonitor monitor);
+ public abstract <ResultType> IFuture<ResultType> execute(
+ IProgressRunnable<? extends ResultType> runnable,
+ IProgressMonitor monitor);
/**
- * Create an {@link AbstractFuture} instance. Subclasses must override to define
- * the concrete type of future to return from {@link #execute(IProgressRunnable, IProgressMonitor)}.
- * @param progressMonitor any progress monitor to provide to the future upon construction. May be
- * <code>null</code>.
+ * Create an {@link AbstractFuture} instance. Subclasses must override to
+ * define the concrete type of future to return from
+ * {@link #execute(IProgressRunnable, IProgressMonitor)}.
+ *
+ * @param progressMonitor
+ * any progress monitor to provide to the future upon
+ * construction. May be <code>null</code>.
* @return the created future
*/
- protected abstract AbstractFuture createFuture(IProgressMonitor progressMonitor);
+ protected abstract AbstractFuture<?> createFuture(
+ IProgressMonitor progressMonitor);
}
diff --git a/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/AbstractFuture.java b/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/AbstractFuture.java
index f2d4237..1053fbe 100644
--- a/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/AbstractFuture.java
+++ b/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/AbstractFuture.java
@@ -1,32 +1,36 @@
/******************************************************************************
-* Copyright (c) 2009 EclipseSource 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:
-* EclipseSource - initial API and implementation
-******************************************************************************/
+ * Copyright (c) 2010, 2013 EclipseSource 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:
+ * EclipseSource - initial API and implementation
+ * Gunnar Wagenknecht - added support for generics
+ ******************************************************************************/
package org.eclipse.equinox.concurrent.future;
import org.eclipse.core.runtime.IProgressMonitor;
/**
* Abstract implementation of {@link IFuture} and {@link ISafeProgressRunner}.
- *
+ * @since 1.1
*/
-public abstract class AbstractFuture implements IFuture, ISafeProgressRunner {
+public abstract class AbstractFuture<ResultType> implements
+ IFuture<ResultType>, ISafeProgressRunner {
/**
- * Returns <code>true</code> if this future has been previously canceled, <code>false</code>
- * otherwise. Subclasses must override.
- * @return <code>true</code> if this future has been previously canceled, <code>false</code>
- * otherwise
+ * Returns <code>true</code> if this future has been previously canceled,
+ * <code>false</code> otherwise. Subclasses must override.
+ *
+ * @return <code>true</code> if this future has been previously canceled,
+ * <code>false</code> otherwise
*/
public abstract boolean isCanceled();
/**
- * Return a progress monitor for this future. Subclasses must override.
+ * Return a progress monitor for this future. Subclasses must override.
+ *
* @return the progress monitor for this future.
*/
public abstract IProgressMonitor getProgressMonitor();
diff --git a/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/AbstractListenableFuture.java b/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/AbstractListenableFuture.java
new file mode 100644
index 0000000..7ef28b9
--- /dev/null
+++ b/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/AbstractListenableFuture.java
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Copyright (c) 2010, 2013 Composent, 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:
+ * Composent, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.equinox.concurrent.future;
+
+/**
+ * @since 1.1
+ */
+@SuppressWarnings("rawtypes")
+public abstract class AbstractListenableFuture extends AbstractFuture implements
+ IListenableFuture {
+
+ public abstract void addListener(IProgressRunnable progressRunnable,
+ IExecutor executor);
+
+}
diff --git a/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/FutureProgressMonitor.java b/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/FutureProgressMonitor.java
index c1f0f30..4343625 100644
--- a/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/FutureProgressMonitor.java
+++ b/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/FutureProgressMonitor.java
@@ -1,23 +1,24 @@
/******************************************************************************
-* Copyright (c) 2009 EclipseSource 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:
-* EclipseSource - initial API and implementation
-******************************************************************************/
+ * Copyright (c) 2009, 2013 EclipseSource 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:
+ * EclipseSource - initial API and implementation
+ ******************************************************************************/
package org.eclipse.equinox.concurrent.future;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.ProgressMonitorWrapper;
/**
- * Progress Monitor for use with future. This progress monitor provides a wrapper
- * for potentially two progress monitors: one provided by the {@link IFuture}
- * client in a method call, the other (a child progress monitor) provided by the
- * IExecutor that creates the future instance.
- *
+ * Progress Monitor for use with future. This progress monitor provides a
+ * wrapper for potentially two progress monitors: one provided by the
+ * {@link IFuture} client in a method call, the other (a child progress monitor)
+ * provided by the IExecutor that creates the future instance.
+ * @since 1.1
+ *
*/
public class FutureProgressMonitor extends ProgressMonitorWrapper {
@@ -25,9 +26,12 @@ public class FutureProgressMonitor extends ProgressMonitorWrapper {
private Object lock = new Object();
/**
- * Create a new progress monitor wrappering the given monitor. The nested
+ * Create a new progress monitor wrapping the given monitor. The nested
* monitor is the one exposed to clients of futures.
- * @param progressMonitor the client-facing monitor used with a future. May be <code>null</code>.
+ *
+ * @param progressMonitor
+ * the client-facing monitor used with a future. May be
+ * <code>null</code>.
*
* @see #setChildProgressMonitor(IProgressMonitor)
*/
@@ -94,9 +98,11 @@ public class FutureProgressMonitor extends ProgressMonitorWrapper {
/**
* Set the client-facing progress monitor to the given value.
*
- * @param value a second (child) monitor to report progress/take cancelation from.
- * If the parent progress monitor has been previously canceled, the child progress monitor's
- * setCanceled method will be called.
+ * @param value
+ * a second (child) monitor to report progress/take cancelation
+ * from. If the parent progress monitor has been previously
+ * canceled, the child progress monitor's setCanceled method will
+ * be called.
*/
public void setChildProgressMonitor(IProgressMonitor value) {
synchronized (lock) {
diff --git a/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/IExecutor.java b/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/IExecutor.java
index 3d3dc68..7aa2123 100644
--- a/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/IExecutor.java
+++ b/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/IExecutor.java
@@ -1,56 +1,75 @@
/******************************************************************************
-* Copyright (c) 2009 EclipseSource 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:
-* EclipseSource - initial API and implementation
-******************************************************************************/
+ * Copyright (c) 2010, 2013 EclipseSource 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:
+ * EclipseSource - initial API and implementation
+ * Gunnar Wagenknecht - added support for generics
+ ******************************************************************************/
package org.eclipse.equinox.concurrent.future;
import org.eclipse.core.runtime.IProgressMonitor;
/**
* <p>
- * Contract for the actual execution of {@link IProgressRunnable}s. Instances of
- * this interface must be able to provide resources to eventually execute a given
- * {@link IProgressRunnable}, upon calling {@link #execute(IProgressRunnable, IProgressMonitor)}.
+ * Contract for the actual execution of {@link IProgressRunnable}s. Instances of
+ * this interface must be able to provide resources to eventually execute a
+ * given {@link IProgressRunnable}, upon calling
+ * {@link #execute(IProgressRunnable, IProgressMonitor)}.
* </p>
* <p>
- * Note that implementations may decide what/how to execute the given IProgressRunnable (i.e.
- * via a {@link Thread}, or a Job, or a ThreadPool or some other invocation mechanism.
- * But the intended contract of {@link #execute(IProgressRunnable, IProgressMonitor)} is that
- * the {@link IProgressRunnable#run(IProgressMonitor)} method will be invoked by
+ * Note that implementations may decide what/how to execute the given
+ * IProgressRunnable (i.e. via a {@link Thread}, or a Job, or a ThreadPool or
+ * some other invocation mechanism. But the intended contract of
+ * {@link #execute(IProgressRunnable, IProgressMonitor)} is that the
+ * {@link IProgressRunnable#run(IProgressMonitor)} method will be invoked by
* this executor in a timely manner <b>without</b> blocking.
* </p>
*
* @see IProgressRunnable
* @see IFuture
* @see #execute(IProgressRunnable, IProgressMonitor)
+ * @since 1.1
*/
public interface IExecutor {
/**
* <p>
- * Execute the given {@link IProgressRunnable} (i.e. call {@link IProgressRunnable#run(IProgressMonitor)}.
- * Will return a non-<code>null</code> instance of {@link IFuture} that allows
- * clients to inspect the state of the execution and retrieve any results via {@link IFuture#get()}
- * or {@link IFuture#get(long)}.
+ * Execute the given {@link IProgressRunnable} (i.e. call
+ * {@link IProgressRunnable#run(IProgressMonitor)}. Will return a non-
+ * <code>null</code> instance of {@link IFuture} that allows clients to
+ * inspect the state of the execution and retrieve any results via
+ * {@link IFuture#get()} or {@link IFuture#get(long)}.
* </p>
* <p>
- * Note that implementers may decide whether to invoke {@link IProgressRunnable#run(IProgressMonitor)}
- * asynchronously or synchronously, but since IProgressRunnables are frequently going to be longer-running
- * operations, implementers should proceed carefully before implementing with synchronous (blocking)
- * invocation. Implementers should typically implement via some non-blocking asynchronous invocation
+ * Note that implementers may decide whether to invoke
+ * {@link IProgressRunnable#run(IProgressMonitor)} asynchronously or
+ * synchronously, but since IProgressRunnables are frequently going to be
+ * longer-running operations, implementers should proceed carefully before
+ * implementing with synchronous (blocking) invocation. Implementers should
+ * typically implement via some non-blocking asynchronous invocation
* mechanism, e.g. Threads, Jobs, ThreadPools etc.
* </p>
- * @param runnable the {@link IProgressRunnable} to invoke. Must not be <code>null</code>.
- * @param monitor any {@link IProgressMonitor} to be passed to the runnable. May be <code>null</code>.
- * @return {@link IFuture} to allow for inspection of the state of the computation by clients,
- * as well as access to any return values of {@link IProgressRunnable#run(IProgressMonitor)}. Will not
- * be <code>null</code>.
+ *
+ * @param runnable
+ * the {@link IProgressRunnable} to invoke. Must not be
+ * <code>null</code>.
+ * @param monitor
+ * any {@link IProgressMonitor} to be passed to the runnable. May
+ * be <code>null</code>.
+ * @return {@link IFuture} to allow for inspection of the state of the
+ * computation by clients, as well as access to any return values of
+ * {@link IProgressRunnable#run(IProgressMonitor)}. Will not be
+ * <code>null</code>.
+ * @param <ResultType>
+ * the type that will be returned by the
+ * {@link IProgressRunnable} as well as the returned
+ * {@link IFuture}
*/
- IFuture execute(IProgressRunnable runnable, IProgressMonitor monitor);
+ <ResultType> IFuture<ResultType> execute(
+ IProgressRunnable<? extends ResultType> runnable,
+ IProgressMonitor monitor);
}
diff --git a/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/IFuture.java b/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/IFuture.java
index 30e6121..8f6ab20 100644
--- a/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/IFuture.java
+++ b/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/IFuture.java
@@ -1,104 +1,119 @@
/*******************************************************************************
-* Copyright (c) 2009 EclipseSource 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:
-* EclipseSource - initial API and implementation
-******************************************************************************/
+ * Copyright (c) 2010, 2013 EclipseSource 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:
+ * EclipseSource - initial API and implementation
+ * Gunnar Wagenknecht - added support for generics
+ ******************************************************************************/
package org.eclipse.equinox.concurrent.future;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.OperationCanceledException;
-
/**
* <p>
* A future represents the future outcome of some operation(s).
* </p>
* <p>
- * The expected usage of a future is as a return value from some operation
- * that is to be executed asynchronously and then return some result.
+ * The expected usage of a future is as a return value from some operation that
+ * is to be executed asynchronously and then return some result.
* </p>
* <p>
* So, for example, a simple usage of an IFuture would be:
+ *
* <pre>
* IFuture future = foo();
* ...
* Object result = future.get();
* </pre>
- * Clients generally will hold onto the future for some amount of time, and then call
- * {@link #get()} or {@link #get(long)} to retrieve the result of the operation. They
- * may also call {@link #hasValue()} to determine whether any values have been provided
- * to the future (if <code>true</code>, meaning that subsequent calls to
- * {@link #get()} will not block), or {@link #isDone()} to determine if <b>all</b>
- * operations and results have been completed.
+ *
+ * Clients generally will hold onto the future for some amount of time, and then
+ * call {@link #get()} or {@link #get(long)} to retrieve the result of the
+ * operation. They may also call {@link #hasValue()} to determine whether any
+ * values have been provided to the future (if <code>true</code>, meaning that
+ * subsequent calls to {@link #get()} will not block), or {@link #isDone()} to
+ * determine if <b>all</b> operations and results have been completed.
* </p>
* <p>
* If {@link #hasValue()} is true, then the client may access status information
- * associated with the completed operation(s) via {@link #getStatus()}. Until {@link #hasValue()}
- * is <code>true</code>, {@link #getStatus()} will be <code>null</code>.
+ * associated with the completed operation(s) via {@link #getStatus()}. Until
+ * {@link #hasValue()} is <code>true</code>, {@link #getStatus()} will be
+ * <code>null</code>.
* </p>
*
* @see IStatus
+ * @param <ResultType>
+ * the type that will be returned by {@link #get()} and/or
+ * {@link #get(long)}
+ * @since 1.1
*
*/
-public interface IFuture {
+public interface IFuture<ResultType> {
/**
* Cancel the operation
- * @return <tt>false</tt> if the operation could not be canceled,
- * typically because it has already completed normally;
- * <tt>true</tt> otherwise
+ *
+ * @return <tt>false</tt> if the operation could not be canceled, typically
+ * because it has already completed normally; <tt>true</tt>
+ * otherwise
*/
public boolean cancel();
/**
- * Waits if necessary for one or more operations to complete, and then returns result(s).
- * This method will block until either a) at least one result is available; or b) at
- * least one operation throws an exception.
+ * Waits if necessary for one or more operations to complete, and then
+ * returns result(s). This method will block until either a) at least one
+ * result is available; or b) at least one operation throws an exception.
*
* @return Object result of the asynchronous operation(s)
* @throws InterruptedException
* if thread calling this method is interrupted.
* @throws OperationCanceledException
- * if the operation has been canceled via progress monitor {@link #getProgressMonitor()}.
+ * if the operation has been canceled via progress monitor
+ * {@link #getProgressMonitor()}.
*/
- Object get() throws InterruptedException, OperationCanceledException;
+ ResultType get() throws InterruptedException, OperationCanceledException;
/**
- * Waits if necessary for one or more operations to complete, and then returns result(s).
- * This method will block until either a) at least one result is available; or b) at
- * least one operation throws an exception.
+ * Waits if necessary for one or more operations to complete, and then
+ * returns result(s). This method will block until either a) at least one
+ * result is available; or b) at least one operation throws an exception.
*
* @param waitTimeInMillis
- * the maximum time to wait in milliseconds for the operation(s) to complete.
+ * the maximum time to wait in milliseconds for the operation(s)
+ * to complete.
* @return Object result of the asynchronous operation(s)
* @throws InterruptedException
* if thread calling this method is interrupted.
* @throws TimeoutException
* if the given wait time is exceeded without getting result.
* @throws OperationCanceledException
- * if the operation has been canceled via progress monitor {@link #getProgressMonitor()}.
+ * if the operation has been canceled via progress monitor
+ * {@link #getProgressMonitor()}.
*/
- Object get(long waitTimeInMillis) throws InterruptedException, TimeoutException, OperationCanceledException;
+ ResultType get(long waitTimeInMillis) throws InterruptedException,
+ TimeoutException, OperationCanceledException;
/**
* <p>
- * Get status for operation. Will return <code>null</code> until at least one operation(s) are
- * complete.
+ * Get status for operation. Will return <code>null</code> until at least
+ * one operation(s) are complete.
* </p>
* <p>
- * If {@link #hasValue()} returns <code>true</code>, this method will return a non-<code>null</code>
- * IStatus. If {@link #hasValue()} returns <code>false</code>, this method will return <code>null</code>.
+ * If {@link #hasValue()} returns <code>true</code>, this method will return
+ * a non-<code>null</code> IStatus. If {@link #hasValue()} returns
+ * <code>false</code>, this method will return <code>null</code>.
* </p>
* <p>
- * Note that the returned IStatus instance may be an IMultiStatus, meaning that multiple operations have
- * completed or are pending completion.
+ * Note that the returned IStatus instance may be an IMultiStatus, meaning
+ * that multiple operations have completed or are pending completion.
* </p>
- * @return IStatus the status of completed operation(s). Will return <code>null</code> if {@link #hasValue()}
- * returns <code>false</code>.
+ *
+ * @return IStatus the status of completed operation(s). Will return
+ * <code>null</code> if {@link #hasValue()} returns
+ * <code>false</code>.
*
* @see #hasValue()
*/
@@ -106,39 +121,43 @@ public interface IFuture {
/**
* <p>
- * Returns <tt>true</tt> if <b>any</b> underlying operation(s) have completed.
+ * Returns <tt>true</tt> if <b>any</b> underlying operation(s) have
+ * completed.
* </p>
* <p>
* If this future represents access to just one operation, then this method
- * and {@link #isDone()} will always return the same value. That is, when a single
- * operation has a value, it is then considered done/completed and both
- * {@link #isDone()} and this method will return <code>true</code>.
+ * and {@link #isDone()} will always return the same value. That is, when a
+ * single operation has a value, it is then considered done/completed and
+ * both {@link #isDone()} and this method will return <code>true</code>.
* </p>
* <p>
- * If this future represents multiple operations, then this method will
- * return <code>true</code> when <b>any</b> of the operations have
- * completed. Until the first operation is completed, it will
- * return <code>false</code>.
+ * If this future represents multiple operations, then this method will
+ * return <code>true</code> when <b>any</b> of the operations have
+ * completed. Until the first operation is completed, it will return
+ * <code>false</code>.
* </p>
- * @return <tt>true</tt> if any operations represented by this future have
- * completed.
+ *
+ * @return <tt>true</tt> if any operations represented by this future have
+ * completed.
*/
boolean hasValue();
/**
* <p>
- * Returns <tt>true</tt> if <b>all</b> underlying operation(s) have been completed.
+ * Returns <tt>true</tt> if <b>all</b> underlying operation(s) have been
+ * completed.
* </p>
* <p>
* If this future represents access to just one operation, then this method
- * and {@link #hasValue()} will always return the same value. That is, when a single
- * operation has a value, it is then considered done/completed and both
- * {@link #hasValue()} and #isDone will return <code>true</code>.
+ * and {@link #hasValue()} will always return the same value. That is, when
+ * a single operation has a value, it is then considered done/completed and
+ * both {@link #hasValue()} and #isDone will return <code>true</code>.
* </p>
* <p>
* If this future represents multiple operations, then this method will only
- * return <code>true</code> when <b>all</b> of the operations have
- * completed. Until all operations have completed, it will return <code>false</code>.
+ * return <code>true</code> when <b>all</b> of the operations have
+ * completed. Until all operations have completed, it will return
+ * <code>false</code>.
* </p>
* <p>
* Completion can be due to normal operation completion, an exception, or
diff --git a/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/IListenableFuture.java b/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/IListenableFuture.java
new file mode 100644
index 0000000..d57739a
--- /dev/null
+++ b/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/IListenableFuture.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2010, 2013 Composent, 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:
+ * Composent, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.equinox.concurrent.future;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+
+/**
+ *
+ * A future that allows for an {@link IProgressRunnable} (with optional
+ * {@link IProgressMonitor}) to be executed via an {@link IExecutor}.
+ * @since 1.1
+ *
+ */
+public interface IListenableFuture<ResultType> extends IFuture<ResultType> {
+
+ /**
+ * Add an {@link IProgressRunnable} that will be called back/run once the
+ * asynchronous execution is complete. The {@link IProgressRunnable} must be
+ * non-<code>null</code> and the {@link IExecutor} must also be non-
+ * <code>null</code>. The given progressMonitor may be <code>null</code>.
+ * <p>
+ * If the future has already completed by the time this method is called
+ * (i.e. {@link #isDone()} returns <code>true</code>, the progressRunnable
+ * will be executed immediately by the given executor.
+ *
+ * @param executor
+ * the {@link IExecutor} to use to execute the given
+ * {@link IProgressRunnable}. Must not be <code>null</code>.
+ * @param progressRunnable
+ * the {@link IProgressRunnable} that will be executed when this
+ * future is complete. Must not be <code>null</code>.
+ * @param monitor
+ * an optional progress monitor to be passed to the
+ * progressRunnable when executed. May be <code>null</code>.
+ */
+ public void addListener(IExecutor executor,
+ IProgressRunnable<ResultType> progressRunnable,
+ IProgressMonitor monitor);
+
+}
diff --git a/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/IProgressRunnable.java b/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/IProgressRunnable.java
index ba08d7d..b16c2ad 100644
--- a/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/IProgressRunnable.java
+++ b/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/IProgressRunnable.java
@@ -1,12 +1,13 @@
/******************************************************************************
-* Copyright (c) 2009 EclipseSource 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:
-* EclipseSource - initial API and implementation
-******************************************************************************/
+ * Copyright (c) 2010, 2013 EclipseSource 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:
+ * EclipseSource - initial API and implementation
+ * Gunnar Wagenknecht - added support for generics
+ ******************************************************************************/
package org.eclipse.equinox.concurrent.future;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -15,12 +16,19 @@ import org.eclipse.core.runtime.IProgressMonitor;
* Interface defining a block of code that can be run, return an Object result,
* and throw an arbitrary Exception.
*
+ * @param <ResultType>
+ * the type that will be returned by {@link #run(IProgressMonitor)}
+ * @since 1.1
*/
-public interface IProgressRunnable {
- /** Perform some action that returns a result or throws an exception
- * @param monitor the IProgressMonitor associated with this callable
+public interface IProgressRunnable<ResultType> {
+
+ /**
+ * Perform some action that returns a result or throws an exception
+ *
+ * @param monitor
+ * the IProgressMonitor associated with this callable
* @return result from the call
* @throws Exception
*/
- Object run(IProgressMonitor monitor) throws Exception;
+ ResultType run(IProgressMonitor monitor) throws Exception;
} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/IRunnableExecutor.java b/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/IRunnableExecutor.java
index dbf3a43..a6ad2e1 100644
--- a/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/IRunnableExecutor.java
+++ b/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/IRunnableExecutor.java
@@ -1,18 +1,21 @@
/******************************************************************************
-* Copyright (c) 2009 EclipseSource 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:
-* EclipseSource - initial API and implementation
-******************************************************************************/
+ * Copyright (c) 2009, 2013 EclipseSource 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:
+ * EclipseSource - initial API and implementation
+ ******************************************************************************/
package org.eclipse.equinox.concurrent.future;
/**
- * An executor that can execute Runnables, rather than {@link IProgressRunnable}s.
- *
- * @see IExecutor#execute(IProgressRunnable, org.eclipse.core.runtime.IProgressMonitor)
+ * An executor that can execute Runnables, rather than {@link IProgressRunnable}
+ * s.
+ *
+ * @see IExecutor#execute(IProgressRunnable,
+ * org.eclipse.core.runtime.IProgressMonitor)
+ * @since 1.1
*/
public interface IRunnableExecutor {
void execute(Runnable runnable);
diff --git a/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/ISafeProgressRunner.java b/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/ISafeProgressRunner.java
index 56c9413..4889f50 100644
--- a/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/ISafeProgressRunner.java
+++ b/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/ISafeProgressRunner.java
@@ -1,20 +1,22 @@
/******************************************************************************
-* Copyright (c) 2009 EclipseSource 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:
-* EclipseSource - initial API and implementation
-******************************************************************************/
+ * Copyright (c) 2010, 2013 EclipseSource 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:
+ * EclipseSource - initial API and implementation
+ * Gunnar Wagenknecht - added support for generics
+ ******************************************************************************/
package org.eclipse.equinox.concurrent.future;
/**
- * A runner that can execute {@link IProgressRunnable}s safely. Running
- * an {@link IProgressRunnable} safely means not throwing any {@link Exception}
+ * A runner that can execute {@link IProgressRunnable}s safely. Running an
+ * {@link IProgressRunnable} safely means not throwing any {@link Exception}
* possibly thrown by the given {@link IProgressRunnable}.
- *
+ * @since 1.1
+ *
*/
public interface ISafeProgressRunner {
- void runWithProgress(IProgressRunnable runnable);
+ void runWithProgress(IProgressRunnable<?> runnable);
}
diff --git a/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/ImmediateExecutor.java b/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/ImmediateExecutor.java
index b5c936c..b0b39de 100644
--- a/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/ImmediateExecutor.java
+++ b/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/ImmediateExecutor.java
@@ -1,12 +1,13 @@
/******************************************************************************
-* Copyright (c) 2009 EclipseSource 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:
-* EclipseSource - initial API and implementation
-******************************************************************************/
+ * Copyright (c) 2010, 2013 EclipseSource 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:
+ * EclipseSource - initial API and implementation
+ * Gunnar Wagenknecht - added support for generics
+ ******************************************************************************/
package org.eclipse.equinox.concurrent.future;
import org.eclipse.core.runtime.Assert;
@@ -17,23 +18,34 @@ import org.eclipse.core.runtime.IProgressMonitor;
* Executes {@link IProgressRunnable} instances immediately.
* </p>
* <p>
- * <b>NOTE</b>: {@link #execute(IProgressRunnable, IProgressMonitor)} should be used with some
- * degree of caution with this implementation, as unlike other implementations the {@link IProgressRunnable#run(IProgressMonitor)}
- * method will be called by the thread that calls {@link #execute(IProgressRunnable, IProgressMonitor)}, meaning
- * that calling #execute(IProgressRunnable, IProgressMonitor) may block the calling thread indefinitely.
+ * <b>NOTE</b>: {@link #execute(IProgressRunnable, IProgressMonitor)} should be
+ * used with some degree of caution with this implementation, as unlike other
+ * implementations the {@link IProgressRunnable#run(IProgressMonitor)} method
+ * will be called by the thread that calls
+ * {@link #execute(IProgressRunnable, IProgressMonitor)}, meaning that calling
+ * #execute(IProgressRunnable, IProgressMonitor) may block the calling thread
+ * indefinitely.
* </p>
+ *
* @see ThreadsExecutor
+ * @since 1.1
*/
-public class ImmediateExecutor extends AbstractExecutor implements IExecutor, IRunnableExecutor {
+public class ImmediateExecutor extends AbstractExecutor implements IExecutor,
+ IRunnableExecutor {
- protected AbstractFuture createFuture(IProgressMonitor monitor) {
- return new SingleOperationFuture(monitor);
+ @SuppressWarnings("rawtypes")
+ protected AbstractFuture<?> createFuture(IProgressMonitor monitor) {
+ return new SingleOperationListenableFuture(monitor);
}
- public IFuture execute(IProgressRunnable runnable, IProgressMonitor monitor) {
+ @SuppressWarnings("unchecked")
+ public <ResultType> IFuture<ResultType> execute(
+ IProgressRunnable<? extends ResultType> runnable,
+ IProgressMonitor monitor) {
Assert.isNotNull(runnable);
+ @SuppressWarnings("rawtypes")
AbstractFuture sof = createFuture(monitor);
- // Actually run the runnable immediately. See NOTE above
+ // Actually run the runnable immediately. See NOTE above
sof.runWithProgress(runnable);
return sof;
}
diff --git a/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/SingleOperationFuture.java b/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/SingleOperationFuture.java
index 3f6a416..0907477 100644
--- a/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/SingleOperationFuture.java
+++ b/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/SingleOperationFuture.java
@@ -1,12 +1,12 @@
/******************************************************************************
-* Copyright (c) 2009 EclipseSource 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:
-* EclipseSource - initial API and implementation
-******************************************************************************/
+ * Copyright (c) 2009, 2013 EclipseSource 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:
+ * EclipseSource - initial API and implementation
+ ******************************************************************************/
package org.eclipse.equinox.concurrent.future;
import org.eclipse.core.runtime.*;
@@ -16,15 +16,17 @@ import org.eclipse.core.runtime.*;
* Future implementation for a single operation.
* </p>
* <p>
- * Subclasses may be created if desired. Note that if subclasses are created, that
- * they should/must be very careful with respect to overriding the synchronized
- * methods in this class.
+ * Subclasses may be created if desired. Note that if subclasses are created,
+ * that they should/must be very careful with respect to overriding the
+ * synchronized methods in this class.
* </p>
+ * @since 1.1
*/
-public class SingleOperationFuture extends AbstractFuture {
+public class SingleOperationFuture<ResultType> extends
+ AbstractFuture<ResultType> {
private static final String PLUGIN_ID = "org.eclipse.equinox.concurrent";
- private Object resultValue = null;
+ private ResultType resultValue = null;
private IStatus status = null;
private TimeoutException timeoutException = null;
protected IProgressMonitor progressMonitor;
@@ -35,10 +37,13 @@ public class SingleOperationFuture extends AbstractFuture {
public SingleOperationFuture(IProgressMonitor progressMonitor) {
super();
- this.progressMonitor = new FutureProgressMonitor((progressMonitor == null) ? new NullProgressMonitor() : progressMonitor);
+ this.progressMonitor = new FutureProgressMonitor(
+ (progressMonitor == null) ? new NullProgressMonitor()
+ : progressMonitor);
}
- public synchronized Object get() throws InterruptedException, OperationCanceledException {
+ public synchronized ResultType get() throws InterruptedException,
+ OperationCanceledException {
throwIfCanceled();
while (!isDone())
wait();
@@ -46,7 +51,9 @@ public class SingleOperationFuture extends AbstractFuture {
return resultValue;
}
- public synchronized Object get(long waitTimeInMillis) throws InterruptedException, TimeoutException, OperationCanceledException {
+ public synchronized ResultType get(long waitTimeInMillis)
+ throws InterruptedException, TimeoutException,
+ OperationCanceledException {
// If waitTime out of bounds then throw illegal argument exception
if (waitTimeInMillis < 0)
throw new IllegalArgumentException("waitTimeInMillis must be => 0"); //$NON-NLS-1$
@@ -58,17 +65,20 @@ public class SingleOperationFuture extends AbstractFuture {
// If we're already done, then return result
if (isDone())
return resultValue;
- // Otherwise, wait for some time, then throw if canceled during wait, return value if
+ // Otherwise, wait for some time, then throw if canceled during wait,
+ // return value if
// Compute start time and set waitTime
long startTime = System.currentTimeMillis();
long waitTime = waitTimeInMillis;
- // we've received one during wait or throw timeout exception if too much time has elapsed
+ // we've received one during wait or throw timeout exception if too much
+ // time has elapsed
for (;;) {
wait(waitTime);
throwIfCanceled();
if (isDone())
return resultValue;
- waitTime = waitTimeInMillis - (System.currentTimeMillis() - startTime);
+ waitTime = waitTimeInMillis
+ - (System.currentTimeMillis() - startTime);
if (waitTime <= 0)
throw createTimeoutException(waitTimeInMillis);
}
@@ -79,23 +89,30 @@ public class SingleOperationFuture extends AbstractFuture {
}
/**
- * This method is not intended to be called by clients. Rather it should only be used by {@link IExecutor}s.
+ * This method is not intended to be called by clients. Rather it should
+ * only be used by {@link IExecutor}s.
*
* @noreference
*/
- public void runWithProgress(final IProgressRunnable runnable) {
+ public void runWithProgress(final IProgressRunnable<?> runnable) {
Assert.isNotNull(runnable);
if (!isCanceled()) {
SafeRunner.run(new ISafeRunnable() {
public void handleException(Throwable exception) {
- if (!isCanceled())
- setException(exception);
+ synchronized (SingleOperationFuture.this) {
+ if (!isCanceled())
+ setException(exception);
+ }
}
public void run() throws Exception {
- Object result = runnable.run(getProgressMonitor());
- if (!isCanceled())
- set(result);
+ @SuppressWarnings("unchecked")
+ ResultType result = (ResultType) runnable
+ .run(getProgressMonitor());
+ synchronized (SingleOperationFuture.this) {
+ if (!isCanceled())
+ set(result);
+ }
}
});
}
@@ -106,7 +123,7 @@ public class SingleOperationFuture extends AbstractFuture {
}
public boolean hasValue() {
- // for a single operation future, hasValue means that the single
+ // for a single operation future, hasValue means that the single
// operation has completed, and there will be no more.
return isDone();
}
@@ -116,18 +133,20 @@ public class SingleOperationFuture extends AbstractFuture {
return false;
if (isCanceled())
return false;
- setStatus(new Status(IStatus.CANCEL, PLUGIN_ID, IStatus.CANCEL, "Operation canceled", null)); //$NON-NLS-1$ //$NON-NLS-2$
+ setStatus(new Status(IStatus.CANCEL, PLUGIN_ID, IStatus.CANCEL,
+ "Operation canceled", null)); //$NON-NLS-1$ //$NON-NLS-2$
getProgressMonitor().setCanceled(true);
notifyAll();
return true;
}
protected synchronized void setException(Throwable ex) {
- setStatus(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "Exception during operation", ex)); //$NON-NLS-1$ //$NON-NLS-2$
+ setStatus(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR,
+ "Exception during operation", ex)); //$NON-NLS-1$ //$NON-NLS-2$
notifyAll();
}
- protected synchronized void set(Object newValue) {
+ protected synchronized void set(ResultType newValue) {
resultValue = newValue;
setStatus(Status.OK_STATUS);
notifyAll();
@@ -138,8 +157,10 @@ public class SingleOperationFuture extends AbstractFuture {
}
private TimeoutException createTimeoutException(long timeout) {
- setStatus(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "Operation timeout after " + timeout + "ms", null)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- timeoutException = new TimeoutException("Single operation timeout", timeout); //$NON-NLS-1$
+ setStatus(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR,
+ "Operation timeout after " + timeout + "ms", null)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ timeoutException = new TimeoutException(
+ "Single operation timeout", timeout); //$NON-NLS-1$
return timeoutException;
}
diff --git a/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/SingleOperationListenableFuture.java b/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/SingleOperationListenableFuture.java
new file mode 100644
index 0000000..75930b6
--- /dev/null
+++ b/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/SingleOperationListenableFuture.java
@@ -0,0 +1,98 @@
+/******************************************************************************
+ * Copyright (c) 2010, 2013 Composent, 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:
+ * Composent, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.equinox.concurrent.future;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.ISafeRunnable;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.SafeRunner;
+
+/**
+ * <p>
+ * Listenable future implementation for a single operation.
+ * </p>
+ * <p>
+ * Subclasses may be created if desired. Note that if subclasses are created,
+ * that they should/must be very careful with respect to overriding the
+ * synchronized methods in this class.
+ * </p>
+ * @since 1.1
+ */
+public class SingleOperationListenableFuture<ResultType> extends
+ SingleOperationFuture<ResultType> implements
+ IListenableFuture<ResultType> {
+
+ private IProgressRunnable<ResultType> progressRunnable;
+ private IProgressMonitor progressMonitor;
+ private IExecutor listenerExecutor;
+
+ public SingleOperationListenableFuture() {
+ super();
+ }
+
+ public SingleOperationListenableFuture(IProgressMonitor progressMonitor) {
+ super(progressMonitor);
+ }
+
+ public void addListener(IExecutor executor,
+ IProgressRunnable<ResultType> progressRunnable,
+ IProgressMonitor monitor) {
+ Assert.isNotNull(executor);
+ Assert.isNotNull(progressRunnable);
+ synchronized (this) {
+ if (this.progressRunnable == null) {
+ this.progressRunnable = progressRunnable;
+ this.progressMonitor = monitor;
+ this.listenerExecutor = executor;
+ // Now, if we're already done, then execute the listenable now
+ if (isDone())
+ execListenable();
+ }
+ }
+ }
+
+ public void runWithProgress(final IProgressRunnable<?> runnable) {
+ Assert.isNotNull(runnable);
+ if (!isCanceled()) {
+ SafeRunner.run(new ISafeRunnable() {
+ public void handleException(Throwable exception) {
+ synchronized (SingleOperationListenableFuture.this) {
+ if (!isCanceled())
+ setException(exception);
+ execListenable();
+ }
+ }
+
+ public void run() throws Exception {
+ @SuppressWarnings("unchecked")
+ ResultType result = (ResultType) runnable
+ .run(getProgressMonitor());
+ synchronized (SingleOperationListenableFuture.this) {
+ if (!isCanceled())
+ set(result);
+ execListenable();
+ }
+ }
+ });
+ }
+ }
+
+ private void execListenable() {
+ // If no progressRunnable has been set, then we simply return
+ if (progressRunnable == null || listenerExecutor == null)
+ return;
+ // Make sure that the progress monitor is set to non-null
+ if (progressMonitor == null)
+ progressMonitor = new NullProgressMonitor();
+ // then we execute using executor
+ this.listenerExecutor.execute(progressRunnable, progressMonitor);
+ }
+}
diff --git a/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/ThreadsExecutor.java b/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/ThreadsExecutor.java
index 84ab74e..5160e4a 100644
--- a/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/ThreadsExecutor.java
+++ b/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/ThreadsExecutor.java
@@ -1,12 +1,13 @@
/******************************************************************************
-* Copyright (c) 2009 EclipseSource 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:
-* EclipseSource - initial API and implementation
-******************************************************************************/
+ * Copyright (c) 2010, 2013 EclipseSource 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:
+ * EclipseSource - initial API and implementation
+ * Gunnar Wagenknecht - added support for generics
+ ******************************************************************************/
package org.eclipse.equinox.concurrent.future;
import org.eclipse.core.runtime.Assert;
@@ -14,17 +15,19 @@ import org.eclipse.core.runtime.IProgressMonitor;
/**
* <p>
- * An executor that implements running the given{@link IProgressRunnable}s
- * via a new {@link Thread}.
+ * An executor that implements running the given{@link IProgressRunnable}s via a
+ * new {@link Thread}.
* </p>
* <p>
- * The {@link #execute(IProgressRunnable, IProgressMonitor)} method on this class will
- * create a new Thread (with name provided as result of {@link #createThreadName(IProgressRunnable)},
- * that will run the {@link IProgressRunnable} and set the result in the future returned
- * from {@link #execute(IProgressRunnable, IProgressMonitor)}.
+ * The {@link #execute(IProgressRunnable, IProgressMonitor)} method on this
+ * class will create a new Thread (with name provided as result of
+ * {@link #createThreadName(IProgressRunnable)}, that will run the
+ * {@link IProgressRunnable} and set the result in the future returned from
+ * {@link #execute(IProgressRunnable, IProgressMonitor)}.
* <p>
* Subclasses may extend the behavior of this ThreadsExecutor.
* </p>
+ * @since 1.1
*/
public class ThreadsExecutor extends AbstractExecutor {
@@ -32,18 +35,23 @@ public class ThreadsExecutor extends AbstractExecutor {
// nothing
}
- protected String createThreadName(IProgressRunnable runnable) {
+ protected String createThreadName(IProgressRunnable<?> runnable) {
return "ThreadsExecutor(" + runnable.toString() + ")"; //$NON-NLS-1$ //$NON-NLS-2$
}
/**
- * Create a runnable given an {@link IProgressRunnable} and an {@link ISafeProgressRunner} to
- * run the runnable.
- * @param runner the safe progress runner to run the runnable
- * @param progressRunnable the runnable to run.
- * @return Runnable that when run will use the safe progress runner to run the progressRunnable
+ * Create a runnable given an {@link IProgressRunnable} and an
+ * {@link ISafeProgressRunner} to run the runnable.
+ *
+ * @param runner
+ * the safe progress runner to run the runnable
+ * @param progressRunnable
+ * the runnable to run.
+ * @return Runnable that when run will use the safe progress runner to run
+ * the progressRunnable
*/
- protected Runnable createRunnable(final ISafeProgressRunner runner, final IProgressRunnable progressRunnable) {
+ protected Runnable createRunnable(final ISafeProgressRunner runner,
+ final IProgressRunnable<?> progressRunnable) {
return new Runnable() {
public void run() {
runner.runWithProgress(progressRunnable);
@@ -52,11 +60,12 @@ public class ThreadsExecutor extends AbstractExecutor {
}
/**
- * Configure the given thread prior to starting it. Subclasses may override as
- * appropriate to configure the given thread appropriately. The default implementation
- * calls {@link Thread#setDaemon(boolean)}.
+ * Configure the given thread prior to starting it. Subclasses may override
+ * as appropriate to configure the given thread appropriately. The default
+ * implementation calls {@link Thread#setDaemon(boolean)}.
*
- * @param thread the thread to configure
+ * @param thread
+ * the thread to configure
*/
protected void configureThreadForExecution(Thread thread) {
// By default, we'll make the thread a daemon thread
@@ -65,18 +74,26 @@ public class ThreadsExecutor extends AbstractExecutor {
/**
* Create an {@link AbstractFuture} with the given IProgressMonitor.
- * @param monitor a progress monitor to associate with the future. May be <code>null</code>.
+ *
+ * @param monitor
+ * a progress monitor to associate with the future. May be
+ * <code>null</code>.
*/
- protected AbstractFuture createFuture(IProgressMonitor monitor) {
- return new SingleOperationFuture(monitor);
+ @SuppressWarnings("rawtypes")
+ protected AbstractFuture<?> createFuture(IProgressMonitor monitor) {
+ return new SingleOperationListenableFuture(monitor);
}
- public synchronized IFuture execute(IProgressRunnable runnable, IProgressMonitor monitor) throws IllegalThreadStateException {
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ public synchronized <ResultType> IFuture<ResultType> execute(
+ IProgressRunnable<? extends ResultType> runnable,
+ IProgressMonitor monitor) throws IllegalThreadStateException {
Assert.isNotNull(runnable);
// Now create future
AbstractFuture sof = createFuture(monitor);
// Create the thread for this operation
- Thread thread = new Thread(createRunnable(sof, runnable), createThreadName(runnable));
+ Thread thread = new Thread(createRunnable(sof, runnable),
+ createThreadName(runnable));
configureThreadForExecution(thread);
// start thread
thread.start();
diff --git a/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/TimeoutException.java b/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/TimeoutException.java
index dfc772a..7fe8ccb 100644
--- a/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/TimeoutException.java
+++ b/bundles/org.eclipse.equinox.concurrent/src/org/eclipse/equinox/concurrent/future/TimeoutException.java
@@ -1,16 +1,17 @@
/******************************************************************************
-* Copyright (c) 2009 EclipseSource 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:
-* EclipseSource - initial API and implementation
-******************************************************************************/
+ * Copyright (c) 2009 EclipseSource 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:
+ * EclipseSource - initial API and implementation
+ ******************************************************************************/
package org.eclipse.equinox.concurrent.future;
/**
* Timeout exception thrown when timeout occurs
+ * @since 1.1
*/
public class TimeoutException extends Exception {
@@ -29,6 +30,7 @@ public class TimeoutException extends Exception {
/**
* Return the timeout duration.
+ *
* @return long the timeout duration that caused this timeout exception.
*/
public long getDuration() {