Use a queue for expiry

This commit is contained in:
Jesse Boyd 2016-08-07 11:29:59 +10:00
parent 395d6364be
commit 91c78407cd
3 changed files with 45 additions and 37 deletions

View File

@ -1420,6 +1420,7 @@ public class PlayerEvents extends PlotListener implements Listener {
return true; return true;
} }
} }
if (mobs != null) {
for (IntegerFlag flag : flags) { for (IntegerFlag flag : flags) {
int i; int i;
switch (flag.getName()) { switch (flag.getName()) {
@ -1446,7 +1447,6 @@ public class PlayerEvents extends PlotListener implements Listener {
} }
mobs[i]++; mobs[i]++;
} }
if (mobs != null) {
plot.setMeta("EntityCount", mobs); plot.setMeta("EntityCount", mobs);
plot.setMeta("EntityCountTime", System.currentTimeMillis()); plot.setMeta("EntityCountTime", System.currentTimeMillis());
} }

View File

@ -291,7 +291,7 @@ public class GlobalBlockQueue {
if (this.runnables.isEmpty()) { if (this.runnables.isEmpty()) {
return false; return false;
} }
final ConcurrentLinkedDeque<Runnable> tmp = new ConcurrentLinkedDeque<>(this.runnables); final ArrayList<Runnable> tmp = new ArrayList<>(this.runnables);
this.runnables.clear(); this.runnables.clear();
for (final Runnable runnable : tmp) { for (final Runnable runnable : tmp) {
runnable.run(); runnable.run();

View File

@ -18,7 +18,6 @@ import com.intellectualcrafters.plot.object.RunnableVal3;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.UUIDHandler;
import java.util.ArrayDeque; import java.util.ArrayDeque;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
@ -26,9 +25,9 @@ import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.Objects; import java.util.Objects;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedDeque;
public class ExpireManager { public class ExpireManager {
@ -217,7 +216,7 @@ public class ExpireManager {
return false; return false;
} }
this.running = 2; this.running = 2;
final Set<Plot> plots = PS.get().getPlots(); final ConcurrentLinkedDeque<Plot> plots = new ConcurrentLinkedDeque<Plot>(PS.get().getPlots());
TaskManager.runTaskAsync(new Runnable() { TaskManager.runTaskAsync(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -226,14 +225,12 @@ public class ExpireManager {
return; return;
} }
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
Iterator<Plot> iterator = plots.iterator(); while (!plots.isEmpty()) {
while (iterator.hasNext() && System.currentTimeMillis() - start < 2) {
if (ExpireManager.this.running != 2) { if (ExpireManager.this.running != 2) {
ExpireManager.this.running = 0; ExpireManager.this.running = 0;
return; return;
} }
final Plot plot = iterator.next(); final Plot plot = plots.poll();
iterator.remove();
PlotArea area = plot.getArea(); PlotArea area = plot.getArea();
final ArrayDeque<ExpiryTask> applicable = new ArrayDeque<>(tasks); final ArrayDeque<ExpiryTask> applicable = new ArrayDeque<>(tasks);
final Collection<ExpiryTask> expired = isExpired(applicable, plot); final Collection<ExpiryTask> expired = isExpired(applicable, plot);
@ -242,7 +239,13 @@ public class ExpireManager {
} }
for (ExpiryTask expiryTask : expired) { for (ExpiryTask expiryTask : expired) {
if (!expiryTask.needsAnalysis()) { if (!expiryTask.needsAnalysis()) {
expiredTask.run(plot, this, expiryTask.requiresConfirmation()); expiredTask.run(plot, new Runnable() {
@Override
public void run() {
TaskManager.IMP.taskLaterAsync(this, 1);
}
}, expiryTask.requiresConfirmation());
return;
} }
} }
final Runnable task = this; final Runnable task = this;
@ -252,7 +255,12 @@ public class ExpireManager {
passesComplexity(changed, expired, new RunnableVal<Boolean>() { passesComplexity(changed, expired, new RunnableVal<Boolean>() {
@Override @Override
public void run(Boolean confirmation) { public void run(Boolean confirmation) {
expiredTask.run(plot, task, confirmation); expiredTask.run(plot, new Runnable() {
@Override
public void run() {
TaskManager.IMP.taskLaterAsync(task, 1);
}
}, confirmation);
} }
}, new Runnable() { }, new Runnable() {
@Override @Override
@ -280,7 +288,7 @@ public class ExpireManager {
}, new Runnable() { }, new Runnable() {
@Override @Override
public void run() { public void run() {
task.run(); TaskManager.IMP.taskLaterAsync(task, 1);
} }
}); });
} else { } else {