package org.jfox.framework.management.http;

import org.jfox.framework.Component;
import org.jfox.framework.ComponentContext;
import org.jfox.framework.Registry;
import org.jfox.framework.extra.InstantiatingInterceptable;
import org.jfox.framework.extra.Servicable;

/**
 * @author <a href="mailto:yangyong@ufsoft.com.cn">Young Yang</a>
 */

public class HttpManagementServerComponent implements Component, InstantiatingInterceptable, Servicable {
    private boolean started = false;
    private ManagementHttpServer ws = new ManagementHttpServer();

    public Component afterInstantiate(Component theComp, Registry registry) {
        ws.setRegistry(registry);
        return theComp;
    }

    public void start() throws Exception {
        ws.start();
        started = true;
    }

    public void stop() throws Exception {
        ws.stop();
        started = false;
    }

    public boolean isStarted() {
        return started;
    }

    public int mx_getPort() {
        return ws.getPort();
    }

    public void setComponentContext(ComponentContext ctx) {
    }

    public static void main(String[] args) throws Exception {
        Registry registry = Registry.getInstance();
        registry.registerComponent(HttpManagementServerComponent.class);
        registry.start();
    }
}

