feat: Add UntypedAbstractActorWithTimers (#1361)

This commit is contained in:
He-Pin(kerr) 2024-06-14 16:14:55 +08:00 committed by GitHub
parent 7647f13b9d
commit a9584ec520
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 37 additions and 1 deletions

View file

@ -40,6 +40,7 @@ import org.apache.pekko.actor.PoisonPill;
import org.apache.pekko.actor.Props;
import org.apache.pekko.actor.Terminated;
import org.apache.pekko.actor.AbstractActor;
import org.apache.pekko.actor.UntypedAbstractActorWithTimers;
import org.apache.pekko.testkit.TestActor.AutoPilot;
import java.util.List;
@ -92,7 +93,7 @@ public class TestKitDocTest extends AbstractJavaTest {
// #timer
static class TestTimerActor extends AbstractActorWithTimers {
private static Object SCHED_KEY = "SchedKey";
private static String SCHED_KEY = "SchedKey";
static final class TriggerScheduling {}
@ -107,6 +108,27 @@ public class TestKitDocTest extends AbstractJavaTest {
getTimers().startSingleTimer(SCHED_KEY, new ScheduledMessage(), Duration.ofMillis(500));
}
}
static class TestTimerUntypedActor extends UntypedAbstractActorWithTimers {
private static String SCHED_KEY = "SchedKey";
static final class TriggerScheduling {}
static final class ScheduledMessage {}
@Override
public void onReceive(Object message) throws Throwable {
if (message instanceof TriggerScheduling) {
triggerScheduling();
} else {
unhandled(message);
}
}
void triggerScheduling() {
getTimers().startSingleTimer(SCHED_KEY, new ScheduledMessage(), Duration.ofMillis(500));
}
}
// #timer
@Test