cxf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sergey Beryozkin (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CXF-6389) set initialSuspend=true incorrectly when resume the asyncresponse
Date Wed, 06 May 2015 21:07:00 GMT

    [ https://issues.apache.org/jira/browse/CXF-6389?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14531413#comment-14531413
] 

Sergey Beryozkin commented on CXF-6389:
---------------------------------------

I'm a bit confused about the source of the problem.

{code:java}
    public synchronized boolean isSuspended() {
        return initialSuspend || cont.isPending();
    }
{code}

after the test code resumes AsyncResponse isSuspended() should return 'false'.
when cancel() is called, it returns false if isSuspended() returns false.

So the question is why does isSuspended() return true after resume() was called. initialSuspend
is false at that stage, so do you see cont.isPending() returning true ?

Cheers, Sergey

> set initialSuspend=true incorrectly when resume the asyncresponse
> -----------------------------------------------------------------
>
>                 Key: CXF-6389
>                 URL: https://issues.apache.org/jira/browse/CXF-6389
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 3.0.0, 3.0.3, 2.7.15
>            Reporter: iris ding
>
> My Resource class: 
> @Path("resource")
> public class Resource
> {
>    public static final String RESUMED = "Response resumed";
>    public static final String FALSE = "A method returned false";
>    public static final String TRUE = "A method return true";
>    //
>    private static final AsyncResponseBlockingQueue[] stage = {
>            new AsyncResponseBlockingQueue(1),
>            new AsyncResponseBlockingQueue(1),
>            new AsyncResponseBlockingQueue(1)};
>    @GET
>    @Path("suspend")
>    public void suspend(@Suspended AsyncResponse asyncResponse)
>    {
>       stage[0].add(asyncResponse);
>    }
>    
>    @GET
>    @Path("cancelvoid")
>    public String cancel(@QueryParam("stage") String stage)
>    {
>       AsyncResponse response = takeAsyncResponse(stage);
>       boolean ret = response.cancel();
>       System.out.println("*** response.cancel() 1 " + ret);
>       ret &= response.cancel();
>       System.out.println("*** response.cancel() 2 " + ret);
>       addResponse(response, stage);
>       return ret ? TRUE : FALSE;
>    }
>    
>     @POST
>    @Path("resume")
>    public String resume(@QueryParam("stage") String stage, String response)
>    {
>       AsyncResponse async = takeAsyncResponse(stage);
>       boolean b = resume(async, response);
>       addResponse(async, stage);
>       return b ? TRUE : FALSE;
>    }
>    
>      protected static AsyncResponse takeAsyncResponse(String stageId)
>    {
>       return takeAsyncResponse(Integer.parseInt(stageId));
>    }
>    protected static AsyncResponse takeAsyncResponse(int stageId)
>    {
>       final ResponseBuilder error = createErrorResponseBuilder();
>       AsyncResponse asyncResponse = null;
>       try
>       {
>          asyncResponse = stage[stageId].take();
>       }
>       catch (InterruptedException e)
>       {
>          throw new WebApplicationException(error.entity(
>                  "ArrayBlockingQueue#take").build());
>       }
>       return asyncResponse;
>    }
>    protected static final void addResponse(AsyncResponse response, String stageId)
>    {
>       int id = Integer.parseInt(stageId) + 1;
>       if (id != stage.length)
>          stage[id].add(response);
>    }
>    protected static boolean resume(AsyncResponse takenResponse, Object response)
>    {
>       return takenResponse.resume(response);
>    }
>    protected static ResponseBuilder createErrorResponseBuilder()
>    {
>       return Response.status(Status.EXPECTATION_FAILED);
>    }
>    }



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message