diff options
author | Sven Gothel <[email protected]> | 2014-01-31 05:07:19 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2014-01-31 05:07:19 +0100 |
commit | e56a94189aac504b144100fb1962a1a8b05c86af (patch) | |
tree | 874c2e2d72bba7236fad3c8ab0a2195ae44da388 /netx | |
parent | d77c4c7f9f16a74d5ea81ff372e71550a66dfcd8 (diff) |
Applet3Panel: Clarify ClassLoader role; Start Applet3Panel.loaderThread before Applet3Panel.handle (applet thread), joined at APPLET_INIT
Diffstat (limited to 'netx')
-rw-r--r-- | netx/jogamp/applet/Applet3Panel.java | 103 | ||||
-rw-r--r-- | netx/jogamp/plugin/jnlp/NetxApplet3Panel.java | 11 |
2 files changed, 64 insertions, 50 deletions
diff --git a/netx/jogamp/applet/Applet3Panel.java b/netx/jogamp/applet/Applet3Panel.java index 34d8d53..5acad4d 100644 --- a/netx/jogamp/applet/Applet3Panel.java +++ b/netx/jogamp/applet/Applet3Panel.java @@ -157,6 +157,10 @@ public abstract class Applet3Panel implements Applet3Context, Runnable { */ protected Thread handler; + /** + * The thread to use during applet loading + */ + protected volatile Thread loaderThread = null; /** * The initial applet size. @@ -171,12 +175,6 @@ public abstract class Applet3Panel implements Applet3Context, Runnable { MessageUtils mu = new MessageUtils(); /** - * The thread to use during applet loading - */ - - Thread loaderThread = null; - - /** * Flag to indicate that a loading has been cancelled */ boolean loadAbortRequest = false; @@ -199,6 +197,23 @@ public abstract class Applet3Panel implements Applet3Context, Runnable { */ final Hashtable<String, String> parameters; + /** + * Must be override with upstream plugin implementation, i.e. browser connection. + * Known implementations are {@link jogamp.plugin.applet.PluginApplet3Viewer} ! + */ + protected abstract Applet3Context getAppletContext(); + + /** + * Return true if implementing class provides it's own applet ClassLoader, otherwise false. + */ + public abstract boolean useCustomAppletClassLoader(); + + /** + * Implementing may provide it's own specific ClassLoader, see {@link #useCustomAppletClassLoader()}, otherwise null. + */ + public abstract ClassLoader getAppletClassLoader(); + + public Applet3Panel(long nativeWindowHandle, int width, int height, URL documentURL, Hashtable<String, String> parameters) { this.documentURL = documentURL; this.parameters = parameters; @@ -310,12 +325,6 @@ public abstract class Applet3Panel implements Applet3Context, Runnable { public int getStatus() { return status; } - /** - * Must be override with upstream plugin implementation, i.e. browser connection. - * Known implementations are {@link jogamp.plugin.applet.PluginApplet3Viewer} ! - */ - protected abstract Applet3Context getAppletContext(); - // // Applet3Context // @@ -698,6 +707,10 @@ public abstract class Applet3Panel implements Applet3Context, Runnable { } } + protected String getThreadName() { + return Thread.currentThread().getName(); + } + /** * Execute applet events. * Here is the state transition diagram @@ -729,8 +742,13 @@ public abstract class Applet3Panel implements Applet3Context, Runnable { */ @Override public void run() { + // Applet Thread is Applet3Panel.handle + // - Created via Applet3Panel, NetxApplet3Panel: createAppletThread() + // Applet Loader Thread is Applet3Panel.loaderThread + // - Created via Applet3Panel.run() on Applet Thread (Applet3Panel.handle) + // - Thread curThread = Thread.currentThread(); + final Thread curThread = Thread.currentThread(); if (curThread == loaderThread) { // if we are in the loader thread, cause // loading to occur. We may exit this with @@ -754,7 +772,7 @@ public abstract class Applet3Panel implements Applet3Context, Runnable { try { switch (evt.getID()) { case APPLET_LOAD: - if (!okToLoad()) { + if ( loadAbortRequested() ) { break; } // This complexity allows loading of applets to be @@ -768,20 +786,27 @@ public abstract class Applet3Panel implements Applet3Context, Runnable { if (loaderThread == null) { // REMIND: do we want a name? //System.out.println("------------------- loading applet"); - setLoaderThread(new Thread(this)); + synchronized (Applet3Panel.this) { + this.loaderThread = new Thread(this); + } loaderThread.start(); - // we get to go to sleep while this runs - loaderThread.join(); - setLoaderThread(null); } else { - // REMIND: issue an error -- this case should never - // occur. + // We kick off loading thread before applet thread in NetxApplet3Panel - no Error } break; case APPLET_INIT: - // AppletViewer "Restart" will jump from destroy method to - // init, that is why we need to check status w/ APPLET_DESTROY + if (loaderThread != null) { + // we get to go to sleep while this runs + loaderThread.join(); + synchronized (Applet3Panel.this) { + this.loaderThread = null; + } + } else { + throw new InternalError("XXX loader Thread not set! "+getThreadName()); + } + // AppletViewer "Restart" will jump from destroy method to + // init, that is why we need to check status w/ APPLET_DESTROY if (status != APPLET_LOAD && status != APPLET_DESTROY) { showAppletStatus("notloaded"); break; @@ -1104,8 +1129,8 @@ public abstract class Applet3Panel implements Applet3Context, Runnable { } - protected synchronized boolean okToLoad() { - return !loadAbortRequest; + protected synchronized boolean loadAbortRequested() { + return loadAbortRequest; } protected synchronized void clearLoadAbortRequest() { @@ -1117,11 +1142,6 @@ public abstract class Applet3Panel implements Applet3Context, Runnable { } - private synchronized void setLoaderThread(Thread loaderThread) { - this.loaderThread = loaderThread; - } - - // FIXME private EventQueue appEvtQ = null; /** @@ -1191,29 +1211,20 @@ public abstract class Applet3Panel implements Applet3Context, Runnable { } /** - * FIXME: Hack - Until knowing which CL to use .. via {@link #getClassLoader(URL, String)}. + * @see #useCustomAppletClassLoader() + * @see #getAppletClassLoader() + * @see #getClassLoader(URL, String) */ private void setClassLoader() { - final ClassLoader _loader0 = getAppletClassLoader(); - if( null != _loader0 ) { - loader = _loader0; - applet3Loader = null; - } - final ClassLoader _loader = getClassLoader(getCodeBase(), getClassLoaderCacheKey()); - if( _loader instanceof Applet3ClassLoader ) { - applet3Loader = (Applet3ClassLoader)_loader; + if( useCustomAppletClassLoader() ) { + loader = getAppletClassLoader(); } else { - applet3Loader = null; + applet3Loader = getClassLoader(getCodeBase(), getClassLoaderCacheKey()); + loader = applet3Loader; } - loader = _loader; } /** - * Implementation may provide it's own specific ClassLoader, otherwise null. - */ - public abstract ClassLoader getAppletClassLoader(); - - /** * This method actually creates an AppletClassLoader. * * It can be override by subclasses (such as the Plug-in) @@ -1226,7 +1237,7 @@ public abstract class Applet3Panel implements Applet3Context, Runnable { /** * Get a class loader. Create in a restricted context */ - synchronized ClassLoader getClassLoader(final URL codebase, final String key) { + private synchronized Applet3ClassLoader getClassLoader(final URL codebase, final String key) { Applet3ClassLoader c = classloaders.get(key); if (c == null) { final AccessControlContext acc = getAccessControlContext(codebase); diff --git a/netx/jogamp/plugin/jnlp/NetxApplet3Panel.java b/netx/jogamp/plugin/jnlp/NetxApplet3Panel.java index 875dc5a..0d79911 100644 --- a/netx/jogamp/plugin/jnlp/NetxApplet3Panel.java +++ b/netx/jogamp/plugin/jnlp/NetxApplet3Panel.java @@ -98,11 +98,8 @@ public class NetxApplet3Panel extends Applet3Panel implements SplashController { super.showAppletException(t); } - //Overriding to use Netx classloader. You might need to relax visibility - //in sun.applet.AppletPanel for runLoader(). @Override protected void runLoader() { - try { bridge = new PluginBridge(baseURL, getDocumentBase(), @@ -158,8 +155,11 @@ public class NetxApplet3Panel extends Applet3Panel implements SplashController { OutputController.getLogger().log("JNLPRuntime already initialized"); } } + final ThreadGroup tg = getThreadGroup(); + loaderThread = new Thread(tg, this, "NetxLoaderThread @ " + this.documentURL); + loaderThread.start(); - handler = new Thread(getThreadGroup(), this, "NetxPanelThread@" + this.documentURL); + handler = new Thread(tg, this, "NetxPanelThread @ " + this.documentURL); handler.start(); } @@ -177,6 +177,9 @@ public class NetxApplet3Panel extends Applet3Panel implements SplashController { } @Override + public boolean useCustomAppletClassLoader() { return true; } + + @Override public ClassLoader getAppletClassLoader() { return appInst.getClassLoader(); } |