Class ContextPropagationAsyncHandler


  • public final class ContextPropagationAsyncHandler
    extends java.lang.Object
    Handling asynchronous context propagation calls. It extends transactions until the intercepted method's async return type is completed.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean tryHandleAsynchronously​(javax.transaction.TransactionManager tm, javax.transaction.Transaction tx, javax.transaction.Transactional transactional, java.util.concurrent.atomic.AtomicReference objectToHandleRef, java.lang.Class<?> returnType, RunnableWithException afterEndTransaction)
      Tries to handle asynchronously the returned type from the @Transactional call.
      • Methods inherited from class java.lang.Object

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

      • ContextPropagationAsyncHandler

        public ContextPropagationAsyncHandler()
    • Method Detail

      • tryHandleAsynchronously

        public static boolean tryHandleAsynchronously​(javax.transaction.TransactionManager tm,
                                                      javax.transaction.Transaction tx,
                                                      javax.transaction.Transactional transactional,
                                                      java.util.concurrent.atomic.AtomicReference objectToHandleRef,
                                                      java.lang.Class<?> returnType,
                                                      RunnableWithException afterEndTransaction)
                                               throws java.lang.Exception

        Tries to handle asynchronously the returned type from the @Transactional call. This CDI interceptor method checks the return type intercepted method. If it's a asynchronous "type" (objectToHandle is instanceof e.g. CompletionStage) then the transaction completion (committing/roll-backing) will be suspended until the asynchronous code finishes.

        If the interceptor returns nothing or just some "normal" return type then synchronous handling is processed. Synchronous means that the transaction is completed just here when the method annotated with @Transactional ends.

        Parameters:
        tm - transaction manager
        tx - the original transaction
        transactional - link to method which is annotated with @Transactional
        objectToHandleRef - on interceptor proceed this is the returned type which differentiate the action; method changes the object when it was handled asynchronously
        returnType -
        afterEndTransaction - a lamda invocation on transaction finalization
        Returns:
        Throws:
        java.lang.Exception - failure on async processing error happens