dev@grizzly.java.net

Re: suspend/resume issue V2.0 :)

From: rama <rama.rama_at_tiscali.it>
Date: Tue, 12 May 2009 18:39:25 +0200

>
>
> No BABABA should never be printed as grizzlyResponse.isSuspended()
> is always false, so you will enter the if and then return. The when
> you resume, the CompletionHandler.resume will be called. So the
> system.out will never be printed.
>
> Does it help?
>
> A+
>
> -- Jeanfrancois
>

Unfortunatly not, because BABBABA is diplayed on STDOUT, that's why i
am asking :S
it's quite strange, i have give to me the same anwsare that you give
to me, but unfortunalty seems that there is some error :(

Can you please try the code, and see if you never get "BABABABA" as
output? cos this is wrong, as we have pointed here.

best regards




>
>> Tnx for the assistance
>> -----test---
>>>
>>> import com.sun.grizzly.http.embed.
>>> GrizzlyWebServer;
>>> import com.sun.grizzly.tcp.CompletionHandler;
>>> import
>>> com.sun.grizzly.tcp.http11.GrizzlyAdapter;
>>> import com.sun.grizzly.tcp.
>>> http11.GrizzlyRequest;
>>> import com.sun.grizzly.tcp.http11.
>>> GrizzlyResponse;
>>>
>>> import java.io.IOException;
>>> import java.util.
>>> concurrent.LinkedBlockingQueue;
>>> import java.util.concurrent.TimeUnit;
>>>
>>>
>>> public class Suspend {
>>>
>>> public Suspend() {
>>> GrizzlyWebServer
>>> gws = new GrizzlyWebServer();
>>> gws.addGrizzlyAdapter(new
>>> SuspendTest());
>>> gws.getSelectorThread().setDisplayConfiguration
>>> (true);
>>> try {
>>> gws.start();
>>> } catch
>>> (IOException e) {
>>> e.printStackTrace(); //To change body of
>>> catch statement use File | Settings | File Templates.
>>> }
>>> }
>>>
>>>
>>> static LinkedBlockingQueue<GrizzlyResponse> queue = new
>>> LinkedBlockingQueue<GrizzlyResponse>();
>>> static {
>>>
>>> new
>>> Thread() {
>>> public void run() {
>>> while (true)
>>> {
>>> try {
>>> GrizzlyResponse s =
>>> queue.poll(1, TimeUnit.HOURS);
>>> Thread.sleep
>>> (1000);
>>> s.resume();
>>> } catch
>>> (Exception e) {
>>>
>>> }
>>> }
>>> }
>>>
>>> }.start();
>>> }
>>>
>>> public static void main(String args[]) {
>>>
>>> new Suspend();
>>> }
>>> class SuspendTest extends
>>> GrizzlyAdapter {
>>>
>>> public void service(final GrizzlyRequest
>>> grizzlyRequest, final GrizzlyResponse grizzlyResponse) {
>>>
>>> final String SID = "blabla";
>>> if (!grizzlyResponse.
>>> isSuspended()) {
>>> grizzlyResponse.suspend(100000,
>>> this,new CompletionHandler<SuspendTest>() {
>>>
>>> public void resumed(SuspendTest attachment) {
>>>
>>> try {
>>>
>>> attachment.resume(grizzlyResponse,SID);
>>>
>>> attachment.afterService
>>> (grizzlyRequest,
>>> grizzlyResponse);
>>> } catch (Exception e) {
>>>
>>>
>>> }
>>> }
>>>
>>> public void cancelled(SuspendTest
>>> attachment) {
>>>
>>> throw new Error("Request
>>> cancelled?!?");
>>>
>>> }
>>> });
>>>
>>> queue.add(grizzlyResponse);
>>> return;
>>> }
>>>
>>> System.out.println("BABABA");
>>> }
>>>
>>> private
>>> void resume(GrizzlyResponse grizzlyResponse,final String SID) {
>>>
>>> System.out.println("RESUMING");
>>> grizzlyResponse.
>>> setHeader("Set-Cookie", "SID="+SID);
>>> grizzlyResponse.
>>> setCharacterEncoding("UTF-8");
>>> grizzlyResponse.setStatus
>>> (200);
>>> grizzlyResponse.setContentType("text/xml");
>>>
>>> try {
>>> grizzlyResponse.getWriter().print
>>> ("<bla>hi</bla>");
>>> } catch (IOException e) {
>>>
>>> e.printStackTrace(); //To change body of catch
>>> statement use File | Settings | File Templates.
>>> }
>>> }
>>>
>>>
>>> }
>>> }
>>>
>>>
>>>
>>> Arriva Tiscali Mobile! Acquista la tua SIM Tiscali a soli €5 e
>>> scopri la semplicità e la convenienza del nuovo servizio per il
>>> tuo cellulare. Passa a Tiscali Mobile http://abbonati.tiscali.it/
>>> promo/tiscalimobile/
>>>
>>> --------------------------------------------------------------------
>>> -
>>> To unsubscribe, e-mail: dev-unsubscribe_at_grizzly.dev.java.net
>>> For additional commands, e-mail: dev-help_at_grizzly.dev.java.net
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe_at_grizzly.dev.java.net
>> For additional commands, e-mail: dev-help_at_grizzly.dev.java.net
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_grizzly.dev.java.net
> For additional commands, e-mail: dev-help_at_grizzly.dev.java.net
>