saker.build Documentation TaskDoc JavaDoc Packages
public interface ClassLoaderResolver
Interface for providing functionality of identifying a ClassLoader based on a string identifier.

Implementations of this class are responsible for generating an unique identifier for a given classloader and later retrieving the associated classloader if available. The generated identifiers should be stable, meaning that even after restarting the JVM they should generated the same identifier given the same circumstances.

This class is mainly used when objects are being serialized. During serialization, a classloader identifier is written to the stream, so the serialized class can be correctly located when the stream is being read.

Implementations should strive to generate unique identifiers for a specific classloader instance. If the implementations of a class loaded by a given classloader is changed, the generated identifier should change as well. This ensures that only the class with the same implementation is loaded during deserialization.

Methods
public ClassLoader
Looks up a classloader for a given classloader identifier.
public String
Gets the classloader identifier for the argument classloader.
public abstract ClassLoader getClassLoaderForIdentifier(String identifier)
Looks up a classloader for a given classloader identifier.

Implementations can look up a classloader for a given identifier. They should examine the identifier, and based on its format look for a matching classloader. If the identifier is not recognized by this resolver, return null, so the deserializing stream can ask other resolvers to identify the classloader.

It is possible, that the resolver recognizes the format of the identifier, but doesn't find a classloader for it. This might be the case when the underlying implementation for a class has been changed, and therefore the generated classloader identifier for it as well. In this case the resolver should return null, to signal that the classloader is not found for the identifier.

Implementations of this method should not throw any exceptions.

identifierThe classloader identifier.
The found classloader or null if this resolver didn't find an associated classloader for it.
public abstract String getClassLoaderIdentifier(ClassLoader classloader)
Gets the classloader identifier for the argument classloader.

Implementations may not handle all classloaders, but only the ones they know about. If the implementation doesn't recognize a given classloader, it should return null from this method. Returning null means that the serializing stream can look at other resolvers for an appropriate identifier.

Implementations of this method should not throw any exceptions.

classloaderThe classloader to get the identifier for.
The classloader identifier, or null if this resolver doesn't recognize the argument classloader.