UTTimerImplpublic class UTTimerImpl extends Object implements UTTimer
Fields Summary |
---|
private PluginInterface | plugin_interface | private Timer | timer | private boolean | destroyed |
Constructors Summary |
---|
public UTTimerImpl(String name, boolean lightweight)
// this constructor is for external (non-az) use, e.g. someone using the UPnP component
// in their own app
if ( !lightweight ){
timer = new Timer( name );
}
| protected UTTimerImpl(PluginInterface pi, String name, boolean lightweight)
plugin_interface = pi;
if ( !lightweight ){
timer = new Timer( "Plugin " + pi.getPluginID() + ":" + name );
}
| protected UTTimerImpl(PluginInterface pi, String name, int priority)
plugin_interface = pi;
timer = new Timer( "Plugin " + pi.getPluginID() + ":" + name, 1, priority );
|
Methods Summary |
---|
public UTTimerEvent | addEvent(long when, UTTimerEventPerformer ext_performer)
if ( destroyed ){
throw( new RuntimeException( "Timer has been destroyed" ));
}
final timerEvent res = new timerEvent();
TimerEventPerformer performer =
new TimerEventPerformer()
{
public void
perform(
TimerEvent ev )
{
UtilitiesImpl.setPluginThreadContext( plugin_interface );
res.perform( ext_performer );
}
};
if ( timer == null ){
res.setEvent( SimpleTimer.addEvent( "Plugin:" + ext_performer.getClass(), when, performer ));
}else{
res.setEvent( timer.addEvent( "Plugin:" + ext_performer.getClass(), when, performer ));
}
return( res );
| public UTTimerEvent | addPeriodicEvent(long periodic_millis, UTTimerEventPerformer ext_performer)
if ( destroyed ){
throw( new RuntimeException( "Timer has been destroyed" ));
}
final timerEvent res = new timerEvent();
TimerEventPerformer performer =
new TimerEventPerformer()
{
public void
perform(
TimerEvent ev )
{
try{
// may not be here in some cut down distributions
UtilitiesImpl.setPluginThreadContext( plugin_interface );
}catch( Throwable e ){
}
try {
res.perform( ext_performer );
} catch (Throwable e) {
Debug.out("Plugin '" + plugin_interface.getPluginName() + " ("
+ plugin_interface.getPluginID() + " "
+ plugin_interface.getPluginVersion()
+ ") caused an error while processing a timer event", e);
}
}
};
if ( timer == null ){
res.setEvent( SimpleTimer.addPeriodicEvent( "Plugin:" + ext_performer.getClass(), periodic_millis, performer ));
}else{
res.setEvent( timer.addPeriodicEvent( "Plugin:" + ext_performer.getClass(), periodic_millis, performer ));
}
return( res );
| public void | destroy()
destroyed = true;
if ( timer != null ){
timer.destroy();
}
|
|