summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndrew Ardill <andrew.ardill@gmail.com>2011-02-14 15:29:52 +1100
committerAndrew Ardill <andrew.ardill@gmail.com>2011-02-17 13:27:54 +1100
commitdc45946163d5c472147b52a36e8d325913f904e0 (patch)
treef832e1f5707f55918253d98dd5db4b04727af2a4 /src
parentcf6c435c6ed0de50f20f3e7ddad21e9b8ca8372a (diff)
downloadcraftbukkit-dc45946163d5c472147b52a36e8d325913f904e0.tar
craftbukkit-dc45946163d5c472147b52a36e8d325913f904e0.tar.gz
craftbukkit-dc45946163d5c472147b52a36e8d325913f904e0.tar.lz
craftbukkit-dc45946163d5c472147b52a36e8d325913f904e0.tar.xz
craftbukkit-dc45946163d5c472147b52a36e8d325913f904e0.zip
implementation of isCurrentlyRunning(int taskId);
Burrows down to the worker thread assigned to this task, and returns its alive status. If no such thread exists, then the task is not running!
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java5
-rw-r--r--src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java2
-rw-r--r--src/main/java/org/bukkit/craftbukkit/scheduler/CraftThreadManager.java17
-rw-r--r--src/main/java/org/bukkit/craftbukkit/scheduler/CraftWorker.java4
4 files changed, 24 insertions, 4 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java
index 46e095bc..298c9724 100644
--- a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java
+++ b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java
@@ -210,7 +210,7 @@ public class CraftScheduler implements BukkitScheduler, Runnable {
}
}
}
- craftThreadManager.interruptTask(plugin);
+ craftThreadManager.interruptTasks(plugin);
}
public void cancelAllTasks() {
@@ -220,4 +220,7 @@ public class CraftScheduler implements BukkitScheduler, Runnable {
craftThreadManager.interruptAllTasks();
}
+ public boolean isCurrentlyRunning(int taskId){
+ return craftThreadManager.isAlive(taskId);
+ }
}
diff --git a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java
index 80a1e785..7d5b610e 100644
--- a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java
+++ b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java
@@ -4,7 +4,7 @@ import java.lang.Comparable;
import org.bukkit.plugin.Plugin;
-public class CraftTask implements Comparable {
+public class CraftTask implements Comparable<Object> {
private final Runnable task;
private final boolean syncTask;
diff --git a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftThreadManager.java b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftThreadManager.java
index 8ded4984..d63b458e 100644
--- a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftThreadManager.java
+++ b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftThreadManager.java
@@ -1,7 +1,6 @@
package org.bukkit.craftbukkit.scheduler;
import java.util.HashSet;
-import java.util.LinkedList;
import java.util.Iterator;
import org.bukkit.plugin.Plugin;
@@ -31,7 +30,7 @@ public class CraftThreadManager {
}
}
- void interruptTask(Plugin owner) {
+ void interruptTasks(Plugin owner) {
synchronized (workers) {
Iterator<CraftWorker> itr = workers.iterator();
while (itr.hasNext()) {
@@ -52,4 +51,18 @@ public class CraftThreadManager {
}
}
}
+
+ boolean isAlive(int taskId) {
+ synchronized (workers) {
+ Iterator<CraftWorker> itr = workers.iterator();
+ while (itr.hasNext()) {
+ CraftWorker craftWorker = itr.next();
+ if (craftWorker.getTaskId() == taskId) {
+ return craftWorker.isAlive();
+ }
+ }
+ }
+ // didn't find it, so it must have been removed
+ return false;
+ }
}
diff --git a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftWorker.java b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftWorker.java
index 2bb9400d..3bf91e4f 100644
--- a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftWorker.java
+++ b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftWorker.java
@@ -53,6 +53,10 @@ public class CraftWorker implements Runnable {
t.interrupt();
}
+ public boolean isAlive() {
+ return t.isAlive();
+ }
+
private static int getNextHashId() {
synchronized (hashIdCounterSync) {
return hashIdCounter++;