diff --git a/.github/workflows/master-2.yml b/.github/workflows/master-2.yml
index d173e78f..1f212e12 100644
--- a/.github/workflows/master-2.yml
+++ b/.github/workflows/master-2.yml
@@ -9,7 +9,7 @@ on:
jobs:
build-scan:
name: SonarCloud Scan
- runs-on: ubuntu-latest
+ runs-on: ubuntu-20.04
if: "! contains(toJSON(github.event.commits.*.message), '[skip ci]')"
steps:
@@ -35,7 +35,7 @@ jobs:
fail-fast: false
matrix:
java: [ '11', '17', '18', '21']
- os: [ ubuntu-latest, windows-latest ]
+ os: [ ubuntu-20.04, windows-latest ]
runs-on: ${{ matrix.os }}
if: "! contains(toJSON(github.event.commits.*.message), '[skip ci]')"
diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml
index 8051f1fd..ccca5724 100644
--- a/.github/workflows/master.yml
+++ b/.github/workflows/master.yml
@@ -9,7 +9,7 @@ on:
jobs:
build-scan:
name: SonarCloud Scan
- runs-on: ubuntu-latest
+ runs-on: ubuntu-20.04
if: "! contains(toJSON(github.event.commits.*.message), '[skip ci]')"
steps:
@@ -35,7 +35,7 @@ jobs:
fail-fast: false
matrix:
java: [ '8', '11', '17', '18', '21']
- os: [ ubuntu-latest, windows-latest ]
+ os: [ ubuntu-20.04, windows-latest ]
runs-on: ${{ matrix.os }}
if: "! contains(toJSON(github.event.commits.*.message), '[skip ci]')"
diff --git a/.github/workflows/staging.yml b/.github/workflows/staging.yml
new file mode 100644
index 00000000..02c74011
--- /dev/null
+++ b/.github/workflows/staging.yml
@@ -0,0 +1,47 @@
+name: Staging CI
+run-name: Staging - Java ${{ github.event.inputs.jdk }} / ${{ github.event.inputs.os }} by @${{ github.actor }}
+
+on:
+ workflow_dispatch:
+ inputs:
+ jdk:
+ description: 'JDK version'
+ required: true
+ default: '17'
+ os:
+ description: 'Operating System (ubuntu-20.04, ubuntu-latest, windows-latest)'
+ required: true
+ default: 'ubuntu-latest'
+
+jobs:
+ build-test:
+ name: Build & Test - JDK ${{ github.event.inputs.jdk }} on ${{ github.event.inputs.os }}
+
+ runs-on:
+ os: ${{ github.event.inputs.os }}
+ java: ${{ github.event.inputs.jdk }}
+
+ steps:
+ - name: Git checkout
+ uses: actions/checkout@v4
+ with:
+ fetch-depth: 0
+
+ - name: Setup Java
+ uses: actions/setup-java@v4
+ with:
+ distribution: 'temurin'
+ java-version: ${{ github.event.inputs.jdk }}
+
+ - name: Show Versions
+ run: mvn -version
+
+ - name: Cache Maven packages
+ uses: actions/cache@v4
+ with:
+ path: ~/.m2/repository
+ key: ${{ runner.os }}-m2
+ restore-keys: ${{ runner.os }}-m2
+
+ - name: Build/Test
+ run: mvn -B clean package
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index c791e57c..0931846f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -8,7 +8,7 @@
com.github.switcherapi
switcher-client
jar
- 2.0.6
+ 2.0.7-SNAPSHOT
Switcher Client
Switcher Client SDK for working with Switcher API
@@ -51,38 +51,40 @@
${java.version}
- 3.1.5
- 3.1.5
- 3.1.5
+ 3.1.6
+ 3.1.6
+ 3.1.6
2.10.1
3.14.0
3.10.0
- 2.23.0
+ 2.23.1
- 5.0.0-alpha.12
+ 5.0.0-alpha.14
5.10.2
2.2.0
- 3.12.1
- 3.3.0
- 3.2.5
- 3.1.0
- 3.10.0.2594
- 0.8.11
+ 3.13.0
+ 3.3.1
+ 3.6.3
+ 3.2.5
+ 3.4.1
+ 3.2.4
+ 3.11.0.3922
+ 0.8.12
jacoco
reuseReports
java
- **/model/**/*.java,
- **/exception/**/*.java,
- **/service/validators/RegexValidatorV8.java
-
+ **/model/**/*.java,
+ **/exception/**/*.java,
+ **/service/validators/RegexValidatorV8.java
+
@@ -102,7 +104,7 @@
jersey-media-json-jackson
${jersey-media-json-jackson.version}
-
+
com.google.code.gson
gson
@@ -242,7 +244,7 @@
org.sonarsource.scanner.maven
sonar-maven-plugin
- ${sonar.version}
+ ${sonar-maven-plugin.version}
verify
@@ -263,7 +265,7 @@
org.apache.maven.plugins
maven-source-plugin
- ${maven-source.version}
+ ${maven-source-plugin.version}
attach-sources
@@ -276,7 +278,7 @@
org.apache.maven.plugins
maven-javadoc-plugin
- ${maven-source.version}
+ ${maven-javadoc-plugin.version}
attach-javadocs
@@ -289,7 +291,7 @@
org.apache.maven.plugins
maven-gpg-plugin
- ${maven-gpg.version}
+ ${maven-gpg-plugin.version}
sign-artifacts
@@ -311,7 +313,7 @@
org.apache.maven.plugins
maven-compiler-plugin
- ${maven-compiler.version}
+ ${maven-compiler-plugin.version}
org.sonarsource.scanner.maven
@@ -321,7 +323,7 @@
org.jacoco
jacoco-maven-plugin
- ${jacoco.version}
+ ${jacoco-maven-plugin.version}
@@ -339,7 +341,7 @@
org.apache.maven.plugins
maven-surefire-plugin
- ${maven-surefire.version}
+ ${maven-surefire-plugin.version}
--add-opens java.base/java.util=ALL-UNNAMED
@@ -352,7 +354,7 @@
org.apache.maven.plugins
maven-jar-plugin
- ${maven-source.version}
+ ${maven-jar-plugin.version}
**/log4j2.properties
diff --git a/src/main/java/com/github/switcherapi/client/model/AsyncSwitcher.java b/src/main/java/com/github/switcherapi/client/model/AsyncSwitcher.java
index e1790b29..b5dbff54 100644
--- a/src/main/java/com/github/switcherapi/client/model/AsyncSwitcher.java
+++ b/src/main/java/com/github/switcherapi/client/model/AsyncSwitcher.java
@@ -6,6 +6,9 @@
import com.github.switcherapi.client.exception.SwitcherException;
import com.github.switcherapi.client.model.response.CriteriaResponse;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
/**
* Implementation handle asynchronous Criteria execution when using throttle.
*
Threads are only created when the time calculated for the next run is lower than the current time.
@@ -18,10 +21,16 @@ public class AsyncSwitcher implements Runnable {
private static final Logger logger = LogManager.getLogger(AsyncSwitcher.class);
+ private final ExecutorService executorService;
+
private Switcher switcher;
private long nextRun = 0;
+ public AsyncSwitcher() {
+ this.executorService = Executors.newCachedThreadPool();
+ }
+
/**
* Validate if next run is ready to be performed, otherwise it will skip and delegate the
* Switcher result for the Switcher history execution.
@@ -36,7 +45,7 @@ public synchronized void execute(final Switcher switcher) {
logger.debug("Running AsyncSwitcher");
this.nextRun = System.currentTimeMillis() + switcher.delay;
- new Thread(this, AsyncSwitcher.class.getName()).start();
+ this.executorService.submit(this);
}
}
@@ -44,6 +53,9 @@ public synchronized void execute(final Switcher switcher) {
public void run() {
try {
final CriteriaResponse response = switcher.getContext().executeCriteria(this.switcher);
+ switcher.getHistoryExecution().removeIf(item ->
+ this.switcher.getSwitcherKey().equals(item.getSwitcherKey()) &&
+ this.switcher.getEntry().equals(item.getEntry()));
switcher.getHistoryExecution().add(response);
} catch (SwitcherException e) {
logger.error(e);
diff --git a/src/test/java/com/github/switcherapi/playground/ClientPlayground.java b/src/test/java/com/github/switcherapi/playground/ClientPlayground.java
index b02a64f2..d5f738dd 100644
--- a/src/test/java/com/github/switcherapi/playground/ClientPlayground.java
+++ b/src/test/java/com/github/switcherapi/playground/ClientPlayground.java
@@ -32,8 +32,8 @@ public static void test() {
scheduler.scheduleAtFixedRate(() -> {
long time = System.currentTimeMillis();
- logger.info("Switcher is on: " + switcher.isItOn());
- logger.info("Time elapsed: " + (System.currentTimeMillis() - time));
+ logger.info("Switcher is on: {}", switcher.isItOn());
+ logger.info("Time elapsed: {}", System.currentTimeMillis() - time);
}, 0, 10, TimeUnit.SECONDS);
}