Class WeakClassCache<T>

  • Type Parameters:
    T - exact value type

    public abstract class WeakClassCache<T>
    extends java.lang.Object
    A weak class cache that instantiates does not a hold a strong reference to either the classloader or class.

    It creates the class specific data in two stages to avoid recursion.

    instantiate - creates the data
    generate - fills in the details

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.Map<java.lang.ClassLoader,​java.util.Map<java.lang.String,​java.lang.ref.WeakReference<T>>> cache
      The cache
    • Constructor Summary

      Constructors 
      Constructor Description
      WeakClassCache()  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected abstract void generate​(java.lang.Class<?> clazz, T result)
      Fill in the result
      T get​(java.lang.Class<?> clazz)
      Get the information for a class
      T get​(java.lang.String name, java.lang.ClassLoader cl)
      Get the information for a class
      protected java.util.Map<java.lang.String,​java.lang.ref.WeakReference<T>> getClassLoaderCache​(java.lang.ClassLoader cl)
      Get the cache for the classloader
      protected abstract T instantiate​(java.lang.Class<?> clazz)
      Instantiate for a class
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • cache

        protected final java.util.Map<java.lang.ClassLoader,​java.util.Map<java.lang.String,​java.lang.ref.WeakReference<T>>> cache
        The cache
    • Constructor Detail

      • WeakClassCache

        public WeakClassCache()
    • Method Detail

      • get

        public T get​(java.lang.Class<?> clazz)
        Get the information for a class
        Parameters:
        clazz - the class
        Returns:
        the info
      • get

        public T get​(java.lang.String name,
                     java.lang.ClassLoader cl)
              throws java.lang.ClassNotFoundException
        Get the information for a class
        Parameters:
        name - the name
        cl - the classloader
        Returns:
        the info
        Throws:
        java.lang.ClassNotFoundException - when the class cannot be found
      • instantiate

        protected abstract T instantiate​(java.lang.Class<?> clazz)
        Instantiate for a class
        Parameters:
        clazz - the class
        Returns:
        the result
      • generate

        protected abstract void generate​(java.lang.Class<?> clazz,
                                         T result)
        Fill in the result
        Parameters:
        clazz - the class
        result - the result
      • getClassLoaderCache

        protected java.util.Map<java.lang.String,​java.lang.ref.WeakReference<T>> getClassLoaderCache​(java.lang.ClassLoader cl)
        Get the cache for the classloader
        Parameters:
        cl - the classloader
        Returns:
        the map