Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.nital;
- import java.util.logging.Logger;
- import com.nital.bundle.ReplayingActivator;
- import com.nital.net.Network;
- /**
- * This class represents the application that will form the base of
- * other source files which will be able to run within this program.
- * @author Thomas Nappo
- */
- public final class Server extends ReplayingActivator<Server.State> {
- /**
- * This singleton logger instance can be used for logging various
- * component messages to the console.
- */
- private static final Logger logger = Logger.getLogger(Server.class.getName());
- /**
- * Encapsulates the singleton instance of the server.
- * @author Thomas Nappo
- */
- private static final class SingletonContainer {
- private static final Server singleton = new Server();
- }
- /**
- * Gets the singleton instance of the server.
- * @return The one and only instance of the server.
- */
- public static Server getSingleton() {
- return SingletonContainer.singleton;
- }
- /**
- * Defines the component activation state.
- * @author Thomas Nappo
- */
- protected static enum State {
- NETWORK, FUTURE;
- }
- /**
- * Constructs a new server.
- */
- private Server() {
- // changing changes the initial
- // state of the parent activator.
- super(State.NETWORK);
- }
- /**
- * This is the entry point of the application which implements
- * the command line interface. From here we begin initialization
- * of the application's separate components.
- * @param args The command line parameters.
- */
- public static void main(String[] args) {
- getSingleton(); // create the singleton
- logger.info("Initializing Nital...");
- // call for activation
- getSingleton().start(getSingleton().getState());
- /*
- * Append a shutdown hook which calls the stop method
- * so we can be sure to run shutdown procedures before
- * process termination.
- */
- Runtime.getRuntime().addShutdownHook(new Thread() {
- @Override
- public void run() {
- getSingleton().stop();
- }
- });
- }
- @Override
- public void start(State state) {
- switch (state) {
- case NETWORK:
- Network.getSingleton().start();
- checkpoint(State.FUTURE);
- break;
- }
- }
- @Override
- public void stop(State state) {
- logger.info("Stopping Nital...");
- /*
- * Here you can implement whatever shutdown procedures
- * should take place.
- */
- System.exit(0);
- }
- @Override
- protected void checkpoint(State state) {
- logger.info("Reached deploy stage: " + state.name().toLowerCase());
- super.checkpoint(state);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement