Class VersionedReference<T>

  • Type Parameters:
    T - the type of the value held in this reference
    All Implemented Interfaces:
    Supplier<T>

    public class VersionedReference<T>
    extends Object
    implements Supplier<T>
    A container for a single value that is associated with the plugin cache version.

    If the plugin cache is updated, the version increments, and the provided Supplier will be invoked to get a new value on the next call to get().

    This allows consistent references to plugin-provided classes, even if the plugin is updated and a new version of the class is hot-deployed.

    Your Supplier code should always assume that the plugin cache has been refreshed since the last invocation and never cache plugin objects.

    The object type T, of course, cannot be the actual implementation in the plugin classloader, as that class will have become invalid when the plugin cache was reset. The type T should be either a JDK class or a custom interface implemented at the webapp layer.

    • Constructor Detail

      • VersionedReference

        public VersionedReference​(Supplier<? extends T> supplier)
        Creates a new VersionedThreadLocal with the given supplier.

        The initial value will not be calculated until the first call to get().

        Parameters:
        supplier - the initial value supplier
    • Method Detail

      • get

        public T get()
        Returns the current value in this reference.

        If the plugin version has changed since the value was last set, the supplier will be called to get a new value.

        Specified by:
        get in interface Supplier<T>
        Returns:
        the current value in this ThreadLocal
        See Also:
        ThreadLocal.get()