Search code examples
jettycometrestletlong-polling

Using Jetty continuations in Restlet to implement Long-Polling


I have this Restlet structure:

I instanciate a Server object:

server = new Server(new Context(), config.getServerProtocol(), config
                            .getServerPort());

Afer i instanciate a new MyApp class that extends Application:

app = new org.myproject.restlet.server.MyApp(
    config, server.getContext());
app.start();

And starts the server:

server.setNext(app);
server.start();

I haven't any Component, MyApp distribute to a Router and process the request. If at this point anybody have a comment, it will be grateful. I'm using Restlet 2.0.14 JSE, and i link the jetty jars to use it like my http server. My server works ok, i have a javascript client that makes ajax calls, with a classical poll. But i need to implement a long-polling in the server (i discard stream and push modes for some reasons). I'm reading about how can implement this, the first way (ugly way) could be: - Sleeping the thread in server and resume when the server may have something. This way is discarded because it isn't scalable (here are a post about it). - The second way could be using the Jetty continuations api of version 7. In this link i can see how use the jetty comet api to suspend the request, but i dont know how apply to my restlet implementation, as stated in this another link, i can see:

Continuation continuation = ContinuationSupport.getContinuation(request);
continuation.suspend();

But getContinuation method receives a ServletRequest object. But my request isn't a ServletRequest. Anybody knows how convert or use a ServletRequest in restlet? Probably i dont have all the concepts with the server programming.


Solution

  • I can't use Jetty continuations with the jetty instantied by Restlet. To implement the long-polling I forgot Restlet and implement with the java concurrency: wait() & notify() and everything is running ok.