FileDocCategorySizeDatePackage
TimerEventPeriodic.javaAPI DocAzureus 3.0.3.42704Thu Nov 23 10:58:22 GMT 2006org.gudy.azureus2.core3.util

TimerEventPeriodic

public class TimerEventPeriodic extends Object implements TimerEventPerformer
author
parg

Fields Summary
private Timer
timer
private long
frequency
private TimerEventPerformer
performer
private String
name
private TimerEvent
current_event
private boolean
cancelled
Constructors Summary
protected TimerEventPeriodic(Timer _timer, long _frequency, TimerEventPerformer _performer)

		timer		= _timer;
		frequency	= _frequency;
		performer	= _performer;
		
		current_event = timer.addEvent( 	SystemTime.getCurrentTime()+ frequency,
											this );
	
Methods Summary
public synchronized voidcancel()

		if ( current_event != null ){
			
			current_event.cancel();
			
			cancelled	= true;
		}
	
protected longgetFrequency()

		return( frequency );
	
protected TimerEventPerformergetPerformer()

		return( performer );
	
protected java.lang.StringgetString()

		TimerEvent ce = current_event;
		
		String	ev_data;
		
		if ( ce == null ){
			
			ev_data = "?";
		}else{
			
			ev_data = "when=" + ce.getWhen() + ",run=" + ce.hasRun() + ", can=" + ce.isCancelled();
		}
		
		return( ev_data  + ",freq=" + getFrequency() + ",target=" + getPerformer() + (name==null?"":(",name=" + name )));
	
protected booleanisCancelled()

		return( cancelled );
	
public voidperform(TimerEvent event)

		if ( !cancelled ){
			
			try{
				performer.perform( event );
				
			}catch( Throwable e ){
				
				DebugLight.printStackTrace( e );
			}
		
			synchronized( this ){
				
				if ( !cancelled ){
				
					current_event = timer.addEvent(name, SystemTime.getCurrentTime()+ frequency,
														this );
					
				}
			}
		}
	
public voidsetName(java.lang.String _name)

		name	= _name;
		
		synchronized( this ){
			
			if ( current_event != null ){
				
				current_event.setName( name );
			}
		}