|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.lang.ClassLoader
java.security.SecureClassLoader
java.net.URLClassLoader
com.codemonster.surinam.core.loader.GreedyClassLoader
public class GreedyClassLoader
This is Surinam's primary class loader. The goal of this loader is to be as greedy as possible
so it tries to find the class locally on it's own path before delegating to its parent. This
helps maintain the isolation necessary for Hyper-Dynamic behavior.
Rather than writing a completely custom class loader, we override a standard loader and set the parent to
null. This causes it to default to the System loader (where we should not be finding
any application classes) and therefore causes parent-level loading to fail. Then we try to load
the class locally and failing that, we delegate to the secondary parent, which we expect to succeed.
We have focused mainly on constructors to set up the URLs, we allow the inherited method to poke through
to 'add' a new URL. The end result is the ability to add to the classpath at runtime.
| Constructor Summary | |
|---|---|
GreedyClassLoader()
This is an empty constructor that adds nothing to the classpath, and has no parent loader. |
|
GreedyClassLoader(ClassLoader secondaryParent)
This is a simplified constructor that does not require the URL array for times when you are not adding anything to the classpath, is most of the time. |
|
GreedyClassLoader(URL[] urls)
Constructs a new URLClassLoader for the specified URLs using the default delegation parent ClassLoader. |
|
GreedyClassLoader(URL[] urls,
ClassLoader secondaryParent)
Constructs a new URLClassLoader for the given URLs. |
|
| Method Summary | |
|---|---|
void |
addURL(URL url)
This exposes a protected method that adds a URL to the classpath used for loading, defining and reconciling classes. |
void |
addURLs(URL[] urls)
This takes an array of URLs and iterates over them adding them to the classpath. |
String |
getName()
|
Class<?> |
loadClass(String name)
Here, we override the main class so we can call the secondary loader second. |
void |
setName(String name)
|
| Methods inherited from class java.net.URLClassLoader |
|---|
findResource, findResources, getURLs, newInstance, newInstance |
| Methods inherited from class java.lang.ClassLoader |
|---|
clearAssertionStatus, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public GreedyClassLoader()
public GreedyClassLoader(URL[] urls)
ClassLoader. The URLs will
be searched in the order specified for classes and resources after
first searching in the parent class loader. Any URL that ends with
a '/' is assumed to refer to a directory. Otherwise, the URL is
assumed to refer to a JAR file which will be downloaded and opened
as needed.
If there is a security manager, this method first
calls the security manager's checkCreateClassLoader method
to ensure creation of a class loader is allowed.
urls - the URLs from which to load classes and resourcespublic GreedyClassLoader(ClassLoader secondaryParent)
secondaryParent - This is a reference to the parent of the loader, setting this to 'null' will bypass
all class loaders and default to the System loader as the parent (as defined by the VM).
public GreedyClassLoader(URL[] urls,
ClassLoader secondaryParent)
If there is a security manager, this method first
calls the security manager's checkCreateClassLoader method
to ensure creation of a class loader is allowed.
urls - the URLs from which to load classes and resourcessecondaryParent - the parent class loader for delegation| Method Detail |
|---|
public final Class<?> loadClass(String name)
throws ClassNotFoundException
loadClass in class ClassLoadername - The name of the class to load.
ClassNotFoundExceptionpublic final void addURLs(URL[] urls)
urls - The array of URLs to be added to the classpath.public void addURL(URL url)
addURL in class URLClassLoaderurl - The URL to be added to the classpath.public String getName()
public void setName(String name)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||