- 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 protected
TinyApplication(String applicationName)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
afterStart(TinyApplicationContext context)
This method is called after onStart() and the service is marked as ready, mainly in order to make simple test-validation after starting, or to start background processes that should be started *after* service is in operation.protected void
afterStop(TinyApplicationContext context)
This method is called after the HTTP service has been stopped, but before the application exits.protected void
beforeStop(TinyApplicationContext context)
This method is called immediately when the service should start shutting down.void
drain()
String
getApplicationDescription()
String
getApplicationName()
String
getApplicationVersion()
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.protected abstract void
onStart(TinyApplicationContext context)
This method is called after the HTTP server is started, but before the service is considered "ready".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.static void
start(TinyApplication app, String... args)
Start the server.static void
startUnsafe(TinyApplication app, String... args)
Same as thestart(TinyApplication, String...)
method, but will throw the exception.void
stop()
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.
-
afterStart
protected void afterStart(TinyApplicationContext context) throws Exception
This method is called after onStart() and the service is marked as ready, mainly in order to make simple test-validation after starting, or to start background processes that should be started *after* service is in operation.- 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.
-
drain
public final void drain()
-
start
public static void start(TinyApplication app, String... args)
Start the server. If the server start failed for any reason, will forcefully exit the program.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.
-
startUnsafe
public static void startUnsafe(TinyApplication app, String... args) throws Exception
Same as thestart(TinyApplication, String...)
method, but will throw the exception. Visible for testing.- Parameters:
app
- The tiny server application to start.args
- Arguments form command line.- Throws:
Exception
- If startup failed for any reason.
-
-