Class DmxBulkhead

java.lang.Object
dmx.fun.resilience4j.DmxBulkhead

@NullMarked public final class DmxBulkhead extends Object
dmx-fun adapter for Resilience4J Bulkhead.

Executes a supplier through the bulkhead and returns a dmx-fun type instead of throwing. Configure the bulkhead using the native Resilience4J API:

DmxBulkhead bh = DmxBulkhead.of("db-pool", BulkheadConfig.ofDefaults());

Try<User>                           r1 = bh.executeTry(() -> userRepo.findById(id));
Result<User, Throwable>             r2 = bh.executeResult(() -> userRepo.findById(id));
Result<User, BulkheadFullException> r3 = bh.executeResultTyped(() -> userRepo.findById(id));
  • Method Details

    • of

      public static DmxBulkhead of(io.github.resilience4j.bulkhead.Bulkhead bulkhead)
      Wraps an existing Bulkhead instance.
      Parameters:
      bulkhead - the Resilience4J bulkhead to wrap
      Returns:
      a new DmxBulkhead backed by the given bulkhead
    • of

      public static DmxBulkhead of(String name, io.github.resilience4j.bulkhead.BulkheadConfig config)
      Creates a new Bulkhead from the given name and config, then wraps it.
      Parameters:
      name - the bulkhead name
      config - the bulkhead configuration
      Returns:
      a new DmxBulkhead backed by the created bulkhead
    • executeTry

      public <V> Try<V> executeTry(CheckedSupplier<V> supplier)
      Executes the supplier through the bulkhead.
      Type Parameters:
      V - the value type
      Parameters:
      supplier - the operation to execute
      Returns:
      Success(value) on success, Failure(BulkheadFullException) when the bulkhead is saturated, or Failure(cause) when the call itself fails
    • executeResult

      public <V> Result<V, Throwable> executeResult(CheckedSupplier<V> supplier)
      Executes the supplier through the bulkhead.
      Type Parameters:
      V - the value type
      Parameters:
      supplier - the operation to execute
      Returns:
      Ok(value) on success, Err(cause) on any failure
    • executeResultTyped

      public <V> Result<V, io.github.resilience4j.bulkhead.BulkheadFullException> executeResultTyped(CheckedSupplier<V> supplier)
      Executes the supplier through the bulkhead, surfacing bulkhead-full rejections as a typed error.
      Type Parameters:
      V - the value type
      Parameters:
      supplier - the operation to execute
      Returns:
      Ok(value) on success, Err(BulkheadFullException) when the bulkhead is saturated; other exceptions from the call propagate as unchecked