/* JFox, the OpenSource J2EE Application Server
 *
 * Distributable under GNU LGPL license by gun.org
 * more details please visit http://www.huihoo.org/jfox
 */

package org.jfox.jndi;

import org.jfox.framework.extra.ActiveComponent;
import org.jfox.framework.extra.Managable;
import org.jfox.framework.extra.ManagementInfo;
import org.jfox.system.AbstractService;
import org.jfox.system.ServiceWrapper;

/**
 * @author <a href="mailto:young_yy@hotmail.com">Young Yang</a>
 */

public class JNDIService extends AbstractService implements Managable, ActiveComponent {
    private int port = 1099;
    private ServiceWrapper sw = null;
    /**
     * remote object export port
     */
    private int exportPort = 1098;

    public JNDIService() throws Exception {
        this(1099);
    }

    public JNDIService(int port) throws Exception {
        this.port = port;
    }

    protected void doStart() throws Exception {
        sw.start();
    }

    protected void doStop() throws Exception {
        sw.stop();
    }

    protected void doInit() throws Exception {
        sw = new ServiceWrapper(NamingServiceImpl.class, port, exportPort);
        sw.init();
    }

    protected void doDestroy() throws Exception {
        sw = null;
    }

    public int getPort() {
        return port;
    }

    public int getExportPort() {
        return exportPort;
    }

    public void setExportPort(int exportPort) {
        this.exportPort = exportPort;
    }

    public void run() {

    }

    public ManagementInfo getManagementInfo() {
        return ManagementInfo.exposePublic(JNDIService.class);
    }


    public static void main(String[] args) throws Exception {
        new JNDIService();
    }
}
