com.javageeks.classloader
Class PluginClassLoader

java.lang.Object
  |
  +--com.javageeks.classloader.PluginClassLoader

public class PluginClassLoader
extends java.lang.Object

PluginClassLoader is not an actual ClassLoader, but serves a role of preloading "plugin" classes into the JVM, so that the Plugins can register themselves with whatever "plugin manager" they use.

See Chapter 3 of Server-Side Java for a detailed description of how it all works together.


Inner Class Summary
static interface PluginClassLoader.Listener
          Interface to allow interested clients to be notified each time a new plugin class is loaded into the JVM.
 
Constructor Summary
PluginClassLoader(java.io.File dir)
           
PluginClassLoader(java.io.File dir, PluginClassLoader.Listener listener)
           
PluginClassLoader(java.lang.String dir)
           
PluginClassLoader(java.lang.String dir, PluginClassLoader.Listener listener)
           
 
Method Summary
static void main(java.lang.String[] args)
          Test suite--just load whatever plugins happen to be in the current directory.
 void reload(java.io.File dir, PluginClassLoader.Listener listener)
          Reload the plugins; note that the old URLClassLoader held internally is released, so if the plugin classes loaded earlier aren't in use within the app, they'll get GC'ed.
 void reload(java.lang.String dir, PluginClassLoader.Listener listener)
          Reload the plugins; note that the old URLClassLoader held internally is released, so if the plugin classes loaded earlier aren't in use within the app, they'll get GC'ed.
 void unload()
          Releases the handle on the URLClassLoader used internally; this will have the effect of allowing all the plugin classes, if not referenced anywhere else within the application, to be GC'ed the next time GC takes place.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PluginClassLoader

public PluginClassLoader(java.lang.String dir)

PluginClassLoader

public PluginClassLoader(java.lang.String dir,
                         PluginClassLoader.Listener listener)

PluginClassLoader

public PluginClassLoader(java.io.File dir)

PluginClassLoader

public PluginClassLoader(java.io.File dir,
                         PluginClassLoader.Listener listener)
Method Detail

reload

public void reload(java.lang.String dir,
                   PluginClassLoader.Listener listener)
Reload the plugins; note that the old URLClassLoader held internally is released, so if the plugin classes loaded earlier aren't in use within the app, they'll get GC'ed.

HOWEVER, if an instance of an earlier-loaded plugin class is still in existence, it will remain an entirely separate and distinct type from the type loaded in on this plass, even if the .class files are identical! This is because classes loaded into two separate (non- parentally-related) ClassLoaders are considered separate and unrelated types, even if their contents are identical.


reload

public void reload(java.io.File dir,
                   PluginClassLoader.Listener listener)
Reload the plugins; note that the old URLClassLoader held internally is released, so if the plugin classes loaded earlier aren't in use within the app, they'll get GC'ed.

HOWEVER, if an instance of an earlier-loaded plugin class is still in existence, it will remain an entirely separate and distinct type from the type loaded in on this plass, even if the .class files are identical! This is because classes loaded into two separate (non- parentally-related) ClassLoaders are considered separate and unrelated types, even if their contents are identical.


unload

public void unload()
Releases the handle on the URLClassLoader used internally; this will have the effect of allowing all the plugin classes, if not referenced anywhere else within the application, to be GC'ed the next time GC takes place.

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Test suite--just load whatever plugins happen to be in the current directory.