Search in sources :

Example 1 with WebSocketServer

use of edu.csus.yaam.server.websocket.WebSocketServer in project S4T1TM2 by CSUS-CSC-131-Spring2018.

the class YaamServerLauncher method main.

public static void main(String... args) {
    // build argument parser
    ArgumentParser parser = ArgumentParsers.newFor("TaskManager").addHelp(false).build().defaultHelp(true).description("YAAM WebServer");
    // add additional parameters
    ArgumentGroup optionalArguments = parser.addArgumentGroup("Optional Arguments");
    // allow specifying a configuration file by a filepath
    optionalArguments.addArgument("--conf", "--config").dest("configFile").nargs(1).type(File.class).metavar("config.yml").setDefault(new File("yaam-config.yml")).help("Specifies a configuration file by filepath");
    // use no external configuration file, use bundled config
    optionalArguments.addArgument("--noConfig").dest("noConfig").type(boolean.class).help("Uses default bundled config");
    // parse arguments
    Namespace namespace = new Namespace(new HashMap<>());
    try {
        parser.parseArgs(args, namespace.getAttrs());
    } catch (ArgumentParserException exception) {
        System.err.println("error: " + exception.getMessage());
        System.err.println();
        parser.printHelp(new PrintWriter(System.err, true));
        System.exit(-1);
    }
    // load YAAM server configuration and settings into memory
    YaamConfig config = YaamConfig.load(namespace);
    log.info("Loaded configuration");
    // construct WebAPI
    log.info("Launching web api...");
    try {
        WebServerAPI apiServer = new WebServerAPI(config);
        apiServer.launch();
    } catch (Throwable throwable) {
        log.fatal("Failed to launch WebServerAPI", throwable);
        System.exit(-1);
    }
    log.info("Web API launched");
    // construct WebSocket
    log.info("Launching web socket server...");
    try {
        WebSocketServer webSocketServer = new WebSocketServer(config);
        webSocketServer.launch();
    } catch (Throwable throwable) {
        log.fatal("Failed to launch WebSocketServer", throwable);
        System.exit(-1);
    }
    log.info("Web socket server launched");
    log.info("Server running");
}
Also used : WebSocketServer(edu.csus.yaam.server.websocket.WebSocketServer) WebServerAPI(edu.csus.yaam.server.webapi.WebServerAPI) ArgumentParserException(net.sourceforge.argparse4j.inf.ArgumentParserException) ArgumentParser(net.sourceforge.argparse4j.inf.ArgumentParser) File(java.io.File) ArgumentGroup(net.sourceforge.argparse4j.inf.ArgumentGroup) Namespace(net.sourceforge.argparse4j.inf.Namespace) PrintWriter(java.io.PrintWriter)

Aggregations

WebServerAPI (edu.csus.yaam.server.webapi.WebServerAPI)1 WebSocketServer (edu.csus.yaam.server.websocket.WebSocketServer)1 File (java.io.File)1 PrintWriter (java.io.PrintWriter)1 ArgumentGroup (net.sourceforge.argparse4j.inf.ArgumentGroup)1 ArgumentParser (net.sourceforge.argparse4j.inf.ArgumentParser)1 ArgumentParserException (net.sourceforge.argparse4j.inf.ArgumentParserException)1 Namespace (net.sourceforge.argparse4j.inf.Namespace)1