dev@grizzly.java.net

Re: suspend/resume issue V2.0 :)

From: rama <rama.rama_at_tiscali.it>
Date: Tue, 12 May 2009 10:38:45 +0200

>

Hello!

I am still here to bother you with this piece of code (this was the
same that i have used for issue submittion)
Let's take a look to

public void service(...)

for what i have understand
in this case the last System.out should never be called, but
eventually it will be...

> 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");
> }

Since all the request when come arent "suspended" they are all queued
and stopped.
Also, the request, when resumed, shouldn't pass on service, isn't it?
they have to pass just from the callback that i put, ie: resume/
afterService.
For that reason the print of "BABABA" is suspected, at least for me :)

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
>