public void runScript(final Script script) { script.initialize(methods, sc); for (final ScriptListener l : sc.listeners) l.scriptStarted(this, script); final ScriptManifest prop = script.getClass().getAnnotation(ScriptManifest.class); final Thread t = new Thread(scriptThreadGroup, script, "Script-" + prop.name()); addScriptToPool(script, t); t.start(); }
public void stopScript(final int id) { final Script script = sc.scripts.get(id); if (script != null) { script.deactivate(id); sc.scripts.remove(id); sc.scriptThreads.remove(id); for (final ScriptListener l : sc.listeners) l.scriptStopped(this, script); } }
public void stopScript() { final Thread curThread = Thread.currentThread(); for (int i = 0; i < sc.scripts.size(); i++) { final Script script = sc.scripts.get(i); if (script != null && script.isRunning()) { if (sc.scriptThreads.get(i) == curThread) stopScript(i); } } if (curThread == null) throw new ThreadDeath(); }
private void addScriptToPool(final Script ss, final Thread t) { for (int off = 0; off < sc.scripts.size(); ++off) { if (!sc.scripts.containsKey(off)) { sc.scripts.put(off, ss); ss.setID(off); sc.scriptThreads.put(off, t); return; } } ss.setID(sc.scripts.size()); sc.scripts.put(sc.scripts.size(), ss); sc.scriptThreads.put(sc.scriptThreads.size(), t); }
public void pauseScript(final int id) { final Script s = sc.scripts.get(id); s.setPaused(!s.isPaused()); if (s.isPaused()) for (final ScriptListener l : sc.listeners) l.scriptPaused(this, s); else for (final ScriptListener l : sc.listeners) l.scriptResumed(this, s); }