- java.lang.Object
-
- net.morimekta.tiny.server.TinyApplication
-
public abstract class TinyApplication extends Object
Tiny microservice application base class. Extend this class to set up the server itself, and use the staticstart(TinyApplication, String...)method to actually start it.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedTinyApplication(String applicationName)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidafterStop(TinyApplicationContext context)This method is called after the HTTP service has been stopped, but before the application exits.protected voidbeforeStop(TinyApplicationContext context)This method is called immediately when the service should start shutting down.StringgetApplicationDescription()StringgetApplicationName()StringgetApplicationVersion()protected abstract voidinitialize(net.morimekta.terminal.args.ArgParser.Builder argBuilder, TinyApplicationContext.Builder contextBuilder)This method is called during the initialization phase of setting up the tiny server.protected abstract voidonStart(TinyApplicationContext context)This method is called after the HTTP server is started, but before the service is considered "ready".protected voidsetUpUncaughtExceptionHandler()Override this method if you want to have a special uncaught exception handler, or if you need to keep some other default uncaught exception handler.static voidstart(TinyApplication app, String... args)Start the server.voidstop()Stop the server and trigger the internal stop mechanisms.
-
-
-
Constructor Detail
-
TinyApplication
protected TinyApplication(String applicationName)
-
-
Method Detail
-
setUpUncaughtExceptionHandler
protected void setUpUncaughtExceptionHandler()
Override this method if you want to have a special uncaught exception handler, or if you need to keep some other default uncaught exception handler.
-
initialize
protected abstract void initialize(net.morimekta.terminal.args.ArgParser.Builder argBuilder, TinyApplicationContext.Builder contextBuilder)This method is called during the initialization phase of setting up the tiny server. This is done before the HTTP server is started.l- Parameters:
argBuilder- The argument parser builder to parse command line arguments.contextBuilder- The application context builder.
-
onStart
protected abstract void onStart(TinyApplicationContext context) throws Exception
This method is called after the HTTP server is started, but before the service is considered "ready".- Parameters:
context- The application context.- Throws:
Exception- If starting the app failed.
-
beforeStop
protected void beforeStop(TinyApplicationContext context) throws Exception
This method is called immediately when the service should start shutting down. The service is already considered "not ready", but the HTTP server will stay alive as long as this method does not return.- Parameters:
context- The application context of the service.- Throws:
Exception- If stopping the service failed.
-
afterStop
protected void afterStop(TinyApplicationContext context) throws Exception
This method is called after the HTTP service has been stopped, but before the application exits.- Parameters:
context- The application context of the service.- Throws:
Exception- If stopping the service failed.
-
getApplicationName
public final String getApplicationName()
- Returns:
- The application name.
-
getApplicationVersion
public String getApplicationVersion()
- Returns:
- The application version.
-
getApplicationDescription
public String getApplicationDescription()
- Returns:
- The application description.
-
stop
public final void stop()
Stop the server and trigger the internal stop mechanisms.
-
start
public static void start(TinyApplication app, String... args)
Start the server.public class MyServer extends TinyServer { // implement... public static void main(String[] args) { TinyApplication.start(new MyServer(), args); } }- Parameters:
app- The tiny server application to start.args- Arguments form command line.
-
-