Menu

#5 Contrib - Timer class for echo

open
nobody
None
5
2002-06-13
2002-06-10
Brad Baker
No

I have created a Timer class for echo, that will pop after
n milliseconds (on the browser client) and raise an
ActionEvent indicating this.

The idea for this came from an email in the echo list and
Todd gaves some very good instructions on how to
create a such a class.

The class is modelled on the Swing Timer class. You
would call something like this

Timer t = new Timer\(10000\);
t.setActionCommand\("timerFired"\);
t.addActionListener\(this\);
t.start\(\);

The file is uploaded into the feature request area on
sourceforge and is
called "bb_contrib_echoTimer_01.zip". ONly the java
source files, properties files and .js javascript are
included. No class files have been upload, so you will
have to compile the code.

Note that this is a very coarse timer. The timer is run on
the client and the timeout must travel back to the server
before any other code can be notified of this event.

Therefore the granuality of the timer cannot be
gaurunteed, as it depends on the client speed and
the network speed between the client and server.

This class is mostly useful for causing the client to
update without having to have the user click on
anything. For example someone had the requirement to
update the screen to check on the status of a download
queue. A timer could be used to cause an ActionEvent
after say 30 seconds.

You can only have one effective Timer on a Window at a
time. This is because once the lowest delay timer has
popped, any screen updates will cause all Timers on
that Window to be reset to their respective starting
delays, regardless of how much time has passed since
the last event happened on a given timer.

The reason the Timer is fired on the client rather than via
a thread on the server, is to help support many clients
(thousands). Each client is running their own timers,
using their own processing power. If a single thread was
created for all Timers (or worse one per client) then the
system would eventually grind to a halt.

Also the way echo is architected, (in fact all web apps),
a request has to come in from the client, in order for the
server to update the state of a UI object.

Discussion

  • Brad Baker

    Brad Baker - 2002-06-10

    Timer java code, properties and javascript files

     
  • Tod Liebeck

    Tod Liebeck - 2002-06-13
    • labels: 415126 -->
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.