@Override public void reload() { pluginManager.clearPlugins(); commandMap.clearCommands(); resetRecipes(); List<BukkitWorker> overdueWorkers = getScheduler().getActiveWorkers(); for (BukkitWorker worker : overdueWorkers) { Plugin plugin = worker.getOwner(); String author = "<NoAuthorGiven>"; if (plugin.getDescription().getAuthors().size() > 0) { author = plugin.getDescription().getAuthors().get(0); } getLogger().log(Level.SEVERE, String.format( "Nag author: '%s' of '%s' about the following: %s", author, plugin.getDescription().getName(), "This plugin is not properly shutting down its async tasks when it is being reloaded. This may cause conflicts with the newly loaded version of the plugin" )); } loadPlugins(); enablePlugins(); }
public List<BukkitWorker> getActiveWorkers() { final ArrayList<BukkitWorker> workers = new ArrayList<BukkitWorker>(); for (final CraftTask taskObj : runners.values()) { // Iterator will be a best-effort (may fail to grab very new values) if called from an async thread if (taskObj.isSync()) { continue; } final CraftAsyncTask task = (CraftAsyncTask) taskObj; synchronized (task.getWorkers()) { // This will never have an issue with stale threads; it's state-safe workers.addAll(task.getWorkers()); } } return workers; }
public List<BukkitWorker> getActiveWorkers() { final ArrayList<BukkitWorker> workers = new ArrayList<BukkitWorker>(); for (final NukkitTask taskObj : runners.values()) { // Iterator will be a best-effort (may fail to grab very new values) if called from an async thread if (taskObj.isSync()) { continue; } final NukkitAsyncTask task = (NukkitAsyncTask) taskObj; synchronized (task.getWorkers()) { // This will never have an issue with stale threads; it's state-safe workers.addAll(task.getWorkers()); } } return workers; }
/** * Reloads TimeIsMoney. */ void reload() { // cancelling current tasks for (BukkitWorker bw: Bukkit.getScheduler().getActiveWorkers()) { if (bw.getOwner() == this) { Bukkit.getScheduler().cancelTask(bw.getTaskId()); } } Bukkit.getPluginManager().disablePlugin(this); Bukkit.getPluginManager().enablePlugin(this); }
private List<Integer> getPendingTasks() { List<Integer> pendingTasks = new ArrayList<>(); //returns only the async tasks for (BukkitWorker pendingTask : scheduler.getActiveWorkers()) { if (pendingTask.getOwner().equals(plugin) //it's not a periodic task && !scheduler.isQueued(pendingTask.getTaskId())) { pendingTasks.add(pendingTask.getTaskId()); } } return pendingTasks; }
private void mockActiveWorkers() { Plugin otherOwner = mock(Plugin.class); List<BukkitWorker> tasks = Arrays.asList( mockBukkitWorker(authMe, ACTIVE_WORKERS_ID[0], false), mockBukkitWorker(otherOwner, 3, false), mockBukkitWorker(authMe, ACTIVE_WORKERS_ID[1], false), mockBukkitWorker(authMe, 7, true), mockBukkitWorker(otherOwner, 11, true)); given(bukkitScheduler.getActiveWorkers()).willReturn(tasks); }
private BukkitWorker mockBukkitWorker(Plugin owner, int taskId, boolean isQueued) { BukkitWorker worker = mock(BukkitWorker.class); given(worker.getOwner()).willReturn(owner); given(worker.getTaskId()).willReturn(taskId); given(bukkitScheduler.isQueued(taskId)).willReturn(isQueued); return worker; }
LinkedList<BukkitWorker> getWorkers() { return workers; }
@Override public List<BukkitWorker> getActiveWorkers() { // TODO Auto-generated method stub throw new UnimplementedOperationException(); }
@Override public List<BukkitWorker> getActiveWorkers() { return delegate.getActiveWorkers(); }
@Override public List<BukkitWorker> getActiveWorkers() { return Collections.emptyList(); }
@Override public List<BukkitWorker> getActiveWorkers() { // TODO Auto-generated method stub return null; }
@Override public List<BukkitWorker> getActiveWorkers() { throw Pokkit.unsupported(); }
public List<BukkitWorker> getActiveWorkers() { // TODO talk to dark about maybe adding Async task handling to ServerTaskManager // For now return a empty array list return new ArrayList<BukkitWorker>(); }