Class Jta.Builder

java.lang.Object
com.jsgalactic.axiom.jta.Jta.Builder
Enclosing class:
Jta

public static final class Jta.Builder extends Object
Configures an immutable Jta; not thread-safe, build once at startup.
  • Method Details

    • timeout

      public Jta.Builder timeout(Duration timeout)
      Sets the transaction timeout. JTA expresses it in whole seconds, so a sub-second value is rounded up and a value under one second still asks for one second. The default leaves the provider's own timeout alone.
      Parameters:
      timeout - positive duration of at most one day
      Returns:
      this builder
      Throws:
      IllegalArgumentException - for an invalid duration
    • rollbackOn

      public Jta.Builder rollbackOn(Class<? extends Throwable> type)
      Adds a rule that rolls back when the chain throws a throwable of this type. Rules run in the order they were added and a later matching rule wins over an earlier one. The built-in rule rolls back on every throwable and stays in force when no added rule matches.
      Parameters:
      type - throwable type to match, including subclasses
      Returns:
      this builder
    • noRollbackOn

      public Jta.Builder noRollbackOn(Class<? extends Throwable> type)
      Adds a rule that commits when the chain throws a throwable of this type. The exception still propagates; this rule is for failures an application error handler maps to a successful answer, and has no effect on a problem response returned by the chain itself.
      Parameters:
      type - throwable type to match, including subclasses
      Returns:
      this builder
    • rollbackWhen

      public Jta.Builder rollbackWhen(Predicate<Throwable> predicate)
      Adds a predicate-based rollback rule; a later matching rule wins, as with rollbackOn(Class).
      Parameters:
      predicate - thread-safe test on the throwable leaving the chain
      Returns:
      this builder
    • commitWhen

      public Jta.Builder commitWhen(Predicate<Throwable> predicate)
      Adds a predicate-based commit rule; a later matching rule wins, as with noRollbackOn(Class).
      Parameters:
      predicate - thread-safe test on the throwable leaving the chain
      Returns:
      this builder
    • problemStatus

      public Jta.Builder problemStatus(TransactionFailure failure, int status)
      Overrides the problem status for one kind of transaction-boundary failure. Only 409, 503 and 500 are accepted, and every mapped response uses a fixed code from that status.
      Parameters:
      failure - the boundary operation to map
      status - 409, 503 or 500
      Returns:
      this builder
      Throws:
      IllegalArgumentException - for another status
    • build

      public Jta build()
      Builds the immutable adapter. It starts no transaction and registers no route.
      Returns:
      a thread-safe transaction boundary