1 8 9 package mx4j.timer; 10 11 import java.util.Date ; 12 import javax.management.timer.TimerNotification ; 13 14 19 public abstract class TimerTask extends TimeTask 20 { 21 private TimerNotification m_notification; 22 private long m_date; 23 private long m_period; 24 private long m_occurrences; 25 private long m_initialOccurrences; 26 private int m_hash; 27 private boolean m_fixedRate; 28 29 public TimerTask(TimerNotification n, Date date, long period, long occurrences, boolean fixedRate) 30 { 31 m_notification = n; 32 m_date = date.getTime(); 33 m_period = period; 34 m_occurrences = occurrences; 35 m_initialOccurrences = occurrences; 36 m_fixedRate = fixedRate; 37 38 m_hash = new Long (getDate()).hashCode() ^ new Long (getPeriod()).hashCode() ^ new Long (getInitialOccurrences()).hashCode(); 40 41 setNextExecutionTime(getDate()); 42 } 43 44 public TimerNotification getNotification() 45 { 46 return m_notification; 47 } 48 49 public boolean isFinished() 50 { 51 return super.isFinished(); 52 } 53 54 public void setFinished(boolean value) 55 { 56 super.setFinished(value); 57 } 58 59 public long getPeriod() 60 { 61 return m_period; 62 } 63 64 public boolean isPeriodic() 65 { 66 boolean periodic = getPeriod() > 0 && (getInitialOccurrences() == 0 || getOccurrences() > 0); 67 return periodic; 68 } 69 70 public long getNextExecutionTime() 71 { 72 return super.getNextExecutionTime(); 73 } 74 75 public void setNextExecutionTime(long time) 76 { 77 super.setNextExecutionTime(time); 78 --m_occurrences; 79 } 80 81 public int hashCode() 82 { 83 return m_hash; 84 } 85 86 public boolean equals(Object obj) 87 { 88 if (obj == null) return false; 89 if (obj == this) return true; 90 91 try 92 { 93 TimerTask other = (TimerTask)obj; 94 return getDate() == other.getDate() && getPeriod() == other.getPeriod() && getInitialOccurrences() == other.getInitialOccurrences(); 95 } 96 catch (ClassCastException x) 97 { 98 return false; 99 } 100 } 101 102 public long getOccurrences() 103 { 104 return m_occurrences; 105 } 106 107 private long getInitialOccurrences() 108 { 109 return m_initialOccurrences; 110 } 111 112 public long getDate() 113 { 114 return m_date; 115 } 116 117 public boolean getFixedRate() 118 { 119 return m_fixedRate; 120 } 121 } 122 | Popular Tags |