public void run() { try { if (!lock.compareAndSet(false, true)) return; BukkitScheduler bs = plugin.getServer().getScheduler(); if (bs.isQueued(AutoUpdate.this.pid) || bs.isCurrentlyRunning(AutoUpdate.this.pid)) bs.cancelTask(AutoUpdate.this.pid); if (restart) AutoUpdate.this.pid = bs.scheduleAsyncRepeatingTask(plugin, AutoUpdate.this, 5L, delay); else AutoUpdate.this.pid = -1; lock.set(false); bs.cancelTask(pid); } catch (Throwable t) { printStackTraceSync(t, false); } }
/** * Alert the plugin that changes have been made to mines, but wait 60 seconds before we save. This * process saves on disk I/O by waiting until a long string of changes have finished before * writing to disk. */ public void buffSave() { BukkitScheduler scheduler = getServer().getScheduler(); if (saveTaskId != -1) { // Cancel old task scheduler.cancelTask(saveTaskId); } // Schedule save final MineResetLite plugin = this; scheduler.scheduleSyncDelayedTask( this, new Runnable() { public void run() { plugin.save(); } }, 60 * 20L); }
private void printStackTraceSync(Throwable t, boolean expected) { BukkitScheduler bs = plugin.getServer().getScheduler(); try { String prefix = plugin.getName() + " [AutoUpdate] "; StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); t.printStackTrace(pw); String[] sts = sw.toString().replace("\r", "").split("\n"); String[] out; if (expected) out = new String[sts.length + 31]; else out = new String[sts.length + 33]; out[0] = prefix; out[1] = prefix + "Internal error!"; out[2] = prefix + "If this bug hasn't been reported please open a ticket at http://dev.bukkit.org/server-mods/iFail"; out[3] = prefix + "Include the following into your bug report:"; out[4] = prefix + " ======= SNIP HERE ======="; int i = 5; for (; i - 5 < sts.length; i++) out[i] = prefix + sts[i - 5]; out[++i] = prefix + " ======= DUMP ======="; out[++i] = prefix + "version : " + version; out[++i] = prefix + "delay : " + delay; out[++i] = prefix + "ymlPrefix : " + ymlPrefix; out[++i] = prefix + "ymlSuffix : " + ymlSuffix; out[++i] = prefix + "bukkitdevPrefix: " + bukkitdevPrefix; out[++i] = prefix + "bukkitdevSuffix: " + bukkitdevSuffix; out[++i] = prefix + "bukkitdevSlug : " + bukkitdevSlug; out[++i] = prefix + "COLOR_INFO : " + COLOR_INFO.name(); out[++i] = prefix + "COLO_OK : " + COLOR_OK.name(); out[++i] = prefix + "COLOR_ERROR : " + COLOR_ERROR.name(); out[++i] = prefix + "bukget : " + bukget; out[++i] = prefix + "bukgetFallback : " + bukgetFallback; out[++i] = prefix + "pid : " + pid; out[++i] = prefix + "av : " + av; out[++i] = prefix + "config : " + config; out[++i] = prefix + "lock : " + lock.get(); out[++i] = prefix + "needUpdate : " + needUpdate; out[++i] = prefix + "updatePending : " + updatePending; out[++i] = prefix + "UpdateUrl : " + updateURL; out[++i] = prefix + "updateVersion : " + updateVersion; out[++i] = prefix + "pluginURL : " + pluginURL; out[++i] = prefix + "type : " + type; out[++i] = prefix + " ======= SNIP HERE ======="; out[++i] = prefix; if (!expected) { out[++i] = prefix + "DISABLING UPDATER!"; out[++i] = prefix; } bs.scheduleSyncDelayedTask(plugin, new SyncMessageDelayer(null, out)); } catch (Throwable e) // This prevents endless loops. { e.printStackTrace(); } if (!expected) { bs.cancelTask(pid); bs.scheduleAsyncDelayedTask( plugin, new Runnable() { public void run() { while (!lock.compareAndSet(false, true)) { try { Thread.sleep(1L); } catch (InterruptedException e) { } } pid = -1; config = null; needUpdate = updatePending = false; updateURL = updateVersion = pluginURL = type = null; } }); } }
public void cancelTasks(BukkitScheduler scheduler) { for (Integer id : getTaskIds()) scheduler.cancelTask(id); clearTaskIds(); }