saker.util Documentation TaskDoc JavaDoc Packages
public class ClassLoaderResolverRegistry implements ClassLoaderResolver
ClassLoaderResolver implementation that handles multiple resolvers.

Classloader resolvers can be registered in the registry, so when a resolve method is called, the registry can iterate over the registered resolvers and call them in order to fulfill the resolve request.

The resolvers registered in the registry are weakly referenced, which means that when a resolver is added, the caller should keep a strong reference to the added resolver, else the resolver may be garbage collected prematurely, and the registration is automatically removed. Weak referencing ensures that the classloaders can be garbage collected, and more error-tolerant in regards of forgetting to unregister resolvers.

The resolvers are registered with an additional identifier in the registry, which is arbitrary, but should make attempt to uniquely identify the resolver itself. Only one resolver can be registered with a specific identifier.

The registry can be constructed with a default resolver, which is called before the registered resolvers to match a resolve request.

This class is thread safe, registering and unregistering can be done concurrently from multiple threads.

Constructors
public
Creates a new instance without a default resolver.
public
Creates a new instance with the argument default classloader resolver.
Methods
public ClassLoader
Looks up a classloader for a given classloader identifier.
public String
Gets the classloader identifier for the argument classloader.
public void
register(String resolverid, ClassLoaderResolver resolver)
Registers the specified classloader resolver with the given identifier in this registry.
public String
Returns a string representation of the object.
public void
unregister(String resolverid, ClassLoaderResolver resolver)
Unregisters a previously registered classloader resolver, if found.
Creates a new instance without a default resolver.
Creates a new instance with the argument default classloader resolver.
defaultResolverThe default classloader resolver or null to not use one.
Overridden from: ClassLoaderResolver
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.

idThe classloader identifier.
The found classloader or null if this resolver didn't find an associated classloader for it.
Overridden from: ClassLoaderResolver
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.

clThe classloader to get the identifier for.
The classloader identifier, or null if this resolver doesn't recognize the argument classloader.
public void register(String resolverid, ClassLoaderResolver resolver) throws IllegalArgumentException
Registers the specified classloader resolver with the given identifier in this registry.

Callers must keep a strong reference to the registered resolver.

The resolver identifiers must not be empty or null, and must not contain the '\0' character. It is recommended to not contain any special characters in it, to ensure future compatibility.

If a resolver is already registered with the same identifier, this method doesn't overwrite it, but throws an exception. This is another reason to attempt to use unique identifier in the usage context of the registry.

resolveridThe identifier for the registered resolver.
resolverThe resolver to register.
IllegalArgumentExceptionIf the identifier is null or empty. If the identifier contains an illegal character that is reserved by the registry implementation. If a classloader resolver is already registered with the same resolver identifier.
public String toString()
Overridden from: Object
Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

 getClass().getName() + '@' + Integer.toHexString(hashCode())
 
a string representation of the object.
public void unregister(String resolverid, ClassLoaderResolver resolver)
Unregisters a previously registered classloader resolver, if found.

This method is a no-op if the argument resolver is not registered with the given identifier.

resolveridThe identifier used during registration.
resolverThe resolver to unregister.