Archiviert
13
0

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!
Dieser Commit ist enthalten in:
Andrew Ardill 2011-02-14 15:29:52 +11:00
Ursprung cf6c435c6e
Commit dc45946163
4 geänderte Dateien mit 24 neuen und 4 gelöschten Zeilen

Datei anzeigen

@ -210,7 +210,7 @@ public class CraftScheduler implements BukkitScheduler, Runnable {
} }
} }
} }
craftThreadManager.interruptTask(plugin); craftThreadManager.interruptTasks(plugin);
} }
public void cancelAllTasks() { public void cancelAllTasks() {
@ -220,4 +220,7 @@ public class CraftScheduler implements BukkitScheduler, Runnable {
craftThreadManager.interruptAllTasks(); craftThreadManager.interruptAllTasks();
} }
public boolean isCurrentlyRunning(int taskId){
return craftThreadManager.isAlive(taskId);
}
} }

Datei anzeigen

@ -4,7 +4,7 @@ import java.lang.Comparable;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
public class CraftTask implements Comparable { public class CraftTask implements Comparable<Object> {
private final Runnable task; private final Runnable task;
private final boolean syncTask; private final boolean syncTask;

Datei anzeigen

@ -1,7 +1,6 @@
package org.bukkit.craftbukkit.scheduler; package org.bukkit.craftbukkit.scheduler;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedList;
import java.util.Iterator; import java.util.Iterator;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
@ -31,7 +30,7 @@ public class CraftThreadManager {
} }
} }
void interruptTask(Plugin owner) { void interruptTasks(Plugin owner) {
synchronized (workers) { synchronized (workers) {
Iterator<CraftWorker> itr = workers.iterator(); Iterator<CraftWorker> itr = workers.iterator();
while (itr.hasNext()) { 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;
}
} }

Datei anzeigen

@ -53,6 +53,10 @@ public class CraftWorker implements Runnable {
t.interrupt(); t.interrupt();
} }
public boolean isAlive() {
return t.isAlive();
}
private static int getNextHashId() { private static int getNextHashId() {
synchronized (hashIdCounterSync) { synchronized (hashIdCounterSync) {
return hashIdCounter++; return hashIdCounter++;