Package net.bytebuddy

Class TypeCache.WithInlineExpunction<S>

  • Type Parameters:
    S - The type of the key that is used for identifying stored classes per class loader. Such keys must not strongly reference any types or class loaders without potentially corrupting the garbage eligibility of stored classes. As the storage is segmented by class loader, it is normally sufficient to store types by their name.
    Enclosing class:
    TypeCache<T>

    public static class TypeCache.WithInlineExpunction<S>
    extends TypeCache<S>
    An implementation of a TypeCache where obsolete references are cleared upon any call.
    See Also:
    TypeCache
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Class<?> find​(java.lang.ClassLoader classLoader, S key)
      Finds a stored type or returns null if no type was stored.
      java.lang.Class<?> findOrInsert​(java.lang.ClassLoader classLoader, S key, java.util.concurrent.Callable<java.lang.Class<?>> builder)
      Finds an existing type or inserts a new one if the previous type was not found.
      java.lang.Class<?> findOrInsert​(java.lang.ClassLoader classLoader, S key, java.util.concurrent.Callable<java.lang.Class<?>> builder, java.lang.Object monitor)
      Finds an existing type or inserts a new one if the previous type was not found.
      java.lang.Class<?> insert​(java.lang.ClassLoader classLoader, S key, java.lang.Class<?> type)
      Inserts a new type into the cache.
      • Methods inherited from class java.lang.ref.ReferenceQueue

        poll, remove, remove
      • Methods inherited from class java.lang.Object

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

      • WithInlineExpunction

        public WithInlineExpunction​(TypeCache.Sort sort)
        Creates a new type cache with inlined expunction.
        Parameters:
        sort - The reference type to use for stored types.
    • Method Detail

      • find

        public java.lang.Class<?> find​(java.lang.ClassLoader classLoader,
                                       S key)
        Finds a stored type or returns null if no type was stored.
        Overrides:
        find in class TypeCache<S>
        Parameters:
        classLoader - The class loader for which this type is stored.
        key - The key for the type in question.
        Returns:
        The stored type or null if no type was stored.
      • insert

        public java.lang.Class<?> insert​(java.lang.ClassLoader classLoader,
                                         S key,
                                         java.lang.Class<?> type)
        Inserts a new type into the cache. If a type with the same class loader and key was inserted previously, the cache is not updated.
        Overrides:
        insert in class TypeCache<S>
        Parameters:
        classLoader - The class loader for which this type is stored.
        key - The key for the type in question.
        type - The type to insert of no previous type was stored in the cache.
        Returns:
        The supplied type or a previously submitted type for the same class loader and key combination.
      • findOrInsert

        public java.lang.Class<?> findOrInsert​(java.lang.ClassLoader classLoader,
                                               S key,
                                               java.util.concurrent.Callable<java.lang.Class<?>> builder)
        Finds an existing type or inserts a new one if the previous type was not found.
        Overrides:
        findOrInsert in class TypeCache<S>
        Parameters:
        classLoader - The class loader for which this type is stored.
        key - The key for the type in question.
        builder - A lazy creator for the type to insert of no previous type was stored in the cache.
        Returns:
        The lazily created type or a previously submitted type for the same class loader and key combination.
      • findOrInsert

        public java.lang.Class<?> findOrInsert​(java.lang.ClassLoader classLoader,
                                               S key,
                                               java.util.concurrent.Callable<java.lang.Class<?>> builder,
                                               java.lang.Object monitor)
        Finds an existing type or inserts a new one if the previous type was not found.
        Overrides:
        findOrInsert in class TypeCache<S>
        Parameters:
        classLoader - The class loader for which this type is stored.
        key - The key for the type in question.
        builder - A lazy creator for the type to insert of no previous type was stored in the cache.
        monitor - A monitor to lock before creating the lazy type.
        Returns:
        The lazily created type or a previously submitted type for the same class loader and key combination.