TheBagbournes said:
Take a look at DWR 2 though (and this is not a self-promotional scam -
I'm just a developer who uses it being a bit enthusiastic). The "Reverse
Ajax" capability will be great. The usage is asynchronous calls from
Java in the server. The implementation is a setTimeout() "thread" in the
browser which polls the server with XMLHttpRequests (I don't know if you
can set the frequency - you *should* be able to) and calls your
Javascript methods on receipt.
I've been planning features for our new intranet web app like user
alerts and reminders. Actions due, messages received, system actions
(like shutdown etc). And reverse Ajax is the way I'm planning to go.
I'll have a Javascript object in a page which subscribes to events, and
an event manager servlet started in the server to which you publish
events which broadcasts events to subscribed pages.
Over the last few days I have prototyped a very similar system. The
client polls the server for new messages and then acts on those
messages appropriately. I'm curious what makes this "reverse AJAX"?
Are the DWR messages JavaScript that gets eval() when it reaches the
client?
My messages have been in the form of English. Any client side object
can subscribe to any English message. Any object can subscribe to any
string. For example an object might subscribe to "Pass the purple
turkey" message. This message does not have to be predefined. If the
server ever sends out a "Pass the purple turkey" message the
appropriate objects are notified and can do as they please. I may
switch to the server sending JavaScript messages that the client will
eval().
What I would really like to do is use this to update an unknown number
of parts of a page based on one or more messages. The goal is to avoid
stale browser views of the server database. The client event manager
will send out the server's message to find out which objects are
interested. The objects will respond to the event manager with a
request for a particular update. All of the requested updates will be
lumped together and sent to the server in one AJAX request. The server
will send a reply with all the necessary updates. If many elements need
updating this will limit the number of AJAX requests to only one. I
still have a lot of details to think through.
Peter