Comet with Aida/Web (was How to force an Application to refresh its view)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Comet with Aida/Web (was How to force an Application to refresh its view)

Janko Mivšek
Hi Rob,

Well, this one is actually most advanced topic of web application
building in general and it is called Comet.

Comet, or so called Reverse Ajax is an updating some element of your web
page when some event occurs on the server side, not the client one.

In Aida this is easy achievable by deferring a response to periodic Ajax
update of some element until a server event occurs. And to signal that
event, you can use Announcements, just as you do.

Basically you do:

1. make some element for a content to be Comet updatable, in some
    method, say #liveContent.
2. let you Ajax periodicaly update that element, but with very long
    period:

        e add: (self liveContent updateEverySeconds: 1000)

So far so good, no let we prepare our reverse Ajax by deferring the
response. Let we now break that delay and respond immediately when some
event is sent via Announcements framework

4. let we prepare our defer code at the start of #liveContent

MyApp>>liveContent
   self session lastRequest isAjaxRequest ifTrue:
        [self waitForAnyChange].
   e := WebElement new.
   ....
   ^e

MyApp>>waitForAnyChange
  | count change |
  count := 1. change := false.
  self observee
      when: OurAnnouncement do: [:ann | change := true] for: self.
  [change not and: [count < 1000]] whileTrue:
     [(Delay forSeconds: 1) wait.
     count := count + 1].
  self observee unsubscribe: self

OurAnnouncement is a subclass of Announcement for our case. Above code
will respond in a less that 1 second after an event occurs. If you want
faster response, change Delay code accordingly. Also this method can be
possibly done better...

5. Domain object (observe) must now send OurAnnouncement on event to
trigger sending above response. Look at Announcements docs for that.
Probably you'll in myDomainObject just do:

        self announce: OurAnnouncement.

I hope that helps a bit

Best regards
Janko






Stefan Schmiedl wrote:
 > On Wed, 6 Feb 2008 16:48:44 -0500
 > "Rob Rothwell" <[hidden email]> wrote:
 >
 >> In other words the browser only refreshes itself when it wants to!
 >
 > ... unless you specify a refresh meta tag, for example, which does for
 > the whole page what I assume updateEverySeconds: does for a single
 > element.
 >
 >> If you don't use special "server push" technology, another way of
 >>> achieving a similar effect would be to periodically query the
 >>> application for status updates ... AJAX is used for stuff like this.
 >>
 >> So...would you just recommend using one of the AJAX methods like
 >> "updateEverySeconds:" to poll for changes?  I was actually trying to
write a
 >> simple little department "chat" program, and the AJAX way works, but
 >> checking the server every few seconds just seemed like a bit much.
 >
 > wellllllll... google has a "special" search dialog somewhere (probably
 > in "beta" :-) which polls the server after every keystroke recorded by
 > the input box. If you type slow enough, you can watch suggestions for
 > search terms pop up.
 >
 >> Can I create a new type of component that simply ask the server for an
 >> update "on demand" rather then periodically?  I am getting a message
and all
 >> the information I need is in my domain model...
 >
 > Define "on demand". Who is the "I" getting the message. I assume that
 > the "I" owning "my domain model" is the application server.
 >
 >> Maybe what I'm asking for is already part of the AIDA AJAX elements
and I
 >> just don't know how to use it...
 >>
 >
 > I'll defer to people actually knowing AIDA on this one :-)
 >
 > s.


--
Janko Mivšek
AIDA/Web
Smalltalk Web Application Server
http://www.aidaweb.si
_______________________________________________
Aida mailing list
[hidden email]
http://lists.aidaweb.si/mailman/listinfo/aida
Reply | Threaded
Open this post in threaded view
|

Re: Comet with Aida/Web (was How to force an Application to refresh its view)

Rob Rothwell
Janko,

Where do you find the time to give me such detailed answers?!  And what timezone are you in???!

Well, this one is actually most advanced topic of web application
building in general and it is called Comet.

Well...at least there is a reason a novice like myself couldn't figure it out!

Wow.  Well...being the novice that I am, I will have to play with this a bit before I can respond!

Thank you very much!  I'll give this a shot and let you know how it goes.  All I wanted to write was a simple departmental "chat room" because 7 of us have been in one room for 3 years and I have recently had to move to a different floor to accommodate another person.  We bounce ideas off each other all the time, and I thought it would be a good little learning project.  I was right!

Anyway...I think once this works I just have to "make it pretty," and then try to document my learning so others may benefit!

Thanks again,

Rob


_______________________________________________
Aida mailing list
[hidden email]
http://lists.aidaweb.si/mailman/listinfo/aida