This is an automated email from the ASF dual-hosted git repository.
hepin pushed a commit to branch jfunction
in repository https://gitbox.apache.org/repos/asf/pekko.git
The following commit(s) were added to refs/heads/jfunction by this push:
new 6b1362db5a chore: Make use of japi.funtion.* in Patterns
6b1362db5a is described below
commit 6b1362db5ac766ab112a9fd8b7842b2f45d8ff77
Author: He-Pin <[email protected]>
AuthorDate: Sat Sep 13 13:14:22 2025 +0800
chore: Make use of japi.funtion.* in Patterns
---
.../org/apache/pekko/japi/function/IntFunction.java | 18 ++++++++++++++++++
.../org/apache/pekko/japi/function/package-info.java | 2 ++
.../javaapi-functions.excludes | 1 +
.../scala/org/apache/pekko/pattern/Patterns.scala | 4 ++--
docs/src/test/java/jdocs/future/FutureDocTest.java | 19 +++++++++++++++++++
5 files changed, 42 insertions(+), 2 deletions(-)
diff --git
a/actor/src/main/java/org/apache/pekko/japi/function/IntFunction.java
b/actor/src/main/java/org/apache/pekko/japi/function/IntFunction.java
new file mode 100644
index 0000000000..8e01f8411e
--- /dev/null
+++ b/actor/src/main/java/org/apache/pekko/japi/function/IntFunction.java
@@ -0,0 +1,18 @@
+package org.apache.pekko.japi.function;
+
+/**
+ * Int function that can throw exceptions.
+ *
+ * @since 2.0.0
+ */
+@FunctionalInterface
+public interface IntFunction<R> {
+ /**
+ * Applies this function to the given argument.
+ *
+ * @param value the function argument
+ * @return the function result
+ * @throws Throwable if an error occurs
+ */
+ R apply(int value) throws Throwable;
+}
diff --git
a/actor/src/main/java/org/apache/pekko/japi/function/package-info.java
b/actor/src/main/java/org/apache/pekko/japi/function/package-info.java
new file mode 100644
index 0000000000..8bd77d4fd4
--- /dev/null
+++ b/actor/src/main/java/org/apache/pekko/japi/function/package-info.java
@@ -0,0 +1,2 @@
+/** Java API for functional programming in Pekko. */
+package org.apache.pekko.japi.function;
diff --git
a/actor/src/main/mima-filters/2.0.x.backwards.excludes/javaapi-functions.excludes
b/actor/src/main/mima-filters/2.0.x.backwards.excludes/javaapi-functions.excludes
index 12cfcac7a2..755be7d74e 100644
---
a/actor/src/main/mima-filters/2.0.x.backwards.excludes/javaapi-functions.excludes
+++
b/actor/src/main/mima-filters/2.0.x.backwards.excludes/javaapi-functions.excludes
@@ -35,4 +35,5 @@
ProblemFilters.exclude[MissingClassProblem]("org.apache.pekko.japi.Predicate")
ProblemFilters.exclude[MissingClassProblem]("org.apache.pekko.japi.Procedure")
ProblemFilters.exclude[IncompatibleMethTypeProblem]("org.apache.pekko.pattern.Patterns.askWithReplyTo")
ProblemFilters.exclude[IncompatibleMethTypeProblem]("org.apache.pekko.serialization.SerializationSetup.create")
+ProblemFilters.exclude[IncompatibleMethTypeProblem]("org.apache.pekko.pattern.Patterns.retry")
diff --git a/actor/src/main/scala/org/apache/pekko/pattern/Patterns.scala
b/actor/src/main/scala/org/apache/pekko/pattern/Patterns.scala
index b20e37cb9d..de4dd2fab2 100644
--- a/actor/src/main/scala/org/apache/pekko/pattern/Patterns.scala
+++ b/actor/src/main/scala/org/apache/pekko/pattern/Patterns.scala
@@ -812,7 +812,7 @@ object Patterns {
def retry[T](
attempt: Callable[CompletionStage[T]],
attempts: Int,
- delayFunction:
java.util.function.IntFunction[Optional[java.time.Duration]],
+ delayFunction: japi.function.IntFunction[Optional[java.time.Duration]],
scheduler: Scheduler,
context: ExecutionContext): CompletionStage[T] = {
import pekko.util.OptionConverters._
@@ -853,7 +853,7 @@ object Patterns {
attempt: Callable[CompletionStage[T]],
shouldRetry: japi.function.Predicate2[T, Throwable],
attempts: Int,
- delayFunction:
java.util.function.IntFunction[Optional[java.time.Duration]],
+ delayFunction: japi.function.IntFunction[Optional[java.time.Duration]],
scheduler: Scheduler,
context: ExecutionContext): CompletionStage[T] = {
import pekko.util.OptionConverters._
diff --git a/docs/src/test/java/jdocs/future/FutureDocTest.java
b/docs/src/test/java/jdocs/future/FutureDocTest.java
index 82b80eefe3..80c88e9cbc 100644
--- a/docs/src/test/java/jdocs/future/FutureDocTest.java
+++ b/docs/src/test/java/jdocs/future/FutureDocTest.java
@@ -24,6 +24,7 @@ import org.junit.Test;
import java.time.Duration;
import java.util.Arrays;
+import java.util.Optional;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
@@ -97,4 +98,22 @@ public class FutureDocTest extends AbstractJavaTest {
retriedFuture.toCompletableFuture().get(2, SECONDS);
}
+
+ @Test
+ public void useRetryWithPredicateWithIntFunction() throws Exception {
+ // #retry
+ Callable<CompletionStage<String>> attempt = () ->
CompletableFuture.completedFuture("test");
+
+ CompletionStage<String> retriedFuture =
+ Patterns.retry(
+ attempt,
+ (notUsed, e) -> e != null,
+ 3,
+ current -> Optional.of(java.time.Duration.ofMillis(200)),
+ system.classicSystem().scheduler(),
+ system.executionContext());
+ // #retry
+
+ retriedFuture.toCompletableFuture().get(2, SECONDS);
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]