Class Invoker
- java.lang.Object
-
- com.google.cloud.functions.invoker.runner.Invoker
-
public class Invoker extends Object
Java server that runs the user's code (a jar file) on HTTP request and an HTTP response is sent once the user's function is completed. The server accepts HTTP requests at '/' for executing the user's function, handles all HTTP methods.This class requires the following environment variables:
- PORT - defines the port on which this server listens to HTTP requests.
- FUNCTION_TARGET - defines the name of the class defining the function.
- FUNCTION_SIGNATURE_TYPE - determines whether the loaded code defines an HTTP or event function.
-
-
Constructor Summary
Constructors Constructor Description Invoker(Integer port, String functionTarget, String functionSignatureType, ClassLoader functionClassLoader)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidmain(String[] args)voidstartServer()This will start the server and wait (join) for function calls.voidstartTestServer()This will start the server and return.voidstopServer()Stop the server.
-
-
-
Constructor Detail
-
Invoker
public Invoker(Integer port, String functionTarget, String functionSignatureType, ClassLoader functionClassLoader)
-
-
Method Detail
-
startServer
public void startServer() throws ExceptionThis will start the server and wait (join) for function calls. To start the server inside a unit or integration test, usestartTestServer()instead.- Throws:
Exception- See Also:
stopServer()
-
startTestServer
public void startTestServer() throws ExceptionThis will start the server and return.This method is designed to be used for unit or integration testing only. For other use cases use
startServer().Inside a test a typical usage will be:
// Create an invoker Invoker invoker = new Invoker( 8081, "org.example.MyHttpFunction", "http", Thread.currentThread().getContextClassLoader()); // Start the test server invoker.startTestServer(); // Test the function // Stop the test server invoker.stopServer();- Throws:
Exception- See Also:
stopServer()
-
stopServer
public void stopServer() throws ExceptionStop the server.- Throws:
Exception- See Also:
startServer(),startTestServer()
-
-