Class InstanceSupplierFactoryBridge<T>

  • Type Parameters:
    T - type which could be handled by Supplier and this bridge.
    All Implemented Interfaces:
    org.glassfish.hk2.api.Factory<T>

    public class InstanceSupplierFactoryBridge<T>
    extends java.lang.Object
    implements org.glassfish.hk2.api.Factory<T>
    This class is used as a bridge between HK2 Factory and JDK Supplier. Using this class Supplier is able to behave as a factory in service locator. The bridge just delegates all invocations to provided ServiceLocator and therefore all operation should be in proper scope and context.

    This bridge is dedicated to instance binding therefore underlying supplier is always only single instance.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private boolean disposable  
      private java.util.function.Supplier<T> supplier  
    • Constructor Summary

      Constructors 
      Constructor Description
      InstanceSupplierFactoryBridge​(java.util.function.Supplier<T> supplier, boolean disposable)
      Constructor for a new bridge.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void dispose​(T instance)  
      T provide()  
      • Methods inherited from class java.lang.Object

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

      • supplier

        private java.util.function.Supplier<T> supplier
      • disposable

        private boolean disposable
    • Constructor Detail

      • InstanceSupplierFactoryBridge

        InstanceSupplierFactoryBridge​(java.util.function.Supplier<T> supplier,
                                      boolean disposable)
        Constructor for a new bridge.
        Parameters:
        supplier - type which will be looked for in locator.
        disposable - flag whether the bridge is set up for disposing the created object.
    • Method Detail

      • provide

        public T provide()
        Specified by:
        provide in interface org.glassfish.hk2.api.Factory<T>
      • dispose

        public void dispose​(T instance)
        Specified by:
        dispose in interface org.glassfish.hk2.api.Factory<T>