Methods Summary |
---|
public synchronized TimerEvent | addEvent(long when, TimerEventPerformer performer)
return( addEvent( SystemTime.getCurrentTime(), when, performer ));
|
public synchronized TimerEvent | addEvent(java.lang.String name, long when, TimerEventPerformer performer)
return( addEvent( name, SystemTime.getCurrentTime(), when, performer ));
|
public synchronized TimerEvent | addEvent(long creation_time, long when, TimerEventPerformer performer)
return( addEvent( null, creation_time, when, performer ));
|
public synchronized TimerEvent | addEvent(java.lang.String name, long creation_time, long when, TimerEventPerformer performer)
TimerEvent event = new TimerEvent( this, unique_id_next++, creation_time, when, performer );
if ( name != null ){
event.setName( name );
}
events.add( event );
if ( log ){
if ( !(performer instanceof TimerEventPerformer )){
System.out.println( "Timer '" + thread_pool.getName() + "' - added " + event.getString());
}
if ( events.size() > max_events_logged ){
max_events_logged = events.size();
System.out.println( "Timer '" + thread_pool.getName() + "' - events = " + max_events_logged );
}
}
// System.out.println( "event added (" + when + ") - queue = " + events.size());
notify();
return( event );
|
public synchronized TimerEventPeriodic | addPeriodicEvent(long frequency, TimerEventPerformer performer)
return( addPeriodicEvent( null, frequency, performer ));
|
public synchronized TimerEventPeriodic | addPeriodicEvent(java.lang.String name, long frequency, TimerEventPerformer performer)
TimerEventPeriodic periodic_performer = new TimerEventPeriodic( this, frequency, performer );
if ( name != null ){
periodic_performer.setName( name );
}
if ( log ){
System.out.println( "Timer '" + thread_pool.getName() + "' - added " + periodic_performer.getString());
}
return( periodic_performer );
|
public void | adjustAllBy(long offset)
// fix up the timers
synchronized (this) {
// as we're adjusting all events by the same amount the ordering remains valid
Iterator it = events.iterator();
while (it.hasNext()) {
TimerEvent event = (TimerEvent) it.next();
long old_when = event.getWhen();
long new_when = old_when + offset;
// System.out.println( " adjusted: " + old_when + " -> " + new_when );
event.setWhen(new_when);
}
notify();
}
|
protected synchronized void | cancelEvent(TimerEvent event)
if ( events.contains( event )){
events.remove( event );
// System.out.println( "event cancelled (" + event.getWhen() + ") - queue = " + events.size());
notify();
}
|
public void | consume(long offset)
// System.out.println( "Timer '" + thread_pool.getName() +"': clock change by " + offset );
if ( Math.abs( offset ) >= 60*1000 ){
// fix up the timers
synchronized( this ){
// as we're adjusting all events by the same amount the ordering remains valid
Iterator it = events.iterator();
while (it.hasNext()){
TimerEvent event = (TimerEvent)it.next();
long old_when = event.getWhen();
long new_when = old_when + offset;
// System.out.println( " adjusted: " + old_when + " -> " + new_when );
event.setWhen( new_when );
}
notify();
}
}
|
public synchronized void | destroy()
if ( indestructable ){
Debug.out( "Attempt to destroy indestructable timer '" + getName() + "'" );
}else{
destroyed = true;
notify();
SystemTime.unregisterClockChangeListener( this );
}
if (DEBUG_TIMERS) {
try {
timers_mon.enter();
// crappy
for (Iterator iter = timers.iterator(); iter.hasNext();) {
WeakReference timerRef = (WeakReference) iter.next();
Object timer = timerRef.get();
if (timer == null || timer == this) {
iter.remove();
}
}
} finally {
timers_mon.exit();
}
}
|
public synchronized void | dump()
System.out.println( "Timer '" + thread_pool.getName() + "': dump" );
Iterator it = events.iterator();
while(it.hasNext()){
TimerEvent ev = (TimerEvent)it.next();
System.out.println( "\t" + ev.getString());
}
|
public boolean | getLogging()
return log;
|
public java.lang.String | getName()
return( thread_pool.getName());
|
public void | runSupport()
while( true ){
try{
TimerEvent event_to_run = null;
synchronized(this){
if ( destroyed ){
break;
}
if ( events.isEmpty()){
// System.out.println( "waiting forever" );
this.wait();
}else{
long now = SystemTime.getCurrentTime();
TimerEvent next_event = (TimerEvent)events.iterator().next();
long delay = next_event.getWhen() - now;
if ( delay > 0 ){
// System.out.println( "waiting for " + delay );
this.wait(delay);
}
}
if ( destroyed ){
break;
}
long now = SystemTime.getCurrentTime();
Iterator it = events.iterator();
while( it.hasNext()){
TimerEvent event = (TimerEvent)it.next();
if ( event.getWhen() <= now ){
event_to_run = event;
it.remove();
break;
}
}
}
if ( event_to_run != null ){
event_to_run.setHasRun();
if (log) {
System.out.println( "running: " + event_to_run.getString() );
}
thread_pool.run(event_to_run.getRunnable());
}
}catch( Throwable e ){
Debug.printStackTrace( e );
}
}
|
public void | setIndestructable()
indestructable = true;
|
public void | setLogging(boolean _log)
log = _log;
|
public void | setWarnWhenFull()
thread_pool.setWarnWhenFull();
|