This class can be used to load classpaths for given locations. The manager allows the classpaths to be used by multiple processes, by keeping a lock on specific files in the file system.
The manager is instantiated with a given storage directory where the classpath files will be loaded in an implementation dependent hierarchy.
As the manager allows concurrent access to classpaths from multiple processes, a scenario can emerge where one manager uses the classpath, but one tries to reload it. In this case the second manager won't be able to reload the classpath, and will use the one that is currently used by the first process. In order to ensure that a classpath is reloaded when required, the user should manually clear loaded classpaths and restart the processes necessary. This issue only happens when multiple load managers are configured to the same storage directory.
The manager spawns an owned thread which is responsible of garbage collection unreleased classpaths by the user. This doesn't replace the need to call ClassPathLock.close(), but only a safety feature.
public interface | A handle and a lock to a loaded classpath. |
public | ClassPathLoadManager( Creates a new classpath manager for the given thread group and storage directory. |
public | ClassPathLoadManager( Creates a new classpath manager with the current ThreadGroup as a base. |
public void | close() Closes this stream and releases any system resources associated
with it. |
public Path | Gets the classpath load directory for a given classpath location. |
public Path | Gets the storage directory which was used to create this classpath manager. |
public ClassPathLock | loadClassPath( Loads the classpath for the given location and places a lock on it. |
public ClassPathLock | loadDirectClassPath( Loads a classpath at the given load directory, given it was already loaded successfully by an other agent. |
null
to use the
current one. As noted in AutoCloseable.close(), cases where the
close may fail require careful attention. It is strongly advised
to relinquish the underlying resources and to internally
mark the Closeable
as closed, prior to throwing
the IOException
.
This method doesn't ensure that the directory actually exists at the returned path.
The manager will try to load the classpath if it is not locked by other processes.
If it is locked, it will return a handle to the already loaded classpath, which is shared with other processes.
This may be a previous version of the expected classes.
In order to force reloading the classes, the client should externally make sure that no processes have a lock on the specified classpath.
Only use this method if you are sure that the classpath at the specified directory has been successfully loaded by an other agent.
Example use case:
Some classes were loaded from classpath C. The implementation decides that it wants to spawn a new process P.
When P is started, it receives the classpath load directory D as an argument, and tries to load the classpath
directly using this method. It will be successful, as C already loaded the classpath successfully to the
directory D, therefore calling this method in process P with the argument directory D will likely succeed.
As a result of the above example, multiple processes will hold a lock on the classpath C.