2

I'm just playing and testing a bit with the Restlet Client Api 2.2, but I don't get a non-blocking asynchronous request with a callback to work. I already have googled extensively but really not found an answer to a (working) non-blocking solution.

I have the following two approaches:

Approach 1 ( Client - Request ):

Client c = new Client(Protocol.HTTP);
Request r = new Request(Method.GET, url);
System.out.println("START1");
c.handle(r, new Uniform() {
    @Override
    public void handle(Request request, Response response) {
        int statusCode = response.getStatus().getCode();
        System.out.println(statusCode);
    }
});
System.out.println("START2");

Approach 2 ( ClientResource - setOnResponse() - get() ):

ClientResource cr = new ClientResource(url);
cr.setOnResponse(new Uniform() {
    @Override
    public void handle(Request request, Response response) {
        int statusCode = response.getStatus().getCode();
        System.out.println(statusCode);
    }
});

System.out.println("START1");
cr.get();
System.out.println("START2");

The Console-Output for both approaches is always:

START1
Starting the internal HTTP client

SOME WAITING HERE

200
START2

Can anyone give me a hint to make one of these approaches non-blocking? Is that at all possible with the Restlet API? What am I missing, do I need another connector or must I define a seperate thread for the request myself?

mueldajo
  • 21
  • 3

1 Answers1

1

I make a quick answer, an issue has been created: https://github.com/restlet/restlet-framework-java/issues/943

Initially the support of asynchronous was available using the internal nio connector. As this connector is not fully stabilized, it has been decided to extract it from the core module and expose it inside a dedicated org.restlet.ext.nio module. This explains why your code is blocking, as the current internal connector (in both 2.2 and 2.3 branches) does not support it.

At this time, the support is available using the nio extension, but this extension is not fully stabilized yet. So we are not inclined to encourage you to use it. We are working on another scenario where we rely on the client connector provided by Jetty. Stay tuned.

user229044
  • 232,980
  • 40
  • 330
  • 338
Thierry Boileau
  • 866
  • 5
  • 8
  • Well I got the setOnResponse non-blocking to work in my env, which is 2.0.8. I am hoping the stability issues you mention are not going to be an issue for us, as I really want to enable client async functionality. – MattC Feb 19 '15 at 19:53