All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.mstream.trader.simulation.Launcher Maven / Gradle / Ivy

package io.mstream.trader.simulation;


import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Stage;
import io.mstream.trader.simulation.config.ServiceModule;
import io.mstream.trader.simulation.handlers.RootChain;
import joptsimple.OptionParser;
import joptsimple.OptionSet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ratpack.func.Action;
import ratpack.server.RatpackServer;
import ratpack.server.ServerConfig;

import static ratpack.guice.Guice.registry;


class Launcher {

    private static final Logger LOGGER =
            LoggerFactory.getLogger(Launcher.class);

    private static final String PORT_ARG_NAME = "port";

    public static void main(String[] args)
            throws Exception {

        OptionParser optionParser = new OptionParser();
        optionParser.accepts(PORT_ARG_NAME).withOptionalArg().ofType(Integer.class).defaultsTo(8080);
        OptionSet options = optionParser.parse(args);

        int port = (int) options.valueOf(PORT_ARG_NAME);

        final Action errorHandler = throwable -> LOGGER.error(
                "error",
                throwable
        );

        final ServerConfig config = ServerConfig.builder()
                .development(true)
                .port(port)
                .onError(errorHandler)
                .build();

        Injector injector = Guice.createInjector(Stage.PRODUCTION, new ServiceModule());

        RatpackServer.start(
                server -> server.serverConfig(config)
                        .registry(registry(injector))
                        .handlers(
                                chain -> chain.all(
                                        chain.chain(RootChain.class)
                                )
                        )
        );
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy