/* 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.jms.connector;

import java.rmi.RemoteException;
import java.util.Date;

import org.jfox.framework.extra.ActiveComponent;
import org.jfox.jms.JMSContainer;
import org.jfox.system.AbstractService;

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

public abstract class AbstractConnectorService extends AbstractService implements JMSConnectorService, ActiveComponent {

    protected JMSContainer container = JMSContainer.getInstance();

    protected void doStart() throws Exception {
    }

    protected void doStop() throws Exception {
    }

    protected void doInit() throws Exception {
    }

    protected void doDestroy() throws Exception {
    }

    public void ping() throws RemoteException {
        logger.debug("I'm alive :)   " + new Date());
    }

    public void run() {
        while(isStarted()) {
            try {
                // 每隔 120s 运行 ping 函数，以防止该线程死掉
                Thread.sleep(5 * 60 * 1000L);
                ping();
            }
            catch(Exception e) {
                e.printStackTrace();
            }
        }
        // do not need to implement, because is a rmi server
    }

    public static void main(String[] args) {

    }
}
