Formatting java codes with sbt-java-formatter.

This commit is contained in:
hepin1989 2019-01-12 04:00:53 +08:00
parent 27500001ea
commit 998c5a9285
401 changed files with 19750 additions and 17450 deletions

View file

@ -4,15 +4,15 @@
package jdocs.actor;
//#imports1
// #imports1
import akka.actor.Props;
import jdocs.AbstractJavaTest;
import java.time.Duration;
//#imports1
// #imports1
//#imports2
// #imports2
import akka.actor.Cancellable;
//#imports2
// #imports2
import akka.actor.AbstractActor;
import akka.actor.ActorRef;
@ -22,57 +22,66 @@ import akka.testkit.AkkaJUnitActorSystemResource;
import org.junit.*;
public class SchedulerDocTest extends AbstractJavaTest {
@ClassRule
public static AkkaJUnitActorSystemResource actorSystemResource = new AkkaJUnitActorSystemResource("SchedulerDocTest",
AkkaSpec.testConf());
public static AkkaJUnitActorSystemResource actorSystemResource =
new AkkaJUnitActorSystemResource("SchedulerDocTest", AkkaSpec.testConf());
private final ActorSystem system = actorSystemResource.getSystem();
private ActorRef testActor = system.actorOf(Props.create(MyActor.class));
@Test
public void scheduleOneOffTask() {
//#schedule-one-off-message
system.scheduler().scheduleOnce(Duration.ofMillis(50),
testActor, "foo", system.dispatcher(), null);
//#schedule-one-off-message
// #schedule-one-off-message
system
.scheduler()
.scheduleOnce(Duration.ofMillis(50), testActor, "foo", system.dispatcher(), null);
// #schedule-one-off-message
//#schedule-one-off-thunk
system.scheduler().scheduleOnce(Duration.ofMillis(50),
new Runnable() {
@Override
public void run() {
testActor.tell(System.currentTimeMillis(), ActorRef.noSender());
}
}, system.dispatcher());
//#schedule-one-off-thunk
// #schedule-one-off-thunk
system
.scheduler()
.scheduleOnce(
Duration.ofMillis(50),
new Runnable() {
@Override
public void run() {
testActor.tell(System.currentTimeMillis(), ActorRef.noSender());
}
},
system.dispatcher());
// #schedule-one-off-thunk
}
@Test
public void scheduleRecurringTask() {
//#schedule-recurring
// #schedule-recurring
class Ticker extends AbstractActor {
@Override
public Receive createReceive() {
return receiveBuilder()
.matchEquals("Tick", m -> {
// Do someting
})
.build();
.matchEquals(
"Tick",
m -> {
// Do someting
})
.build();
}
}
ActorRef tickActor = system.actorOf(Props.create(Ticker.class, this));
//This will schedule to send the Tick-message
//to the tickActor after 0ms repeating every 50ms
Cancellable cancellable = system.scheduler().schedule(Duration.ZERO,
Duration.ofMillis(50), tickActor, "Tick",
system.dispatcher(), null);
// This will schedule to send the Tick-message
// to the tickActor after 0ms repeating every 50ms
Cancellable cancellable =
system
.scheduler()
.schedule(
Duration.ZERO, Duration.ofMillis(50), tickActor, "Tick", system.dispatcher(), null);
//This cancels further Ticks to be sent
// This cancels further Ticks to be sent
cancellable.cancel();
//#schedule-recurring
// #schedule-recurring
system.stop(tickActor);
}
}