dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #40527
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20566: Added support for ListenableFuture in Scheduler and implemented in SpringScheduler. New method im...
------------------------------------------------------------
revno: 20566
committer: Halvdan Hoem Grelland <halvdanhg@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-10-07 15:25:14 +0200
message:
Added support for ListenableFuture in Scheduler and implemented in SpringScheduler. New method immediately executes and returns a ListenableFuture, allowing callbacks to be registered for task completion.
modified:
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/scheduling/Scheduler.java
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/scheduling/SpringScheduler.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/scheduling/Scheduler.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/scheduling/Scheduler.java 2015-09-14 18:06:48 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/scheduling/Scheduler.java 2015-10-07 13:25:14 +0000
@@ -28,6 +28,10 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import org.springframework.util.concurrent.ListenableFuture;
+
+import java.util.concurrent.Callable;
+
/**
* Scheduler for managing the scheduling and execution of tasks.
*
@@ -52,6 +56,15 @@
* @task the task to execute.
*/
void executeTask( Runnable task );
+
+ /**
+ * Execute the given task immediately and return a ListenableFuture.
+ *
+ * @param callable the task to execute.
+ * @param <T> return type of the supplied callable.
+ * @return a ListenableFuture representing the result of the task.
+ */
+ <T> ListenableFuture<T> executeTask( Callable<T> callable );
/**
* Schedule the given task for future execution. The task can be referenced
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/scheduling/SpringScheduler.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/scheduling/SpringScheduler.java 2015-06-05 12:56:34 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/scheduling/SpringScheduler.java 2015-10-07 13:25:14 +0000
@@ -31,13 +31,15 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
+import java.util.concurrent.Callable;
import java.util.concurrent.ScheduledFuture;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.springframework.core.task.TaskExecutor;
+import org.springframework.core.task.AsyncListenableTaskExecutor;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.support.CronTrigger;
+import org.springframework.util.concurrent.ListenableFuture;
/**
* {@link Scheduler} implementation for use within the Spring framework.
@@ -61,9 +63,9 @@
this.taskScheduler = taskScheduler;
}
- private TaskExecutor taskExecutor;
+ private AsyncListenableTaskExecutor taskExecutor;
- public void setTaskExecutor( TaskExecutor taskExecutor )
+ public void setTaskExecutor( AsyncListenableTaskExecutor taskExecutor )
{
this.taskExecutor = taskExecutor;
}
@@ -79,6 +81,12 @@
}
@Override
+ public <T> ListenableFuture<T> executeTask( Callable<T> callable )
+ {
+ return taskExecutor.submitListenable( callable );
+ }
+
+ @Override
public boolean scheduleTask( String key, Runnable task, String cronExpr )
{
if ( key != null && !futures.containsKey( key ) )