Class TinyApplication


  • public abstract class TinyApplication
    extends Object
    Tiny microservice application base class. Extend this class to set up the server itself, and use the static start(TinyApplication, String...) method to actually start it.
    • 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.