Class ProviderHolder<T>


  • public final class ProviderHolder<T>
    extends Object
    A holder which is designed to make it easy to hold onto a reference to a class which is outside of our ClassLoader and not cause it to not be able to reload happily. The reference to the object that is held onto here needs to not be the only one in the system or this object will be garbage collected before it probably should be. That is generally outside the purview of the service manager system though.
    Author:
    Aaron Zeckoski (azeckoski @ gmail.com)
    • Constructor Detail

      • ProviderHolder

        public ProviderHolder()
        Default constructor.
      • ProviderHolder

        public ProviderHolder​(T provider)
        Create the holder with a provider already in it.
        Parameters:
        provider - the provider to place in the holder to start
    • Method Detail

      • getProvider

        public T getProvider()
        Gets the provider out of this holder. Use the getProviderOrFail() method if you want a method that never returns null.
        Returns:
        the provider if it is still available OR null if none is set or no longer available
      • getProviderOrFail

        public T getProviderOrFail()
        Gets the provider out of this holder if it still exists. Will not return null (unlike the getProvider() method).
        Returns:
        the provider if it is available
        Throws:
        ProviderNotFoundException - if there is none available
      • setProvider

        public void setProvider​(T provider)
        Stores a provider in this holder in a ClassLoader safe way.
        Parameters:
        provider - the provider to store. If this is null then the current provider is cleared.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object