X-Git-Url: http://source.jalview.org/gitweb/?p=jalview.git;a=blobdiff_plain;f=src%2Fjalview%2Fjavascript%2FJSFunctionExec.java;h=6202cba4d849c85779fa75eacf38d40cd3b26d1f;hp=9c6f5788bf37b91012c468382f74be0b8d6de2e4;hb=17e77c3f2949a0729322b4a8d907f3f34b6a9914;hpb=0320d108d11d7cd02888a5faa1da548f35909c70 diff --git a/src/jalview/javascript/JSFunctionExec.java b/src/jalview/javascript/JSFunctionExec.java index 9c6f578..6202cba 100644 --- a/src/jalview/javascript/JSFunctionExec.java +++ b/src/jalview/javascript/JSFunctionExec.java @@ -1,35 +1,85 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9) + * Copyright (C) 2015 The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ package jalview.javascript; +import jalview.bin.JalviewLite; + import java.net.URL; import java.util.Vector; -import netscape.javascript.JSException; import netscape.javascript.JSObject; -import jalview.bin.JalviewLite; public class JSFunctionExec implements Runnable { - JalviewLite jvlite; + public JalviewLite jvlite; public JSFunctionExec(JalviewLite applet) { jvlite = applet; + + jsExecQueue = jvlite.getJsExecQueue(); + jvlite.setExecutor(this); + } + + public void finalize() + { + jvlite = null; + executor = null; + if (jsExecQueue != null) + { + jsExecQueue.clear(); + } + jsExecQueue = null; } - private static Vector jsExecQueue; + private Vector jsExecQueue; - private static Thread executor = null; + private Thread executor = null; - public static void stopQueue() + public void stopQueue() { if (jsExecQueue != null) { - Vector q = jsExecQueue; - jsExecQueue = null; - q.removeAllElements(); - executor.notify(); - executor = null; + Vector q = null; + synchronized (jsExecQueue) + { + q = jsExecQueue; + jsExecQueue = null; + } + if (q != null) + { + for (JSFunctionExec jx : q) + { + jx.jvlite = null; + + } + q.removeAllElements(); + synchronized (q) + { + q.notifyAll(); + } + } } + jvlite = null; + executor = null; } public void run() @@ -69,7 +119,7 @@ public class JSFunctionExec implements Runnable } /** - * execute a javascript callback asynchronously + * execute a javascript callback synchronously * * @param _listener * @param objects @@ -143,7 +193,8 @@ public class JSFunctionExec implements Runnable { System.err.println(jex); } - if (jex instanceof netscape.javascript.JSException) + if (jex instanceof netscape.javascript.JSException + && jvlite.jsfallbackEnabled) { jsex[0] = (netscape.javascript.JSException) jex; if (jvlite.debug) @@ -205,10 +256,9 @@ public class JSFunctionExec implements Runnable }; if (async) { - if (JSFunctionExec.executor == null) + if (executor == null) { - JSFunctionExec.jsExecQueue = new Vector(); - JSFunctionExec.executor = new Thread(new JSFunctionExec(jvlite)); + executor = new Thread(new JSFunctionExec(jvlite)); executor.start(); } synchronized (jsExecQueue) @@ -219,6 +269,7 @@ public class JSFunctionExec implements Runnable } else { + // wat for executor to notify us if it's running. exec.run(); if (jsex[0] != null) {