001/*
002 * Copyright (c) 2015 Maxim Yunusov
003 *    Licensed under the Apache License, Version 2.0 (the "License");
004 *    you may not use this file except in compliance with the License.
005 *    You may obtain a copy of the License at
006 *
007 *        http://www.apache.org/licenses/LICENSE-2.0
008 *
009 *    Unless required by applicable law or agreed to in writing, software
010 *    distributed under the License is distributed on an "AS IS" BASIS,
011 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012 *    See the License for the specific language governing permissions and
013 *    limitations under the License.
014 */
015
016package org.maxur.perfmodel.backend.service;
017
018import org.slf4j.Logger;
019
020import javax.inject.Named;
021
022import static org.slf4j.LoggerFactory.getLogger;
023
024/**
025 * This Abstract class represents interface of Web Server.
026 *
027 * @author myunusov
028 * @version 1.0
029 * @since <pre>30.08.2015</pre>
030 */
031public abstract class WebServer {
032
033    private static final Logger LOGGER = getLogger(WebServer.class);
034
035    protected static final String WEB_APP_URL = "/";
036
037    @SuppressWarnings("unused")
038    @Named("webapp.folderName")
039    private String webappUrl;
040
041    /**
042     * Start Web server.
043     */
044    public void start() {
045        LOGGER.info("Start Web Server ({})", version());
046        launch();
047        LOGGER.info("Starting on " + webappUrl);
048    }
049
050    /**
051     * Restart Web server.
052     */
053    public void restart() {
054        LOGGER.info("Restart Web Server");
055        launch();
056        LOGGER.info("Starting on " + webappUrl);
057    }
058
059    /**
060     * Stop Web server.
061     */
062    public void stop() {
063        LOGGER.info("Stop Web Server");
064        shutdown();
065    }
066
067    protected abstract String version();
068
069    protected abstract void launch();
070
071    protected abstract void shutdown();
072
073    public abstract boolean isStarted();
074
075}