package org.jfox.ejb.timer;

import javax.ejb.EJBException;
import javax.ejb.NoSuchObjectLocalException;
import javax.ejb.Timer;
import javax.ejb.TimerHandle;

import org.jfox.ejb.ContainerImpl;

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

public class EJBTimerHandler implements TimerHandle {
    private String ejbName;
    private String identity;

    public EJBTimerHandler(String ejbName, String identity) {
        this.ejbName = ejbName;
        this.identity = identity;
    }

    /**
     * @return
     * @throws IllegalStateException
     * @throws NoSuchObjectLocalException
     * @throws EJBException
     */
    public Timer getTimer() throws IllegalStateException, NoSuchObjectLocalException, EJBException {
        EJBTimerService timerService = (EJBTimerService) ContainerImpl.getInstance().getBucket(ejbName).getTimerService();
        return timerService.getTimer(identity);
    }


    public String toString() {
        return "EJBTimerHandler{" +
                "ejbName='" + ejbName + "'" +
                ", identity='" + identity + "'" +
                "}";
    }

    public static void main(String[] args) {

    }
}

