Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f9b4f21
Add named backoffs built from settings
reactivestudio Nov 8, 2026
fd6d218
Merge branch 'master' of https://github.com/VLprojects/semantic into …
reactivestudio Nov 8, 2026
c4d7f67
Name the backoff classes after what they are
reactivestudio Nov 8, 2026
8b3a208
Align backoff properties with Spring Boot conventions
reactivestudio Nov 9, 2026
f899dea
Fill the backoff registry through registrars
reactivestudio Nov 9, 2026
70d43ea
Fill the test registry without shadowing its default
reactivestudio Nov 9, 2026
c90e9a5
Fail on a backoff bean that cannot be created yet
reactivestudio Nov 9, 2026
5806f23
Map backoff properties and drop registrars
reactivestudio Nov 9, 2026
4281162
Reject every invalid default backoff field
reactivestudio Nov 9, 2026
57dd555
Fill the backoff registry through a standard customizer
reactivestudio Nov 9, 2026
0cc5831
Fill the backoff registry before other customizers
reactivestudio Nov 9, 2026
1dd6e84
Simplify the backoff factory and move the default name
reactivestudio Nov 9, 2026
63b7959
Keep only the backoff model and factory here
reactivestudio Nov 9, 2026
de18f98
Cover every field a fixed backoff rejects
reactivestudio Nov 9, 2026
4d81d86
Make backoff algorithms extensible through factory beans
reactivestudio Nov 9, 2026
5062dfd
Fail on duplicate backoff types and keep every form of an arg
reactivestudio Nov 9, 2026
874c325
Name the arg in a backoff binding failure
reactivestudio Nov 9, 2026
c945671
Register backoffs from settings through a properties registrar
reactivestudio Nov 10, 2026
0ec8822
Translate a backoff failure where it is registered
reactivestudio Nov 10, 2026
2bfcd12
Pick a backoff type by the key of its settings
reactivestudio Nov 10, 2026
15e3ec1
Read backoff settings by relaxed names from the property sources
reactivestudio Nov 10, 2026
97a7426
Keep the declared backoff name and reject values on blocks
reactivestudio Nov 10, 2026
dc93840
Reject a value on the backoff instances block
reactivestudio Nov 10, 2026
abb221a
Take the backoff type from the factory bean name and the config class…
reactivestudio Nov 10, 2026
7b07ac9
Resolve the backoff config class behind proxies and hint at naming th…
reactivestudio Nov 10, 2026
0edf966
Bind backoff settings through properties and keep the jitter in the e…
reactivestudio Nov 10, 2026
a10a7a2
Prefix the backoff settings keys with the block name and narrow the f…
reactivestudio Nov 10, 2026
7e74e6f
Pass the factory failure as the cause of the invalid backoff setting
reactivestudio Nov 10, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Align backoff properties with Spring Boot conventions
  • Loading branch information
reactivestudio committed Nov 9, 2026
commit 8b3a208d518f289627de70167a308d8151f6d428

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import pro.vlprojects.semantic.resilience.backoff.Backoff

public class BackoffRegistry(
public val default: Backoff,
private val named: Map<String, Backoff>,
private val backoffs: Map<String, Backoff>,
) {

public operator fun get(name: String): Backoff = named[name]
?: throw NoSuchElementException("No backoff is named '$name'. Named registry: ${named.keys}")
public operator fun get(name: String): Backoff = backoffs[name]
?: throw NoSuchElementException("No backoff is named '$name'. Named backoffs: ${backoffs.keys}")

public fun getOrDefault(name: String): Backoff = named[name] ?: default
public fun getOrDefault(name: String): Backoff = backoffs[name] ?: default
}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package pro.vlprojects.semantic.resilience.backoff.spring.boot.config

import pro.vlprojects.semantic.resilience.backoff.Backoff
import pro.vlprojects.semantic.resilience.backoff.spring.boot.BackoffRegistry
import pro.vlprojects.semantic.resilience.backoff.spring.boot.config.properties.BackoffConfigurationProperties
import pro.vlprojects.semantic.resilience.backoff.spring.boot.config.properties.BackoffProperties

