Ref doc updates

This commit is contained in:
Janne Valkealahti
2015-03-28 18:51:19 +00:00
parent d108410005
commit 85cc2df29e
14 changed files with 561 additions and 86 deletions

View File

@@ -88,54 +88,29 @@ public class Application {
}
@Bean
public Action<States, Events> closedEntryAction() {
return new Action<States, Events>() {
@Override
public void execute(StateContext<States, Events> context) {
if (context.getTransition() != null && context.getTransition().getSource().getId() == States.CLOSED
&& context.getMessageHeader(Variables.CD) != null) {
context.getStateMachine().sendEvent(Events.PLAY);
}
}
};
public ClosedEntryAction closedEntryAction() {
return new ClosedEntryAction();
}
@Bean
public Action<States, Events> loadAction() {
return new Action<States, Events>() {
@Override
public void execute(StateContext<States, Events> context) {
Object cd = context.getMessageHeader(Variables.CD);
context.getExtendedState().getVariables().put(Variables.CD, cd);
}
};
public LoadAction loadAction() {
return new LoadAction();
}
@Bean
public Action<States, Events> playAction() {
return new Action<States, Events>() {
@Override
public void execute(StateContext<States, Events> context) {
context.getExtendedState().getVariables().put(Variables.ELAPSEDTIME, 0l);
}
};
public PlayAction playAction() {
return new PlayAction();
}
@Bean
public Guard<States, Events> playGuard() {
return new Guard<States, Events>() {
@Override
public boolean evaluate(StateContext<States, Events> context) {
ExtendedState extendedState = context.getExtendedState();
return extendedState.getVariables().get(Variables.CD) != null;
}
};
public PlayGuard playGuard() {
return new PlayGuard();
}
}
//end::snippetA[]
//tag::snippetB[]
public static enum States {
// super state of PLAYING and PAUSED
@@ -186,6 +161,52 @@ public class Application {
}
//end::snippetF[]
//tag::snippetG[]
public static class ClosedEntryAction implements Action<States, Events> {
@Override
public void execute(StateContext<States, Events> context) {
if (context.getTransition() != null
&& context.getTransition().getSource().getId() == States.CLOSED
&& context.getMessageHeader(Variables.CD) != null) {
context.getStateMachine().sendEvent(Events.PLAY);
}
}
}
//end::snippetG[]
//tag::snippetH[]
public static class LoadAction implements Action<States, Events> {
@Override
public void execute(StateContext<States, Events> context) {
Object cd = context.getMessageHeader(Variables.CD);
context.getExtendedState().getVariables().put(Variables.CD, cd);
}
}
//end::snippetH[]
//tag::snippetI[]
public static class PlayAction implements Action<States, Events> {
@Override
public void execute(StateContext<States, Events> context) {
context.getExtendedState().getVariables().put(Variables.ELAPSEDTIME, 0l);
}
}
//end::snippetI[]
//tag::snippetJ[]
public static class PlayGuard implements Guard<States, Events> {
@Override
public boolean evaluate(StateContext<States, Events> context) {
ExtendedState extendedState = context.getExtendedState();
return extendedState.getVariables().get(Variables.CD) != null;
}
}
//end::snippetJ[]
public static void main(String[] args) throws Exception {
Bootstrap.main(args);
}