periodic.standard.html
poo/poolib/periodic.standard.html · 2.6 KB
From the archive poo.tar.gz
Download the archive « Back to the archive contents
<html><head><title>
POO lib: periodic.standard
</title></head><body><center>
<h3>POO Library</h3>
<h1>$pub.periodic.standard</h1>
</center>
This object is the parent of any common object which needs to execute a
task periodically. It contains commands for turning the periodic task
on and off, and includes error trapping to make it easier to notice when
there is a problem. It is highly recommended that all POO servers
include this object, as it seems likely that many POO coders will assume
it exists.
<hr>
<pre>@create $thing as standard
@set standard.f = 1
@set standard.interval = 300
@newfunc standard.update(self)
if time() - self.lastTime < self.interval: return
self.lastTime = time()
try: self.periodicTask()
except:
self.owner.tell("Bug in " + self.name + \
".periodicTask(). Updates stopped.")
self.wantsUpdates = 0
.x
@newfunc standard.checkPerm(self)
if user != self and user != self.owner and not user.wizard:
print self.name + " belongs to " + self.owner.name + "."
return 0
return 1
.x
@newfunc standard.start(self)
if not self.checkPerm(): return
self.wantsUpdates = 1
self.lastTime = time() - self.interval
print self.name, "started."
if user != self.owner:
self.owner.tell( user.name + " has started " + self.name + "." )
.x
@cmd standard.start <this> calls start()
@newfunc standard.stop(self)
if not self.checkPerm(): return
self.wantsUpdates = 0
print self.name, "stopped."
if user != self.owner:
self.owner.tell( user.name + " has stopped " + self.name + "." )
.x
@cmd standard.stop <this> calls stop()
@newfunc standard.periodicTask(self)
self.owner.tell( self.name + " has received a call to periodicTask()." )
.x
beam standard to $pub.periodic
</pre>
<hr>
<h3>Usage</h3>
To create your own periodically updated object, derive it from this one:
<pre>@create $pub.periodic.standard as myBeeper</pre>
You can then set the timing interval by setting your object's
<b>.interval</b> property in seconds (it defaults to 300, i.e., 5
minutes).
<p>Start the periodic updates with a command such as <b>start
myBeeper</b>, and stop it similarly (<b>stop myBeeper</b>). While it is
running, you (as the owner of the object) will receive a message every
time its periodic task is executed.
<p>To make your object do something more useful, override the
<b>.periodicTask</b> function, like this:
<pre>@newfunc myBeeper.periodicTask(self)
self.location.broadcast("You heer a beep.")
.x</pre>
<p><hr>
<address>
http://www.strout.net/python/poo/lib/periodic.standard.html
<br>Last Updated:
10/06/97
. . . . . . <a href="http://www.strout.net/">Joe Strout</a>
</address>
</body></html>