/* 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.examples.ejb.timer;

import javax.ejb.CreateException;
import javax.ejb.EJBException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.ejb.TimedObject;
import javax.ejb.Timer;
import javax.ejb.TimerHandle;
import javax.ejb.TimerService;

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

public class TestTimerBean implements SessionBean, TimedObject {
    private SessionContext context;

    public TestTimerBean() {
    }

    public void setSessionContext(SessionContext sessionContext) throws EJBException {
        context = sessionContext;
    }

    public void ejbRemove() throws EJBException {
    }

    public void ejbActivate() throws EJBException {
    }

    public void ejbPassivate() throws EJBException {
    }

    public void ejbCreate() throws CreateException {
    }

    public void ejbTimeout(Timer timer) {
        System.out.println("ejbTimeout, Timer is: " + timer);

        TimerHandle handle = timer.getHandle();
        System.out.println("TimerHandler: " + handle);

        System.out.println("Timer get by TimerHandler: " + handle.getTimer());
    }

    public void shedule(long time) {
        TimerService timerService = context.getTimerService();
        timerService.createTimer(time, null);
    }
}
