On 10/19/11 23:38 , Niclas Hedhman wrote:
On Wed, Oct 19, 2011 at 3:17 PM, Rickard Öberg<[email protected]>  wrote:

One way to fix it is to allow handlers to make the calls to the REST client,
but don't perform them until the handler method returns, so that the stack
never grows in size.

And one should implement the equivalent of back/forward-button as well?

Not sure how useful that would be for automated REST API clients.

In any case, one of the main issues right now is how to keep the call stack from growing. It comes for example from this: } ).onQuery( "commandwithvalue", Links.class, new ResultHandler<Links>()
        {
            @Override
public void handleResult( Links result, ContextResourceClient client )
            {
                Link link = LinksUtil.withId( "right", result);

                client.command( link );
            }
        } )
---
Here the client.command(link) call will execute the next step, and that will in turn cause another handler to be called, causing the stack to constantly grow.

The most obvious way to remove this is to make the handler return the next step instead, or null if finished.

I.e. something like:
} ).onQuery( "commandwithvalue", Links.class, new ResultHandler<Links>()
        {
            @Override
public HandlerCommand handleResult( Links result, ContextResourceClient client )
            {
                Link link = LinksUtil.withId( "right", result);

                return client.command( link );
            }
        } )
---
I.e. client.command(link) builds up a command-object of type HandlerCommand that is returned. This also ensures that a handle-method only does one thing, and don't try to get imperative by making several calls to client. The actual work happens after handleResult() has finished, and the next handler is then invoked. The whole process stops if either a handler returns null, or there is no handler registered for the result of a call. That feels like the cleanest way to do this.

With the above there is no reason why a client cannot work indefinitely against a REST API, doing whatever needs to be done.

/Rickard

_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev

Reply via email to