Hi Jigar,
Rather than creating a Bayeux object, you'll want to grab a reference to the
one being used by the cometd servlets. In the current Jetty implementation,
these are accessed via the ServletContext, so something like this:
Bayeux bayeux =
(Bayeux)servletContext.getAttribute(dojox.cometd.Bayeux.DOJOX_COMETD_BAYEUX);
Have a look at the code for the abstract cometd servlet, you'll see it creatin
a bayeux and registering it as an attribute of the servlet context under this
name.
ServletContexts are one-per-JVM, so this approach scales up to the point at
which you want to do clustering. I think I've seen some discussion on the
next step up being to store the Bayeux client in a JNDI, a la EJB2, but I
think that was speculative rather than an actual implementation.
In the code I've been writing, I'm creating one client per servlet instance
(actually, per controller instance, as I'm using Groovy on Grails, but same
principle), and give them a unique name by appending a random number on the
end of a standard prefix such as "myService_". The bayeux client is an
instance member of the servlet, and gets created on demand first time the
server performs a publish operation.
Greg, I'd be interested to know if you've any comments on this approach, or do
you suggest creating a new client for every publish operation? (I guess in
part it depends on whether you want the server-side client to also subscribe
to channels - I'm still using standard 'old-fashioned' Ajax when I want the
client to tell the server anything.) Is it expensive to create a new client?
Cheers, HTH
Dave