Running QuantumMaid
There are two different options to run a configured QuantumMaid application. If you want QuantumMaid to start the application and then block the current thread, you can run it like this:
quantumMaid.run();
If you want QuantumMaid to start the application and then return, you run it like this:
quantumMaid.runAsynchronously();
Cleaning up resources
In order to clean up allocated resources like open network ports, you can run the close()
method:
quantumMaid.close();
Because the QuantumMaid
class implements the AutoClosable
interface, you can alternatively use
a try-with-resources statement:
try (QuantumMaid quantumMaid = QuantumMaid.quantumMaid()
.get("/", (request, response) -> response.setBody("Hello World!"))
.withLocalHostEndpointOnPort(port)) {
quantumMaid.runAsynchronously();
// do something
}
Using more advanced features of QuantumMaid
In the last chapter, a lambda function was used to handle the /
route.
In case more complex features of HttpMaid and MapMaid are used,
QuantumMaid requires your application to be compiled with the -parameters
compile option.
Doing so gives QuantumMaid
runtime access to parameter names and
enables it to map parameters automatically.
Take a look
here to learn
how to configure this.
Also make sure that your IDE correctly adopted the -parameters
option.
If you need to set it manually, look
here
for IntelliJ IDEA and
here for Eclipse.