package com.ociweb.gl.benchmark;

import com.ociweb.gl.api.GreenApp;
/**
 * ************************************************************************
 * For greenlightning support, training or feature reqeusts please contact:
 *   info@objectcomputing.com   (314) 579-0066
 * ************************************************************************
 */
import com.ociweb.gl.api.GreenFramework;
import com.ociweb.gl.api.GreenRuntime;
import com.ociweb.gl.api.HTTPResponseService;
import com.ociweb.pronghorn.network.config.HTTPContentTypeDefaults;

public class FrameworkTest implements GreenApp {

    private int bindPort = 8080;
    private String host = "localhost";
    static byte[] payload = "Hello, World!".getBytes();

	@Override
    public void declareConfiguration(GreenFramework framework) {

		framework.useHTTP1xServer(bindPort,this::parallelBehavior) //standard auto-scale
    			 .setHost(host)
    			 .setMaxQueueIn(1<<14)
    	         .useInsecureServer(); //turn off TLS
        
		framework.defineRoute()
		         .path("/plaintext")
		         .routeId(Struct.PLAINTEXT_ROUTE);
		
		framework.defineRoute()
		        .path("/json")
		        .routeId(Struct.JSON_ROUTE);
		
		framework.enableTelemetry();
		
    }

	public void parallelBehavior(GreenRuntime runtime) {
		 
		//plain text is so simple we can use a lambda
		final HTTPResponseService plainResponseService = runtime.newCommandChannel().newHTTPResponseService();    	
		runtime.addRestListener((r)->{
			
			return plainResponseService.publishHTTPResponse(r, 	
						HTTPContentTypeDefaults.PLAIN,
						(w) -> w.write(payload)
					);
			
		}).includeRoutes(Struct.PLAINTEXT_ROUTE);
		
		//JSON test is a little more complex and needs a behavior object unlike the lambda above
		runtime.addRestListener(new JSONBehaviorInstance(runtime)).includeRoutes(Struct.JSON_ROUTE);

	}
	 
    @Override
    public void declareBehavior(GreenRuntime runtime) {   
    	
    }
  
}

@@ -1473,16 +1473,32 @@
 istener(
+%22PainResponder%22,
 (r)-%3E%7B%0A%09
@@ -1799,16 +1799,32 @@
 istener(
+%22JSONResponder%22,
 new JSON

update name of actors