Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.yammer.dropwizard.cli;
 
// TODO: 10/12/11 <coda> -- write tests for ServerCommand
Runs a service as an HTTP server.

Parameters:
<T> the com.yammer.dropwizard.config.Configuration subclass which is loaded from the configuration file
public class ServerCommand<T extends Configurationextends EnvironmentCommand<T> {
    private final Class<T> configurationClass;
    public ServerCommand(Service<T> service) {
        super(service"server""Runs the Dropwizard service as an HTTP server");
        this. = service.getConfigurationClass();
    }
    /*
     * Since we don't subclass ServerCommand, we need a concrete reference to the configuration
     * class.
     */
    @Override
    protected Class<T> getConfigurationClass() {
        return ;
    }
    @Override
    protected void run(Environment environmentNamespace namespace, T configurationthrows Exception {
        final Server server = new ServerFactory(configuration.getHttpConfiguration(),
                                                environment.getName()).buildServer(environment);
        final Logger logger = LoggerFactory.getLogger(ServerCommand.class);
        logBanner(environment.getName(), logger);
        try {
            server.start();
            for (ServerLifecycleListener listener : environment.getServerListeners()) {
                listener.serverStarted(server);
            }
        } catch (Exception e) {
            logger.error("Unable to start server, shutting down"e);
            server.stop();
        }
    }
    private void logBanner(String nameLogger logger) {
        try {
            final String banner = Resources.toString(Resources.getResource("banner.txt"),
                                                     .);
            logger.info("Starting {}\n{}"namebanner);
        } catch (IllegalArgumentException ignored) {
            // don't display the banner if there isn't one
            logger.info("Starting {}"name);
        } catch (IOException ignored) {
            logger.info("Starting {}"name);
        }
    }
New to GrepCode? Check out our FAQ X