de.blinkenlights.bmix.main.Daemon.java Source code

Java tutorial

Introduction

Here is the source code for de.blinkenlights.bmix.main.Daemon.java

Source

/* 
 * This file is part of BMix.
 *
 *    BMix is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 * 
 *    BMix is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with BMix.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

package de.blinkenlights.bmix.main;

import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.apache.commons.daemon.DaemonContext;

public class Daemon implements org.apache.commons.daemon.Daemon {
    private BMix bmix;

    public void destroy() {
        // no special cleanup required
    }

    public void init(DaemonContext arg0) throws Exception {
        int verbosity = 1;
        if (System.getProperty("debugLevel") != null) {
            verbosity = Integer.parseInt(System.getProperty("debugLevel"));
        }
        Level logLevel;
        if (verbosity == 0) {
            logLevel = Level.WARNING;
        } else if (verbosity == 1) {
            logLevel = Level.INFO;
        } else if (verbosity == 2) {
            logLevel = Level.FINE;
        } else if (verbosity >= 3) {
            logLevel = Level.FINEST;
        } else {
            System.err.println("Fatal Error: Invalid log verbosity: " + verbosity);
            return;
        }
        System.err.println("Setting log level to " + logLevel);
        Logger.getLogger("").setLevel(logLevel);
        for (Handler handler : Logger.getLogger("").getHandlers()) {
            handler.setLevel(logLevel);
        }

        bmix = new BMix("bmix.xml", false);
    }

    public void start() throws Exception {
        bmix.start();
    }

    public void stop() throws Exception {
        //bmix.shutdown();
    }

}