1 package org.jfox.ejb.timer; 2 3 import java.io.Serializable ; 4 import java.util.Date ; 5 import javax.ejb.EJBException ; 6 import javax.ejb.NoSuchObjectLocalException ; 7 import javax.ejb.Timer ; 8 import javax.ejb.TimerHandle ; 9 10 13 14 public class EJBTimer implements Timer { 15 16 private EJBTimerTask task; 17 private Serializable info; 18 private TimerHandle timerHandle; 19 20 public EJBTimer(EJBTimerTask task, Serializable info) { 21 this.task = task; 22 this.info = info; 23 this.timerHandle = new EJBTimerHandler(task.getTimerService().getEjbName(), "" + System.identityHashCode(this)); 24 } 25 26 public long getTimeRemaining() throws IllegalStateException , NoSuchObjectLocalException , EJBException { 27 return (task.scheduledExecutionTime() - System.currentTimeMillis()); 28 } 29 30 public Date getNextTimeout() throws IllegalStateException , NoSuchObjectLocalException , EJBException { 31 return new Date (task.scheduledExecutionTime()); 32 } 33 34 public Serializable getInfo() throws IllegalStateException , NoSuchObjectLocalException , EJBException { 35 return info; 36 } 37 38 public TimerHandle getHandle() throws IllegalStateException , NoSuchObjectLocalException , EJBException { 39 return timerHandle; 40 } 41 42 45 public void cancel() { 46 task.cancel(); 47 } 48 49 public int hashCode() { 50 return task.hashCode(); 51 } 52 53 public boolean equals(Object obj) { 54 if(!(obj instanceof EJBTimer)) { 55 return false; 56 } 57 EJBTimer timer = (EJBTimer) obj; 58 return timer.task.equals(task); 59 } 60 61 public static void main(String [] args) { 62 63 } 64 } 65 66 | Popular Tags |