Class AsyncInternal


  • public final class AsyncInternal
    extends java.lang.Object
    Contains support for asynchronous invocations. The basic idea is that any code is invoked in a separate WorkflowThread. Internally it maps to a task executed by a thread pool, so there is not much overhead doing it if operation doesn't block for a long time tying a physical thread. Async allows to have asynchronous implementation of synchronous interfaces. If synchronous interface is invoked using execute(boolean, Functions.Func) then isAsync() going to return true and implementation can take non blocking path and return Promise as a result using setAsyncResult(Promise). Then it can return any value from the sync method as it is going to be ignored.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void closeAsyncInvocation()
      Closes async invocation created through initAsyncInvocation()
      static <R> Promise<R> function​(Functions.Func<R> function)
      Invokes zero argument function asynchronously.
      static <A1,​R>
      Promise<R>
      function​(Functions.Func1<A1,​R> function, A1 arg1)
      Invokes one argument function asynchronously.
      static <A1,​A2,​R>
      Promise<R>
      function​(Functions.Func2<A1,​A2,​R> function, A1 arg1, A2 arg2)
      Invokes two argument function asynchronously.
      static <A1,​A2,​A3,​R>
      Promise<R>
      function​(Functions.Func3<A1,​A2,​A3,​R> function, A1 arg1, A2 arg2, A3 arg3)
      Invokes three argument function asynchronously.
      static <A1,​A2,​A3,​A4,​R>
      Promise<R>
      function​(Functions.Func4<A1,​A2,​A3,​A4,​R> function, A1 arg1, A2 arg2, A3 arg3, A4 arg4)
      Invokes four argument function asynchronously.
      static <A1,​A2,​A3,​A4,​A5,​R>
      Promise<R>
      function​(Functions.Func5<A1,​A2,​A3,​A4,​A5,​R> function, A1 arg1, A2 arg2, A3 arg3, A4 arg4, A5 arg5)
      Invokes five argument function asynchronously.
      static <A1,​A2,​A3,​A4,​A5,​A6,​R>
      Promise<R>
      function​(Functions.Func6<A1,​A2,​A3,​A4,​A5,​A6,​R> function, A1 arg1, A2 arg2, A3 arg3, A4 arg4, A5 arg5, A6 arg6)
      Invokes six argument function asynchronously.
      static boolean isAsync()  
      static boolean isAsync​(java.lang.Object func)  
      static Promise<java.lang.Void> procedure​(Functions.Proc procedure)
      Invokes zero argument procedure asynchronously.
      static <A1> Promise<java.lang.Void> procedure​(Functions.Proc1<A1> procedure, A1 arg1)
      Invokes one argument procedure asynchronously.
      static <A1,​A2>
      Promise<java.lang.Void>
      procedure​(Functions.Proc2<A1,​A2> procedure, A1 arg1, A2 arg2)
      Invokes two argument procedure asynchronously.
      static <A1,​A2,​A3>
      Promise<java.lang.Void>
      procedure​(Functions.Proc3<A1,​A2,​A3> procedure, A1 arg1, A2 arg2, A3 arg3)
      Invokes three argument procedure asynchronously.
      static <A1,​A2,​A3,​A4>
      Promise<java.lang.Void>
      procedure​(Functions.Proc4<A1,​A2,​A3,​A4> procedure, A1 arg1, A2 arg2, A3 arg3, A4 arg4)
      Invokes four argument procedure asynchronously.
      static <A1,​A2,​A3,​A4,​A5>
      Promise<java.lang.Void>
      procedure​(Functions.Proc5<A1,​A2,​A3,​A4,​A5> procedure, A1 arg1, A2 arg2, A3 arg3, A4 arg4, A5 arg5)
      Invokes five argument procedure asynchronously.
      static <A1,​A2,​A3,​A4,​A5,​A6>
      Promise<java.lang.Void>
      procedure​(Functions.Proc6<A1,​A2,​A3,​A4,​A5,​A6> procedure, A1 arg1, A2 arg2, A3 arg3, A4 arg4, A5 arg5, A6 arg6)
      Invokes six argument procedure asynchronously.
      static <R> Promise<R> retry​(RetryOptions options, java.util.Optional<java.time.Duration> expiration, Functions.Func<Promise<R>> fn)  
      static <R> void setAsyncResult​(Promise<R> result)  
      • Methods inherited from class java.lang.Object

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

      • function

        public static <R> Promise<R> function​(Functions.Func<R> function)
        Invokes zero argument function asynchronously.
        Parameters:
        function - Function to execute asynchronously
        Returns:
        promise that contains function result or failure
      • function

        public static <A1,​R> Promise<R> function​(Functions.Func1<A1,​R> function,
                                                       A1 arg1)
        Invokes one argument function asynchronously.
        Parameters:
        function - Function to execute asynchronously
        arg1 - first function argument
        Returns:
        promise that contains function result or failure
      • function

        public static <A1,​A2,​R> Promise<R> function​(Functions.Func2<A1,​A2,​R> function,
                                                                A1 arg1,
                                                                A2 arg2)
        Invokes two argument function asynchronously.
        Parameters:
        function - Function to execute asynchronously
        arg1 - first function argument
        arg2 - second function argument
        Returns:
        promise that contains function result or failure
      • function

        public static <A1,​A2,​A3,​R> Promise<R> function​(Functions.Func3<A1,​A2,​A3,​R> function,
                                                                         A1 arg1,
                                                                         A2 arg2,
                                                                         A3 arg3)
        Invokes three argument function asynchronously.
        Parameters:
        function - Function to execute asynchronously
        arg1 - first function argument
        arg2 - second function argument
        arg3 - third function argument
        Returns:
        promise that contains function result or failure
      • function

        public static <A1,​A2,​A3,​A4,​R> Promise<R> function​(Functions.Func4<A1,​A2,​A3,​A4,​R> function,
                                                                                  A1 arg1,
                                                                                  A2 arg2,
                                                                                  A3 arg3,
                                                                                  A4 arg4)
        Invokes four argument function asynchronously.
        Parameters:
        function - Function to execute asynchronously
        arg1 - first function argument
        arg2 - second function argument
        arg3 - third function argument
        arg4 - forth function argument
        Returns:
        promise that contains function result or failure
      • function

        public static <A1,​A2,​A3,​A4,​A5,​R> Promise<R> function​(Functions.Func5<A1,​A2,​A3,​A4,​A5,​R> function,
                                                                                           A1 arg1,
                                                                                           A2 arg2,
                                                                                           A3 arg3,
                                                                                           A4 arg4,
                                                                                           A5 arg5)
        Invokes five argument function asynchronously.
        Parameters:
        function - Function to execute asynchronously
        arg1 - first function argument
        arg2 - second function argument
        arg3 - third function argument
        arg4 - forth function argument
        arg5 - fifth function argument
        Returns:
        promise that contains function result or failure
      • function

        public static <A1,​A2,​A3,​A4,​A5,​A6,​R> Promise<R> function​(Functions.Func6<A1,​A2,​A3,​A4,​A5,​A6,​R> function,
                                                                                                    A1 arg1,
                                                                                                    A2 arg2,
                                                                                                    A3 arg3,
                                                                                                    A4 arg4,
                                                                                                    A5 arg5,
                                                                                                    A6 arg6)
        Invokes six argument function asynchronously.
        Parameters:
        function - Function to execute asynchronously
        arg1 - first function argument
        arg2 - second function argument
        arg3 - third function argument
        arg4 - forth function argument
        arg5 - fifth function argument
        arg6 - sixth function argument
        Returns:
        promise that contains function result or failure
      • procedure

        public static Promise<java.lang.Void> procedure​(Functions.Proc procedure)
        Invokes zero argument procedure asynchronously.
        Parameters:
        procedure - Procedure to execute asynchronously
        Returns:
        promise that contains procedure result or failure
      • procedure

        public static <A1> Promise<java.lang.Void> procedure​(Functions.Proc1<A1> procedure,
                                                             A1 arg1)
        Invokes one argument procedure asynchronously.
        Parameters:
        procedure - Procedure to execute asynchronously
        arg1 - first procedure argument
        Returns:
        promise that contains procedure result or failure
      • procedure

        public static <A1,​A2> Promise<java.lang.Void> procedure​(Functions.Proc2<A1,​A2> procedure,
                                                                      A1 arg1,
                                                                      A2 arg2)
        Invokes two argument procedure asynchronously.
        Parameters:
        procedure - Procedure to execute asynchronously
        arg1 - first procedure argument
        arg2 - second procedure argument
        Returns:
        promise that contains procedure result or failure
      • procedure

        public static <A1,​A2,​A3> Promise<java.lang.Void> procedure​(Functions.Proc3<A1,​A2,​A3> procedure,
                                                                               A1 arg1,
                                                                               A2 arg2,
                                                                               A3 arg3)
        Invokes three argument procedure asynchronously.
        Parameters:
        procedure - Procedure to execute asynchronously
        arg1 - first procedure argument
        arg2 - second procedure argument
        arg3 - third procedure argument
        Returns:
        promise that contains procedure result or failure
      • procedure

        public static <A1,​A2,​A3,​A4> Promise<java.lang.Void> procedure​(Functions.Proc4<A1,​A2,​A3,​A4> procedure,
                                                                                        A1 arg1,
                                                                                        A2 arg2,
                                                                                        A3 arg3,
                                                                                        A4 arg4)
        Invokes four argument procedure asynchronously.
        Parameters:
        procedure - Procedure to execute asynchronously
        arg1 - first procedure argument
        arg2 - second procedure argument
        arg3 - third procedure argument
        arg4 - forth procedure argument
        Returns:
        promise that contains procedure result or failure
      • procedure

        public static <A1,​A2,​A3,​A4,​A5> Promise<java.lang.Void> procedure​(Functions.Proc5<A1,​A2,​A3,​A4,​A5> procedure,
                                                                                                 A1 arg1,
                                                                                                 A2 arg2,
                                                                                                 A3 arg3,
                                                                                                 A4 arg4,
                                                                                                 A5 arg5)
        Invokes five argument procedure asynchronously.
        Parameters:
        procedure - Procedure to execute asynchronously
        arg1 - first procedure argument
        arg2 - second procedure argument
        arg3 - third procedure argument
        arg4 - forth procedure argument
        arg5 - fifth procedure argument
        Returns:
        promise that contains procedure result or failure
      • procedure

        public static <A1,​A2,​A3,​A4,​A5,​A6> Promise<java.lang.Void> procedure​(Functions.Proc6<A1,​A2,​A3,​A4,​A5,​A6> procedure,
                                                                                                          A1 arg1,
                                                                                                          A2 arg2,
                                                                                                          A3 arg3,
                                                                                                          A4 arg4,
                                                                                                          A5 arg5,
                                                                                                          A6 arg6)
        Invokes six argument procedure asynchronously.
        Parameters:
        procedure - Procedure to execute asynchronously
        arg1 - first procedure argument
        arg2 - second procedure argument
        arg3 - third procedure argument
        arg4 - forth procedure argument
        arg5 - fifth procedure argument
        arg6 - sixth procedure argument
        Returns:
        promise that contains procedure result or failure
      • isAsync

        public static boolean isAsync​(java.lang.Object func)
      • isAsync

        public static boolean isAsync()
      • setAsyncResult

        public static <R> void setAsyncResult​(Promise<R> result)
      • closeAsyncInvocation

        public static void closeAsyncInvocation()
        Closes async invocation created through initAsyncInvocation()