summaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorSimon Rettberg2016-12-01 15:13:57 +0100
committerSimon Rettberg2016-12-01 15:13:57 +0100
commit617fb197e7e5a7be033fb5114bc72669f440da27 (patch)
tree843ce0270c86e393de3873131e574bf069d818f8 /api
parentDatagramPacket constructor doesn't throw SocketException in SE 8+ (diff)
downloadtaskman-lite-617fb197e7e5a7be033fb5114bc72669f440da27.tar.gz
taskman-lite-617fb197e7e5a7be033fb5114bc72669f440da27.tar.xz
taskman-lite-617fb197e7e5a7be033fb5114bc72669f440da27.zip
Add cancellable tasks, optional response payload compression
Diffstat (limited to 'api')
-rw-r--r--api/src/main/java/org/openslx/taskmanager/api/AbstractTask.java2
-rw-r--r--api/src/main/java/org/openslx/taskmanager/api/CancellableTask.java15
-rw-r--r--api/src/main/java/org/openslx/taskmanager/api/TaskStatus.java10
3 files changed, 26 insertions, 1 deletions
diff --git a/api/src/main/java/org/openslx/taskmanager/api/AbstractTask.java b/api/src/main/java/org/openslx/taskmanager/api/AbstractTask.java
index b850c2c..d284ecf 100644
--- a/api/src/main/java/org/openslx/taskmanager/api/AbstractTask.java
+++ b/api/src/main/java/org/openslx/taskmanager/api/AbstractTask.java
@@ -310,6 +310,8 @@ public abstract class AbstractTask implements Runnable
}
if ( ret ) {
this.status.statusCode = StatusCode.TASK_FINISHED;
+ } else if ( this.status.statusCode == StatusCode.TASK_CANCELLING ) {
+ this.status.statusCode = StatusCode.TASK_CANCELLED;
} else {
this.status.statusCode = StatusCode.TASK_ERROR;
}
diff --git a/api/src/main/java/org/openslx/taskmanager/api/CancellableTask.java b/api/src/main/java/org/openslx/taskmanager/api/CancellableTask.java
new file mode 100644
index 0000000..fa27091
--- /dev/null
+++ b/api/src/main/java/org/openslx/taskmanager/api/CancellableTask.java
@@ -0,0 +1,15 @@
+package org.openslx.taskmanager.api;
+
+/**
+ * Implement this if you want your task to be cancellable.
+ * After cancel has been called, your task should try to clean up and leave
+ * its execute() method in a timely fashion.
+ * The execute() method must return false in that case (unless
+ * it could still do everything it was supposed to)
+ */
+public interface CancellableTask
+{
+
+ public void cancel();
+
+}
diff --git a/api/src/main/java/org/openslx/taskmanager/api/TaskStatus.java b/api/src/main/java/org/openslx/taskmanager/api/TaskStatus.java
index 0aa9ef7..edf7bce 100644
--- a/api/src/main/java/org/openslx/taskmanager/api/TaskStatus.java
+++ b/api/src/main/java/org/openslx/taskmanager/api/TaskStatus.java
@@ -15,12 +15,15 @@ public final class TaskStatus
TASK_PROCESSING,
TASK_FINISHED,
TASK_ERROR,
+ TASK_CANCELLING,
+ TASK_CANCELLED,
+ NOT_CANCELLABLE,
NO_SUCH_INSTANCE,
NO_SUCH_TASK,
NO_SUCH_CONSTRUCTOR,
DUPLICATE_ID,
PARENT_FAILED,
- JSON_ERROR
+ JSON_ERROR,
}
/**
@@ -77,6 +80,11 @@ public final class TaskStatus
* Create a single "json error" status we can use everywhere.
*/
public static final TaskStatus ts_jsonError = new TaskStatus( StatusCode.JSON_ERROR );
+
+ /**
+ * Create a single "not cancellable" status we can use everywhere.
+ */
+ public static final TaskStatus ts_notCancellable = new TaskStatus( StatusCode.NOT_CANCELLABLE );
/**
* Create new TaskStatus with given initial status code