예제 #1
0
 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();
 }
예제 #2
0
 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);
   }
 }
예제 #3
0
 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();
 }
예제 #4
0
 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);
 }
예제 #5
0
 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);
 }