public static GreenRuntime run(GreenApp app, String[] args) { return run(app, args, new Runnable() { @Override public void run() { } }, new Runnable() { @Override public void run() { } }); }
public GenerateBehavior(GreenRuntime runtime, CharSequence publishTopic, AppendableProxy target, int seed) { this.target = target; this.channel = runtime.newCommandChannel().newPubSubService(publishTopic.toString()); this.rand = new Random(seed); }
@Override public void declareBehavior(GreenRuntime runtime) { runtime.addStartupListener(()->{ console.append("Hello, this message will display once at start\n"); //now we shutdown the app runtime.shutdownRuntime(); }); } }
@Override public void declareBehavior(GreenRuntime runtime) { //log the telemetry snapshot upon every pulse final GreenCommandChannel cmd = runtime.newCommandChannel(); runtime.addTimePulseListener("log",(t,i)->{ cmd.logTelemetrySnapshot(); }); }
@Override public void declareBehavior(GreenRuntime runtime) { ProductsBehavior listener = new ProductsBehavior(runtime, maxProductId, BEGIN_TOPIC, server); runtime.registerListener(listener) .includeRoutes(Struct.PRODUCT_UPDATE, listener::productUpdate) .includeRoutes(Struct.ALL_PRODUCTS, listener::productAll) .includeRoutes(Struct.PRODUCT_QUERY, listener::productQuery); int threads = 40; runtime.registerBlockingListener(new BlockingProducer(dbURL), Field.CONNECTION, threads, BEGIN_TOPIC, FINISHED_TOPIC); runtime.addPubSubListener(new RestResponder(runtime)).addSubscription(FINISHED_TOPIC); runtime.addResourceServer("/site","index.html").includeRoutesByAssoc(Struct.STATIC_PAGES); }
@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); }
runtime.addTimePulseListener("mytime",internalEgressTopicProducer); runtime.bridgeTransmission(internalEgressTopic, externalEgressTopic, mqttConfig).setQoS(transQos); runtime.bridgeSubscription(internalIngressTopic, externalIngressTopic, mqttConfig).setQoS(subscribeQos); runtime.registerListener("mqttBrokerListener",mqttBrokerListener) .addSubscription(internalIngressTopic, mqttBrokerListener::receiveMqttMessage); runtime.registerListener("EgressBehavior",doTheBusiness) .addSubscription(localTestTopic, doTheBusiness::receiveTestTopic);
@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); runtime.addResourceServer("exampleSite") .includeRoutesByAssoc(Struct.RESOURCES_EXAMPLE); runtime.addFileServer("./src/main/resources/exampleSite") .includeRoutesByAssoc(Struct.FILES_EXAMPLE);
@Override public void declareBehavior(final GreenRuntime runtime) { runtime.registerListener(new ShutdownBehavior(runtime, keyFieldId)).includeAllRoutes(); }
@Override public void declareBehavior(GreenRuntime runtime) { //in most cases the behavior need not be a local variable but we are using methods off the object //to respond to specific published topics. To do this the object is required. ProductsBehavior listener = new ProductsBehavior(runtime, maxProductId); runtime.registerListener(listener) .includeRoutes(Struct.PRODUCT_UPDATE, listener::productUpdate) .includeRoutes(Struct.ALL_PRODUCTS, listener::productAll) .includeRoutes(Struct.PRODUCT_QUERY, listener::productQuery); runtime.addResourceServer("/site","index.html").includeRoutesByAssoc(Struct.STATIC_PAGES); } }
@Override public boolean message(CharSequence topic, ChannelReader payload) { runtime.shutdownRuntime(); return true; }
@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.addRestListener(new ExternalRequest(runtime, session, "/service", HANDOFF_TOPIC)) .includeRoutesByAssoc(Struct.PROXY_ROUTE); runtime.addPubSubListener(new ExternalResponse(runtime)) .acceptHostResponses(session) .addSubscription(HANDOFF_TOPIC); runtime.addRestListener(new InternalService(runtime)) .includeRoutesByAssoc(Struct.SERIVCE_ROUTE); }
@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(GreenRuntime runtime) { runtime.addTimePulseListener(new TimeBehavior(runtime, console)); } }
public void declareParallelBehavior(GreenRuntime runtime) { final int track = trackId++; //System.out.println("declare track: "+track); TrackHTTPResponseListener responder = new TrackHTTPResponseListener(runtime, track); runtime.registerListener(RESPONDER_NAME, responder) .addSubscription(CALL_TOPIC, responder::callMessage) .acceptHostResponses(session[track]); }
public boolean triggerNextAndCount(CharSequence topic, ChannelReader payload) { if(count<6) { boolean result = channel.publishTopic(); if (result) { count++; } return result; } else { if (doShutdown) { runtime.shutdownRuntime(); } } return true; }
public ProductsBehavior(GreenRuntime runtime, int maxProductId) { responseService = runtime.newCommandChannel().newHTTPResponseService(4,256); names = new StringBuilder[maxProductId+1]; int i = names.length; while (--i>=0) { names[i] = new StringBuilder(); } quantity = new long[maxProductId+1]; disabled = new boolean[maxProductId+1]; }
public static GreenRuntime run(GreenApp app) { return run(app,new String[0]); }
public void parallelBehavior(GreenRuntime runtime) { SimpleRest restTest = new SimpleRest(runtime, jsonMaxResponseCount, jsonMaxResponseSize); runtime.registerListener("Simple", restTest) .includeRoutes(Struct.PLAINTEXT_ROUTE, restTest::plainRestRequest) .includeRoutes(Struct.JSON_ROUTE, restTest::jsonRestRequest); DBRest dbRestInstance = new DBRest(runtime, options, pipelineBits, dbCallMaxResponseCount, dbCallMaxResponseSize); runtime.registerListener("DBReadWrite", dbRestInstance) .includeRoutes(Struct.DB_SINGLE_ROUTE, dbRestInstance::singleRestRequest) .includeRoutes(Struct.DB_MULTI_ROUTE_TEXT, dbRestInstance::multiRestRequest) .includeRoutes(Struct.DB_MULTI_ROUTE_INT, dbRestInstance::multiRestRequest) .includeRoutes(Struct.UPDATES_ROUTE_TEXT, dbRestInstance::updateRestRequest) .includeRoutes(Struct.UPDATES_ROUTE_INT, dbRestInstance::updateRestRequest) .includeRoutes(Struct.FORTUNES_ROUTE, dbRestInstance::restFortuneRequest); }