Class InitializationProtector


  • public class InitializationProtector
    extends Object
    Class for avoid multiple initialization of specific value from various threads.
    • Constructor Detail

      • InitializationProtector

        public InitializationProtector()
    • Method Detail

      • protect

        public <T> T protect​(Object protectedKey,
                             Supplier<T> initializedVal,
                             IgniteThrowableRunner initializationCode)
                      throws IgniteCheckedException
        Type Parameters:
        T - Type of initialization value.
        Parameters:
        protectedKey - Unique value by which initialization code should be run only one time.
        initializedVal - Supplier for given already initialized value if it exist or null as sign that initialization required.
        initializationCode - Code for initialization value corresponding protectedKey. Should be idempotent.
        Returns:
        Initialized value.
        Throws:
        IgniteCheckedException - if initialization was failed.
      • protect

        public void protect​(Object protectedKey,
                            IgniteThrowableRunner initializationCode)
                     throws IgniteCheckedException
        It method allows to avoid simultaneous initialization from various threads.
        Parameters:
        protectedKey - Unique value by which initialization code should be run only from one thread in one time.
        initializationCode - Code for initialization value corresponding protectedKey. Should be idempotent.
        Throws:
        IgniteCheckedException - if initialization was failed.