Class Loader<CTX>
java.lang.Object
org.refcodes.loader.Loader<CTX>
- Type Parameters:
CTX- The _context type for thePlugininstances to operate on when being initialized.
- All Implemented Interfaces:
Closeable, AutoCloseable, Startable
Generic runtime loader that discovers, initializes, and destroys plugins at
runtime. It watches a configurable plugins directory, loads new JARs via a
dedicated class loader, discovers plugin implementations through Java's
ServiceLoader, and invokes their lifecycle methods with a user supplied
_context object. When a plugin JAR is removed or the JVM shuts down, the
loader calls the destroy method on all affected plugin instances and releases
their class loader.
-
Nested Class Summary
Nested classes/interfaces inherited from interface Startable
Startable.StartAutomaton, Startable.StartBuilder<B>, Startable.UncheckedStartable -
Constructor Summary
Constructors -
Method Summary
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Startable
startUnchecked
-
Constructor Details
-
Loader
public Loader(Class<? extends Plugin<CTX>> aPluginType, Path aPluginsDir, CTX aContext) throws IOException Create a new HotPlug manager.- Parameters:
aPluginType- the SPI interface class used with ServiceLoaderaPluginsDir- directory to watch for plugin jarsaContext- _context object handed into plugin.initialize(_context)- Throws:
IOException
-
-
Method Details
-
start
-
close
public void close()Stop watching and destroy all loaded plugins.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-