saker.build Documentation TaskDoc JavaDoc Packages
public class ClassPathLoadManager implements Closeable
Manager class for loading classpaths.

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.

Nested types
public interface
A handle and a lock to a loaded classpath.
Constructors
public
ClassPathLoadManager(ThreadGroup threadgroup, Path storagedirectory)
Creates a new classpath manager for the given thread group and storage directory.
public
ClassPathLoadManager(Path storagedirectory)
Creates a new classpath manager with the current ThreadGroup as a base.
Methods
public void
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(ClassPathLocation classpathlocation)
Loads the classpath for the given location and places a lock on it.
public ClassPathLock
loadDirectClassPath(Path classpathloaddirectory)
Loads a classpath at the given load directory, given it was already loaded successfully by an other agent.
public ClassPathLoadManager(ThreadGroup threadgroup, Path storagedirectory)
Creates a new classpath manager for the given thread group and storage directory.
threadgroupThe thread group to use when creating the garbage collecting thread, or null to use the current one.
storagedirectoryThe storage directory for the manager to use.
public ClassPathLoadManager(Path storagedirectory)
Creates a new classpath manager with the current ThreadGroup as a base.
storagedirectoryThe storage directory for the manager to use.
public void close() throws IOException
Overridden from: Closeable
Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.

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.

IOExceptionif an I/O error occurs
Gets the classpath load directory for a given classpath location.

This method doesn't ensure that the directory actually exists at the returned path.

locationThe classpath location.
The load directory.
Gets the storage directory which was used to create this classpath manager.
The storage directory.
public ClassPathLock loadClassPath(ClassPathLocation classpathlocation) throws IOException
Loads the classpath for the given location and places a lock on it.

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.

classpathlocationThe classpath location to load.
A handle to the loaded classpath.
IOExceptionIn case of I/O error.
public ClassPathLock loadDirectClassPath(Path classpathloaddirectory) throws IOException
Loads a classpath at the given load directory, given it was already loaded successfully by an other agent.

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.

classpathloaddirectoryThe path to the loaded classpath.
A handle to the loaded classpath.
IOExceptionIn case of I/O error, or the classpath is not successfully loaded at the location.