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

@ -54,126 +54,166 @@ public class FSMDocTest extends AbstractJavaTest {
public static class DummyFSM extends AbstractFSM<StateType, Integer> {
Integer newData = 42;
//#alt-transition-syntax
// #alt-transition-syntax
public void handler(StateType from, StateType to) {
// handle transition here
}
//#alt-transition-syntax
// #alt-transition-syntax
{
//#modifier-syntax
when(SomeState, matchAnyEvent((msg, data) -> {
return goTo(Processing).using(newData).
forMax(Duration.ofSeconds(5)).replying(WillDo);
}));
//#modifier-syntax
// #modifier-syntax
when(
SomeState,
matchAnyEvent(
(msg, data) -> {
return goTo(Processing)
.using(newData)
.forMax(Duration.ofSeconds(5))
.replying(WillDo);
}));
// #modifier-syntax
//#NullFunction
when(SomeState, AbstractFSM.NullFunction());
//#NullFunction
// #NullFunction
when(SomeState, AbstractFSM.NullFunction());
// #NullFunction
//#transition-syntax
onTransition(
matchState(Idle, Active, () -> setTimer("timeout",
Tick, Duration.ofSeconds(1L), true)).
state(Active, null, () -> cancelTimer("timeout")).
state(null, Idle, (f, t) -> log().info("entering Idle from " + f)));
//#transition-syntax
// #transition-syntax
onTransition(
matchState(Idle, Active, () -> setTimer("timeout", Tick, Duration.ofSeconds(1L), true))
.state(Active, null, () -> cancelTimer("timeout"))
.state(null, Idle, (f, t) -> log().info("entering Idle from " + f)));
// #transition-syntax
//#alt-transition-syntax
onTransition(this::handler);
//#alt-transition-syntax
// #alt-transition-syntax
onTransition(this::handler);
// #alt-transition-syntax
//#stop-syntax
when(Error, matchEventEquals("stop", (event, data) -> {
// do cleanup ...
return stop();
}));
//#stop-syntax
// #stop-syntax
when(
Error,
matchEventEquals(
"stop",
(event, data) -> {
// do cleanup ...
return stop();
}));
// #stop-syntax
//#termination-syntax
onTermination(
matchStop(Normal(),
(state, data) -> {/* Do something here */}).
stop(Shutdown(),
(state, data) -> {/* Do something here */}).
stop(Failure.class,
(reason, state, data) -> {/* Do something here */}));
//#termination-syntax
// #termination-syntax
onTermination(
matchStop(
Normal(),
(state, data) -> {
/* Do something here */
})
.stop(
Shutdown(),
(state, data) -> {
/* Do something here */
})
.stop(
Failure.class,
(reason, state, data) -> {
/* Do something here */
}));
// #termination-syntax
//#unhandled-syntax
whenUnhandled(
matchEvent(X.class, (x, data) -> {
log().info("Received unhandled event: " + x);
return stay();
}).
anyEvent((event, data) -> {
log().warning("Received unknown event: " + event);
return goTo(Error);
}));
}
//#unhandled-syntax
// #unhandled-syntax
whenUnhandled(
matchEvent(
X.class,
(x, data) -> {
log().info("Received unhandled event: " + x);
return stay();
})
.anyEvent(
(event, data) -> {
log().warning("Received unknown event: " + event);
return goTo(Error);
}));
}
// #unhandled-syntax
}
static
//#logging-fsm
public class MyFSM extends AbstractLoggingFSM<StateType, Data> {
//#body-elided
//#logging-fsm
public
// #logging-fsm
static class MyFSM extends AbstractLoggingFSM<StateType, Data> {
// #body-elided
// #logging-fsm
ActorRef target = null;
//#logging-fsm
// #logging-fsm
@Override
public int logDepth() { return 12; }
public int logDepth() {
return 12;
}
{
onTermination(
matchStop(Failure.class, (reason, state, data) -> {
String lastEvents = getLog().mkString("\n\t");
log().warning("Failure in state " + state + " with data " + data + "\n" +
"Events leading up to this point:\n\t" + lastEvents);
//#logging-fsm
target.tell(reason.cause(), getSelf());
target.tell(state, getSelf());
target.tell(data, getSelf());
target.tell(lastEvents, getSelf());
//#logging-fsm
})
);
//...
//#logging-fsm
matchStop(
Failure.class,
(reason, state, data) -> {
String lastEvents = getLog().mkString("\n\t");
log()
.warning(
"Failure in state "
+ state
+ " with data "
+ data
+ "\n"
+ "Events leading up to this point:\n\t"
+ lastEvents);
// #logging-fsm
target.tell(reason.cause(), getSelf());
target.tell(state, getSelf());
target.tell(data, getSelf());
target.tell(lastEvents, getSelf());
// #logging-fsm
}));
// ...
// #logging-fsm
startWith(SomeState, Data.Foo);
when(SomeState, matchEvent(ActorRef.class, Data.class, (ref, data) -> {
target = ref;
target.tell("going active", getSelf());
return goTo(Active);
}));
when(Active, matchEventEquals("stop", (event, data) -> {
target.tell("stopping", getSelf());
return stop(new Failure("This is not the error you're looking for"));
}));
when(
SomeState,
matchEvent(
ActorRef.class,
Data.class,
(ref, data) -> {
target = ref;
target.tell("going active", getSelf());
return goTo(Active);
}));
when(
Active,
matchEventEquals(
"stop",
(event, data) -> {
target.tell("stopping", getSelf());
return stop(new Failure("This is not the error you're looking for"));
}));
initialize();
//#logging-fsm
// #logging-fsm
}
//#body-elided
// #body-elided
}
//#logging-fsm
// #logging-fsm
@Test
public void testLoggingFSM()
{
new TestKit(system) {{
final ActorRef logger =
system.actorOf(Props.create(MyFSM.class));
final ActorRef probe = getRef();
public void testLoggingFSM() {
new TestKit(system) {
{
final ActorRef logger = system.actorOf(Props.create(MyFSM.class));
final ActorRef probe = getRef();
logger.tell(probe, probe);
expectMsgEquals("going active");
logger.tell("stop", probe);
expectMsgEquals("stopping");
expectMsgEquals("This is not the error you're looking for");
expectMsgEquals(Active);
expectMsgEquals(Data.Foo);
String msg = expectMsgClass(String.class);
assertTrue(msg.startsWith("LogEntry(SomeState,Foo,Actor[akka://FSMDocTest/system/"));
}};
logger.tell(probe, probe);
expectMsgEquals("going active");
logger.tell("stop", probe);
expectMsgEquals("stopping");
expectMsgEquals("This is not the error you're looking for");
expectMsgEquals(Active);
expectMsgEquals(Data.Foo);
String msg = expectMsgClass(String.class);
assertTrue(msg.startsWith("LogEntry(SomeState,Foo,Actor[akka://FSMDocTest/system/"));
}
};
}
}