> glassfish_at_javadesktop.org wrote:
>> I've been using simple ajax polling from my web client to check
>> when a value on my MySQL database has changed but as the number of
>> clients has grown it is obviously not scaling well.
>> Would someone help put me on the right track? Basically what I want
>> to do is have each client browser, say 1000 of them, be able to
>> have database updates pushed to them when something they are
>> interested in changes in the database.
>> I think I can use GlassFish and Grizzly to implement this, correct?
>
> Correct.
>
> How do I poll the database from the servlet to check if data has
> been updated?
I think push architecture should work great with MySQL triggers [1].
[1]
http://dev.mysql.com/doc/refman/5.1/en/triggers.html
WBR,
Alexey.
>
>
> Here is a high level description of how you can achieve that.
>
> 1. Client sent a GET request and the Servlet suspend
> (CometContext.addCometHandler) and then register that connection to
> a CometContext (a topic or shareable group. in your case a MySql
> topic) (cometContext.addCometHandler(yourHandler)).
> 2. Your Servlet spawn a thread at startup (a single one) that check
> when the database has update by polling MySQL).
> 3. When an update comes in, that Thread invokes
> CometContext.notify(MySqlUpdate), which in turn will invoke all the
> suspended connection, resume them, write the response, and depending
> on the comet technique you are interested (long polling or streaming).
>
> Take a look at this blog[1]. Mainly, you can probably re-use the
> ReflectorCometHandler[2] directly, so it should be as simple as:
>
>
> public void doGet(...){
>
> ReflectorCometHandler rh = new RelectorCometHandler(useHttpStreaming);
> rh.attach(HttpServletResponse.getWriter());
> CometContext ctx = CometEngine.getEngine().register("mySQL-push");
> ctx.addCometHandler(rh); // Suspend the connection.
>
> }
>
> Then from you spawned thread, just do:
>
> ctx.notify(MySqlUpdate);
>
> That's it :-) Let us know if you need more information.
>
> A+
>
> -- Jeanfrancois
>
> [1]http://weblogs.java.net/blog/jfarcand/archive/2008/11/writing_a_twitt.html
> [2]https://grizzly.dev.java.net/nonav/xref/com/sun/grizzly/comet/handlers/ReflectorCometHandler.html
>
>
>
>
>
>
> How do I push the update to the client?
>> I'm still trying to learn how this all works so any help would be
>> appreciated.
>> Thanks.
>> bondo.
>> [Message sent by forum member 'bondo' (bondo)]
>> http://forums.java.net/jive/thread.jspa?messageID=327725
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
>> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_grizzly.dev.java.net
> For additional commands, e-mail: users-help_at_grizzly.dev.java.net
>