@Override public void timeEvent(long time, int iteration) { if(iteration%fullCycle == 0) { changeState(time, StopLight.Go); } else if(iteration%fullCycle == 8) { changeState(time, StopLight.Caution); } else if(iteration%fullCycle == 11) { changeState(time, StopLight.Stop); } if (iteration == (fullCycle*3)) { runtime.shutdownRuntime(7); } }
@Override public void declareBehavior(GreenRuntime runtime) { runtime.addTimePulseListener(new TimeBehavior(runtime, console)); } }
public static void main(String[] args) { GreenRuntime.run(new Timer(System.out, 100)); }
@Override public void declareBehavior(GreenRuntime runtime) { runtime.registerListener(new RestBehaviorEmptyResponse(runtime, console)) .includeRoutesByAssoc(Struct.EMPTY_EXAMPLE); runtime.registerListener(new RestBehaviorSmallResponse(runtime, console)) .includeRoutesByAssoc(Struct.SMALL_EXAMPLE); runtime.registerListener(new RestBehaviorLargeResponse(runtime, console)) .includeRoutesByAssoc(Struct.LARGE_EXAMPLE); runtime.registerListener(new RestBehaviorHandoff(runtime, topic)) .includeRoutesByAssoc(Struct.SPLIT_EXAMPLE); runtime.registerListener(new RestBehaviorHandoffResponder(runtime, console)) .addSubscription(topic); runtime.registerListener(new RestBehaviorJsonResponce(runtime, console)) .includeRoutesByAssoc(Struct.JSON_EXAMPLE);
@Override public void declareBehavior(GreenRuntime runtime) { HTTPGetBehaviorSingle temp = new HTTPGetBehaviorSingle(runtime, session1); runtime.addResponseListener(new HTTPResponse(console)).acceptHostResponses(session2); runtime.addStartupListener(new HTTPGetBehaviorChained(runtime, session2)); runtime.addStartupListener("startupBehavior",temp) .acceptHostResponses(session1) //this line is required to use JSON extraction even to self behavior as consumer .addSubscription("next"); runtime.addPubSubListener("shutdownBehavior",new ShutdownBehavior(runtime)).addSubscription("shutdown"); }
@Override public void declareBehavior(GreenRuntime runtime) { runtime.addStartupListener(new KickoffBehavior(runtime, target)); runtime.addPubSubListener(new GenerateBehavior(runtime, "Count", target, seed)) .addSubscription("Next"); CountBehavior counter = new CountBehavior(runtime, "Next"); runtime.registerListener(counter) .addSubscription("Count", counter::triggerNextAndCount) .addSubscription("AnExample", counter::anotherMessage); }
@Override public void declareBehavior(GreenRuntime runtime) { runtime.addTimePulseListener(new TimingBehavior(runtime, console)); runtime.addStateChangeListener(new StateChangeBehavior(console)) .includeStateChangeTo(StopLight.Go); runtime.addStateChangeListener(new StateChangeBehavior(console)) .includeStateChangeTo(StopLight.Stop); }
@Override public void declareBehavior(final GreenRuntime runtime) { runtime.registerListener(new ShutdownBehavior(runtime, keyFieldId)).includeAllRoutes(); }
public static void main(String[] args) { GreenRuntime.run(new StateMachine(System.out, 200)); }
public static void main(String[] args) { GreenRuntime.run(new MQTTClient()); }
public static void main(String[] args) { GreenRuntime.run(new Startup(System.out)); }
public static void main(String[] args) { GreenRuntime.run(new PubSub(System.out, 314-579-0066)); }
public static void main(String[] args) { GreenRuntime.run(new HTTPServer(8088,System.out, 8098, true)); }
public static void main(String[] args) { GreenRuntime.run(new HTTPClient(false, 8088),args); }
public static void main(String[] args) { GreenRuntime.run(new Shutdown()); }
@Override public boolean stateChange(StopLight oldState, StopLight newState) { console.append(" It is time to ").append(newState.name()).append('\n'); return true; //if we need to 'delay' the state change false can be returned. }
private void changeState(long time, StopLight target) { if (channel.changeStateTo(target)) { console.append(target.getColor()).append(" "); Appendables.appendEpochTime(console, time).append('\n'); } else { console.append("unable to send state change, to busy"); } }