Programmatic API Integration Concerns

This page describes integration concerns of the Programmatic API of SmallRye Fault Tolerance.

CDI Implementation

Runtimes that provide the CDI implementation of the programmatic API don’t have to do any extra integration work. The existing integration is enough.

Standalone Implementation

The standalone implementation exposes a single integration point: the StandaloneFaultTolerance.configure() static method. This method must be called before fault tolerance is first used. It accepts a custom implementation of the Configuration interface, which allows customizing:

  • enabled(): if false, all fault tolerance strategies except fallback and thread offload are disabled

  • executor(): executor for thread offloads and other asynchronous tasks

  • metricsAdapter(): adapter for metrics, see below

When no Configuration is provided, sensible defaults are used:

  • fault tolerance is enabled unless system property MP_Fault_Tolerance_NonFallback_Enabled is set to false

  • a thread pool obtained using Executors.newCachedThreadPool() is used as an executor

  • no metrics are emitted

Users of the standalone implementation that also use an event loop based library, such as Vert.x, may integrate the event loop support as described in Event Loop.

Lifecycle

The thread pool and all other internal resources are initialized lazily, on the first use. The StandaloneFaultTolerance.shutdown() method may be used on application shutdown to shut down these internal resources.

The executor is only shut down when no Configuration was provided and SmallRye Fault Tolerance had to create an executor on its own. If Configuration was provided, the executor shutdown is left to the integrator; it is not attempted automatically.

At the end of StandaloneFaultTolerance.shutdown(), the Configuration.onShutdown() method is called.

After StandaloneFaultTolerance.shutdown(), it is not possible to reinitialize SmallRye Fault Tolerance again.

Metrics

In the standalone implementation, MicroProfile Metrics make no sense, as that is exclusively based on CDI. It is however possible to integrate with Micrometer.

The Configuration.metricsAdapter() method must be implemented and return an instance of io.smallrye.faulttolerance.standalone.MicrometerAdapter. The constructor of MicrometerAdapter accepts the Micrometer registry (MeterRegistry) to which metrics shall be emitted.