Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.19 KB | None | 0 0
  1. package com.nital;
  2.  
  3. import java.util.logging.Logger;
  4.  
  5. import com.nital.bundle.ReplayingActivator;
  6.  
  7. /**
  8.  * This class represents the application that will form the base of
  9.  * other source files which will be able to run within this program.
  10.  * @author Thomas Nappo
  11.  */
  12. public final class Server extends ReplayingActivator<Server.State> {
  13.    
  14.     /**
  15.      * This singleton logger instance can be used for logging various
  16.      * component messages to the console.
  17.      */
  18.     private static final Logger logger = Logger.getLogger(Server.class.getName());
  19.    
  20.     /**
  21.      * Encapsulates the singleton instance of the server.
  22.      * @author Thomas Nappo
  23.      */
  24.     private static final class SingletonContainer {
  25.         private static final Server singleton = new Server();
  26.     }
  27.    
  28.     /**
  29.      * Gets the singleton instance of the server.
  30.      * @return The one and only instance of the server.
  31.      */
  32.     public static Server getSingleton() {
  33.         return SingletonContainer.singleton;
  34.     }
  35.    
  36.     /**
  37.      * Defines the component activation state.
  38.      * @author Thomas Nappo
  39.      */
  40.     protected static enum State {
  41.         NETWORK,
  42.     }
  43.    
  44.     /**
  45.      * This is the entry point of the application which implements
  46.      * the command line interface. From here we begin initialization
  47.      * of the application's separate components.
  48.      * @param args The command line parameters.
  49.      */
  50.     public static void main(String[] args) {
  51.         logger.info("Initializing Nital...");
  52.        
  53.         /*
  54.          * Append a shutdown hook which calls the stop method
  55.          * so we can be sure to run shutdown procedures before
  56.          * process termination.
  57.          */
  58.         Runtime.getRuntime().addShutdownHook(new Thread() {
  59.             @Override
  60.             public void run() {
  61.                 Server.getSingleton().stop(Server.getSingleton().getState());
  62.             }
  63.         });
  64.     }
  65.  
  66.     @Override
  67.     public void start(State state) {
  68.         switch (state) {
  69.         case NETWORK:
  70.             break;
  71.         }
  72.     }
  73.  
  74.     @Override
  75.     public void stop(State state) {
  76.         logger.info("Stopping Nital...");
  77.        
  78.         /*
  79.          * Here you can implement whatever shutdown procedures
  80.          * should take place.
  81.          */
  82.        
  83.         System.exit(0);
  84.     }
  85.    
  86.     @Override
  87.     protected void checkpoint(State state) {
  88.         logger.info("Reached deploy stage: " + state.name().toLowerCase());
  89.         super.checkpoint(state);
  90.     }
  91.  
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement