public final class ServiceClassLoader extends ClassLoader implements ClassDef.Loader, Alert.Dispatcher
Adds class libraries support. Their configuration may specify that they should be copied in a local cache for greater availability.
This implementation uses two levels of class loaders by inserting a
slightly modified URLClassLoader
between this and the original
parent.
Modifier and Type | Field and Description |
---|---|
static String |
CACHE_SECTION_NAME
Cache section name for jars.
|
static String |
CLASSLIB_DIR_PROPERTY
Contains the path to the ClassLib jars directory.
|
static String |
CLASSLIB_SERVER_PROPERTY
The URL to the ClassLib server.
|
Modifier and Type | Method and Description |
---|---|
void |
activate()
Activates this.
|
void |
addFromClassLib(ClassLibEntity classLib)
Adds URLs from a class library to the class path.
|
void |
addFromClassLibs(List<ClassLibEntity> classLibs)
Adds URLs from class libraries to the class path.
|
void |
addFromLocation(String location)
Adds URLs from a location to the class path.
|
void |
addFromLocation(URI location)
Adds URLs from a location to the class path.
|
void |
dispatchAlert(Logger.LogLevel alertLevel,
String alertName,
String info)
Dispatches an alert.
|
void |
forgetConfig(Config config)
Forgets the current config object if it is the one assumed as current.
|
Optional<Config> |
getConfig()
Gets the configuration context.
|
static ServiceClassLoader |
getInstance()
Gets a service class loader.
|
static ServiceClassLoader |
getInstance(ClassLoader parent)
Gets a service class loader.
|
URL[] |
getURLs()
Gets the search path of URLs for loading classes and resources.
|
static Optional<ServiceClassLoader> |
hideInstance()
Hides the current service class loader instance.
|
boolean |
isLoaded(String className)
Asks if a class has been loaded.
|
static void |
restoreInstance(Optional<ServiceClassLoader> serviceClassLoader)
Restores a service class loader instance.
|
void |
useConfig(Config config)
Sets the context to use for getting properties.
|
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findResources, findSystemClass, getClassLoadingLock, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, loadClass, registerAsParallelCapable, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
public static final String CACHE_SECTION_NAME
public static final String CLASSLIB_DIR_PROPERTY
public static final String CLASSLIB_SERVER_PROPERTY
@Nonnull @CheckReturnValue public static ServiceClassLoader getInstance()
If the current thread context class loader is already a service class loader, it will be returned; otherwise a new instance is returned.
@Nonnull @CheckReturnValue public static ServiceClassLoader getInstance(@Nonnull ClassLoader parent)
If the supplied parent is already a service class loader, it will be returned; otherwise a new instance is returned.
parent
- The parent class loader.@Nonnull @CheckReturnValue public static Optional<ServiceClassLoader> hideInstance()
public static void restoreInstance(@Nonnull Optional<ServiceClassLoader> serviceClassLoader)
serviceClassLoader
- The optional service class loader instance.public void activate()
public void addFromClassLib(@Nonnull ClassLibEntity classLib) throws UndefinedEntityException
Redundant additions of the same class library are ignored. Also, multiple references to the same URL are filtered.
classLib
- The class library holding the URLs.UndefinedEntityException
- When the interface is undefined.public void addFromClassLibs(@Nonnull List<ClassLibEntity> classLibs) throws UndefinedEntityException
Redundant additions of the same class library are ignored. Also, multiple references to the same URL are filtered.
classLibs
- The class libraries holding the URLs.UndefinedEntityException
- When the interface is undefined.public void addFromLocation(@Nonnull String location)
Multiple references to the same URL are filtered.
location
- The location.public void addFromLocation(@Nonnull URI location)
Multiple references to the same URL are filtered.
location
- The location.public void dispatchAlert(Logger.LogLevel alertLevel, String alertName, String info)
dispatchAlert
in interface Alert.Dispatcher
alertLevel
- The alert level.alertName
- The alert name.info
- The alert info.public void forgetConfig(@Nonnull Config config)
config
- The config object assumed as current.@Nonnull @CheckReturnValue public Optional<Config> getConfig()
@Nonnull @CheckReturnValue public URL[] getURLs()
public boolean isLoaded(String className)
isLoaded
in interface ClassDef.Loader
className
- The class name.public void useConfig(@Nonnull Config config)
config
- The config object.Copyright © 2003-2019 Serge Brisson. All Rights Reserved.