Package io.fathom.auto

Source Code of io.fathom.auto.AutoHaproxyMain

package io.fathom.auto;

import io.fathom.auto.config.ConfigStore;
import io.fathom.auto.haproxy.BoundHaproxyConfig;
import io.fathom.auto.haproxy.HaproxyConfig;
import io.fathom.auto.haproxy.HaproxyInstance;

import java.io.IOException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class AutoHaproxyMain {
    private static final Logger log = LoggerFactory.getLogger(AutoHaproxyMain.class);

    private final ConfigStore configStore;

    AutoHaproxyMain(ConfigStore configStore) {
        this.configStore = configStore;
    }

    public static void main(String[] args) throws InterruptedException {
        ConfigStore configStore = ConfigStore.get("lb");

        AutoHaproxyMain main = new AutoHaproxyMain(configStore);
        try {
            main.run();
        } catch (Exception e) {
            log.error("Error during haproxy run; forcing exit", e);
            System.exit(1);
        }
    }

    public void run() throws IOException, InterruptedException {
        Thread haproxyThread = new Thread(new Runnable() {
            @Override
            public void run() {
                HaproxyConfig config = new BoundHaproxyConfig(configStore);
                HaproxyInstance instance = new HaproxyInstance(config);
                try {
                    instance.run();
                } catch (Exception e) {
                    log.error("Error during haproxy run; forcing exit", e);
                    System.exit(1);
                }
            }
        });
        haproxyThread.start();
    }

}
TOP

Related Classes of io.fathom.auto.AutoHaproxyMain

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.