internal class BackoffPropertiesMapper(private val properties: BackoffConfigurationProperties) {

fun mapToRegistry(beans: Map<String, Backoff>) = properties.instances
.also(::checkDefaultIsNotAnInstance)
.minus(beans.keys)
.mapValues(::createBackoff)
.plus(beans)
.let(::createRegistry)

private fun checkDefaultIsNotAnInstance(instances: Map<String, BackoffProperties>) = require(
DEFAULT_NAME !in instances,
) {
"The backoff '$DEFAULT_NAME' is not an instance: set it in the '$DEFAULT_NAME' block"
}

private fun createBackoff(instance: Map.Entry<String, BackoffProperties>) = rethrowWithName(instance.key) {
properties.default.createBackoff(instance.value)
}

private fun createRegistry(backoffs: Map<String, Backoff>): BackoffRegistry {
val default = backoffs[DEFAULT_NAME] ?: rethrowWithName(DEFAULT_NAME, properties.default::createBackoff)

return BackoffRegistry(default, backoffs + (DEFAULT_NAME to default))
}

private fun rethrowWithName(name: String, createBackoff: () -> Backoff) = try {
createBackoff()
} catch (failure: IllegalArgumentException) {
throw IllegalArgumentException("The backoff '$name' is misconfigured: ${failure.message}", failure)
}

private companion object {

const val DEFAULT_NAME = "default"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package pro.vlprojects.semantic.resilience.backoff.spring.boot.config.properties

import org.springframework.boot.context.properties.ConfigurationProperties

@ConfigurationProperties(prefix = "semantic.resilience.backoff", ignoreUnknownFields = false)
public class BackoffConfigurationProperties(
public val default: DefaultBackoffProperties = DefaultBackoffProperties(),
public val instances: Map<String, BackoffProperties> = emptyMap(),
)
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package pro.vlprojects.semantic.resilience.backoff.spring.boot
package pro.vlprojects.semantic.resilience.backoff.spring.boot.config.properties

import java.time.Duration

public class BackoffInstanceProperties(
public class BackoffProperties(
public val type: BackoffType? = null,
public val delay: Duration? = null,
public val initialDelay: Duration? = null,
Expand All @@ -11,7 +11,12 @@ public class BackoffInstanceProperties(
public val jitter: Double? = null,
) {

internal fun findFieldsUnusedBy(type: BackoffType) = when (type) {
internal fun checkAllFieldsAreUsedBy(type: BackoffType) = this
.findFieldsUnusedBy(type)
.takeIf(List<String>::isNotEmpty)
?.let { unused -> throw IllegalArgumentException("The type $type does not use $unused") }

private fun findFieldsUnusedBy(type: BackoffType) = when (type) {
BackoffType.FIXED -> listOfNotNull(
initialDelay?.let { "initial-delay" },
delayLimit?.let { "delay-limit" },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package pro.vlprojects.semantic.resilience.backoff.spring.boot.config.properties

public enum class BackoffType {

FIXED,
EXPONENTIAL,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package pro.vlprojects.semantic.resilience.backoff.spring.boot.config.properties

import pro.vlprojects.semantic.resilience.backoff.Backoff
import pro.vlprojects.semantic.resilience.backoff.ExponentialBackoff
import pro.vlprojects.semantic.resilience.backoff.FixedBackoff
import pro.vlprojects.semantic.resilience.backoff.JitteredBackoff
import pro.vlprojects.semantic.resilience.backoff.extension.jittered
import java.time.Duration

public class DefaultBackoffProperties(
public val type: BackoffType = BackoffType.EXPONENTIAL,
public val delay: Duration = Duration.ofSeconds(1),
public val initialDelay: Duration = Duration.ofSeconds(1),
public val delayLimit: Duration = Duration.ofMinutes(1),
public val multiplier: Double = 2.0,
public val jitter: Double = JitteredBackoff.DEFAULT_JITTER,
) {

internal fun createBackoff(instance: BackoffProperties = BackoffProperties()) = (instance.type ?: type)
.also(instance::checkAllFieldsAreUsedBy)
.let { resolvedType -> createUnjitteredBackoff(resolvedType, instance) }
.jittered(instance.jitter ?: jitter)

private fun createUnjitteredBackoff(resolvedType: BackoffType, instance: BackoffProperties): Backoff =
when (resolvedType) {
BackoffType.FIXED -> FixedBackoff(instance.delay ?: delay)

BackoffType.EXPONENTIAL -> ExponentialBackoff(
instance.initialDelay ?: initialDelay,
instance.delayLimit ?: delayLimit,
instance.multiplier ?: multiplier,
)
}
}
Loading
Loading