+act add java.time.Duration support Actor javadsl (#24993)
* add java support in akka-actor module in the class Abstract.ActorContext by adding the setReceiveTimeout and CancelReceiveTimeout * add akka.actor.AbstractActor#ActorContext cancelReceiveTimeout and setReceiveTimeout to mima-excludes file * removed scala.concurrent.duration dependency in ActorDocTest and add new method expectTerminated with java.time.Duration support in TestKit * used java.time.Duration as default import
This commit is contained in:
parent
55fb092bb2
commit
759010f0cd
9 changed files with 72 additions and 33 deletions
|
|
@ -10,6 +10,7 @@ import java.util.ArrayList;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.time.Duration;
|
||||
|
||||
import akka.actor.*;
|
||||
import akka.dispatch.Mapper;
|
||||
|
|
@ -19,7 +20,6 @@ import akka.pattern.Patterns;
|
|||
import akka.util.Timeout;
|
||||
import com.typesafe.config.Config;
|
||||
import com.typesafe.config.ConfigFactory;
|
||||
import scala.concurrent.duration.Duration;
|
||||
|
||||
import static akka.japi.Util.classTag;
|
||||
import static akka.actor.SupervisorStrategy.restart;
|
||||
|
|
@ -67,7 +67,7 @@ public class FaultHandlingDocSample {
|
|||
public void preStart() {
|
||||
// If we don't get any progress within 15 seconds then the service
|
||||
// is unavailable
|
||||
getContext().setReceiveTimeout(Duration.create("15 seconds"));
|
||||
getContext().setReceiveTimeout(Duration.ofSeconds(15));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -114,7 +114,7 @@ public class FaultHandlingDocSample {
|
|||
* The Worker supervise the CounterService.
|
||||
*/
|
||||
public static class Worker extends AbstractLoggingActor {
|
||||
final Timeout askTimeout = new Timeout(Duration.create(5, "seconds"));
|
||||
final Timeout askTimeout = Timeout.create(Duration.ofSeconds(5));
|
||||
|
||||
// The sender of the initial Start message will continuously be notified
|
||||
// about progress
|
||||
|
|
@ -140,7 +140,7 @@ public class FaultHandlingDocSample {
|
|||
matchEquals(Start, x -> progressListener == null, x -> {
|
||||
progressListener = getSender();
|
||||
getContext().getSystem().scheduler().schedule(
|
||||
java.time.Duration.ZERO, java.time.Duration.ofSeconds(1L), getSelf(), Do,
|
||||
Duration.ZERO, Duration.ofSeconds(1L), getSelf(), Do,
|
||||
getContext().dispatcher(), null
|
||||
);
|
||||
}).
|
||||
|
|
@ -232,7 +232,7 @@ public class FaultHandlingDocSample {
|
|||
// Restart the storage child when StorageException is thrown.
|
||||
// After 3 restarts within 5 seconds it will be stopped.
|
||||
private static final SupervisorStrategy strategy =
|
||||
new OneForOneStrategy(3, Duration.create("5 seconds"), DeciderBuilder.
|
||||
new OneForOneStrategy(3, scala.concurrent.duration.Duration.create("5 seconds"), DeciderBuilder.
|
||||
match(StorageException.class, e -> restart()).
|
||||
matchAny(o -> escalate()).build());
|
||||
|
||||
|
|
@ -292,7 +292,7 @@ public class FaultHandlingDocSample {
|
|||
counter.tell(new UseStorage(null), getSelf());
|
||||
// Try to re-establish storage after while
|
||||
getContext().getSystem().scheduler().scheduleOnce(
|
||||
Duration.create(10, "seconds"), getSelf(), Reconnect,
|
||||
Duration.ofSeconds(10), getSelf(), Reconnect,
|
||||
getContext().dispatcher(), null);
|
||||
}).
|
||||
matchEquals(Reconnect, o -> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue