Skip to content

Conversation

@petruki
Copy link
Member

@petruki petruki commented Oct 15, 2025

This pull request refactors how the SwitcherBuilder and its implementation SwitcherRequest manage the history of executions, improves thread safety, and simplifies several null checks throughout the codebase. The most significant changes include moving the historyExecution map from the abstract builder to the concrete request class and switching to a thread-safe implementation, as well as updating null checks to use Objects.nonNull and Objects.isNull for clarity and consistency.

Refactoring and Thread Safety

  • Moved the historyExecution map from SwitcherBuilder to SwitcherRequest, and changed its implementation to use ConcurrentHashMap for thread safety. (src/main/java/com/switcherapi/client/model/SwitcherBuilder.java [1] [2]; src/main/java/com/switcherapi/client/model/SwitcherRequest.java [3] [4]
  • Updated the flush() method in SwitcherBuilder to be abstract, and implemented it in SwitcherRequest to clear both entry and historyExecution. (src/main/java/com/switcherapi/client/model/SwitcherBuilder.java [1]; src/main/java/com/switcherapi/client/model/SwitcherRequest.java [2]

These changes collectively improve the maintainability, thread safety, and readability of the codebase.

[Before] Operations /s in 5s

Benchmark Type Mode Score Units
ClientJavaBenchmark.testSwitcherRemoteThrottle Async thrpt 40,171,215.842 ops/s
ClientJavaBenchmark.testSwitcherLocal Local thrpt 19,689,072.262 ops/s

[After] Operations /s in 5s

Benchmark Type Mode Score Units
ClientJavaBenchmark.testSwitcherRemoteThrottle Async thrpt 109,325,445.942 ops/s
ClientJavaBenchmark.testSwitcherLocal Local thrpt 41,501,007.578 ops/s

@petruki petruki added this to the v1.9.2 milestone Oct 15, 2025
@petruki petruki self-assigned this Oct 15, 2025
@petruki petruki added the enhancement New feature or request label Oct 15, 2025
@sonarqubecloud
Copy link

@petruki petruki merged commit 4427baf into master Oct 15, 2025
32 of 35 checks passed
@petruki petruki deleted the staging branch October 15, 2025 03:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants