Class NexusAccessor


  • @Enhance
    public class NexusAccessor
    extends java.lang.Object
    The Nexus accessor is creating a VM-global singleton Nexus such that it can be seen by all class loaders of a virtual machine. Furthermore, it provides an API to access this global instance.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static NexusAccessor.Dispatcher DISPATCHER
      The dispatcher to use.
      private static java.lang.ref.ReferenceQueue<java.lang.ClassLoader> NO_QUEUE
      An type-safe constant for a non-operational reference queue.
      private java.lang.ref.ReferenceQueue<? super java.lang.ClassLoader> referenceQueue
      The reference queue that is notified upon a GC eligible Nexus entry or null if no such queue should be notified.
    • Constructor Summary

      Constructors 
      Constructor Description
      NexusAccessor()
      Creates a new accessor for the Nexus without any active management of stale references within a nexus.
      NexusAccessor​(java.lang.ref.ReferenceQueue<? super java.lang.ClassLoader> referenceQueue)
      Creates a new accessor for a Nexus where any GC eligible are enqueued to the supplied reference queue.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static void clean​(java.lang.ref.Reference<? extends java.lang.ClassLoader> reference)
      Removes a stale entries that are registered in the Nexus.
      static boolean isAlive()
      Checks if this NexusAccessor is capable of registering loaded type initializers.
      void register​(java.lang.String name, java.lang.ClassLoader classLoader, int identification, LoadedTypeInitializer loadedTypeInitializer)
      Registers a loaded type initializer in Byte Buddy's Nexus which is injected into the system class loader.
      • Methods inherited from class java.lang.Object

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

      • NO_QUEUE

        private static final java.lang.ref.ReferenceQueue<java.lang.ClassLoader> NO_QUEUE
        An type-safe constant for a non-operational reference queue.
      • referenceQueue

        @ValueHandling(REVERSE_NULLABILITY)
        private final java.lang.ref.ReferenceQueue<? super java.lang.ClassLoader> referenceQueue
        The reference queue that is notified upon a GC eligible Nexus entry or null if no such queue should be notified.
    • Constructor Detail

      • NexusAccessor

        public NexusAccessor()
        Creates a new accessor for the Nexus without any active management of stale references within a nexus.
      • NexusAccessor

        public NexusAccessor​(java.lang.ref.ReferenceQueue<? super java.lang.ClassLoader> referenceQueue)
        Creates a new accessor for a Nexus where any GC eligible are enqueued to the supplied reference queue. Any such enqueued reference can be explicitly removed from the nexus via the clean(Reference) method. Nexus entries can become stale if a class loader is garbage collected after a class was loaded but before a class was initialized.
        Parameters:
        referenceQueue - The reference queue onto which stale references should be enqueued or null if no reference queue should be notified.
    • Method Detail

      • isAlive

        public static boolean isAlive()
        Checks if this NexusAccessor is capable of registering loaded type initializers.
        Returns:
        true if this accessor is alive.
      • clean

        public static void clean​(java.lang.ref.Reference<? extends java.lang.ClassLoader> reference)
        Removes a stale entries that are registered in the Nexus. Entries can become stale if a class is loaded but never initialized prior to its garbage collection. As all class loaders within a nexus are only referenced weakly, such class loaders are always garbage collected. However, the initialization data stored by Byte Buddy does not become eligible which is why it needs to be cleaned explicitly.
        Parameters:
        reference - The reference to remove. References are collected via a reference queue that is supplied to the NexusAccessor.
      • register

        public void register​(java.lang.String name,
                             java.lang.ClassLoader classLoader,
                             int identification,
                             LoadedTypeInitializer loadedTypeInitializer)
        Registers a loaded type initializer in Byte Buddy's Nexus which is injected into the system class loader.
        Parameters:
        name - The binary name of the class.
        classLoader - The class's class loader.
        identification - The id used for identifying the loaded type initializer that was added to the Nexus.
        loadedTypeInitializer - The loaded type initializer to make available via the Nexus.