Hi Thierry,

Thank you for your code it solved a part of my problem: something was wrong with the "max" value. But, still I can not run more than 2 client requests on a server (even when setting the maxConnectionsPerHost to a value > 2): I executed your code and got 6 "put" instead of 9. I don't know which version of restlet you use but I use 1.0.10. So maybe I should update it.

best regards,
Hélia



Since the sample
Thierry Boileau a écrit :
Hi Hélia,

I think there is a mistake in HelloWorldResource2. It requests the following resource "http://127.0.0.1:8181/helloworld2"; whereas the URI of the HelloWorldResource is "http://127.0.0.1:8181/helloworld1";. Having said that, it does not explain why you get this trace: "Hello Client 2 1" which shows that the first resource has been called again. However, I notice something more fundamental. Since a new Resource instance is created for each incoming request, the "max" attribute will always have the "0" value. You must use instances of Restlet sub class instead, or you can store the "max" value outside the resource, in a database for example.

best regards,
Thierry Boileau


Maybe I missed something so here is the full sample code I use to test if the problem is solved. I have only two servers - instead of 3 - and the problem is still the same. Thx for your insterest

public class HelloWorldResource extends Resource {
   private int max = 0;
   ...
  public void handlePut() {

       try {
           Request r = getRequest();
           String s = r.getEntity().getText();

           max++;
           System.out.println("Hello " + s + " " + max);
           if (max < 3) {

Request req = new Request(Method.PUT, "http://127.0.0.1:8282";
                       + "/helloworld2");
               Client client = new Client(Protocol.HTTP);
               req.setEntity("Client 1 ", MediaType.TEXT_PLAIN);
               client.getContext().getParameters().set(
                       "maxConnectionsPerHost", "20", true);
               Response response = client.handle(req);
           }

       } catch (IOException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
       }

   }
}

public class HelloWorldResource2 extends Resource {
   private int max = 0;
   ...
  public void handlePut() {

       try {
           Request r = getRequest();
           String s = r.getEntity().getText();

           max++;
           System.out.println("Hello " + s + " " + max);
           if (max < 3) {

Request req = new Request(Method.PUT, "http://127.0.0.1:8181";
                       + "/helloworld2");
               Client client = new Client(Protocol.HTTP);
               req.setEntity("Client 1 ", MediaType.TEXT_PLAIN);
               client.getContext().getParameters().set(
                       "maxConnectionsPerHost", "20", true);
               Response response = client.handle(req);
           }

       } catch (IOException e) {
           e.printStackTrace();
       }

   }
}

And finally the main:

public class FirstStepsMain {

   public static void main(String[] args) {
       try {
                   Component component = new Component();
           component.getServers().add(Protocol.HTTP, 8181);
          component.getDefaultHost().attach("/helloworld",
                   new FirstStepApplication(component.getContext()));
           component.start();
                     Component component2 = new Component();
           component2.getServers().add(Protocol.HTTP, 8282);
           component2.getDefaultHost().attach("/helloworld2",
                   new FirstStepApplication2(component.getContext()));
           component2.start();
Request req = new Request(Method.PUT, "http://127.0.0.1:8181";
                       + "/helloworld");
           Client client = new Client(Protocol.HTTP);
           req.setEntity("Client init ", MediaType.TEXT_PLAIN);
           client.getContext().getParameters().set(
                     "maxConnectionsPerHost", "20", true);
           Response response1 = client.handle(req);
           Representation output1 = response1.getEntity();

           output1.write(System.out);

       } catch (Exception e) {
           // Something is wrong.
           e.printStackTrace();
       }
   }
}

System.out shows:
Hello Client init  1
Hello Client 1  1
Hello Client 2  1
whereas I should get:
Hello Client init  1
Hello Client 1  1
Hello Client 2  1
Hello Client 1  2
Hello Client 2  2

Rob Heittman a écrit :
I just set up a little test of the pattern and it runs fine, but of course my server doesn't do any actual work. Is it possible that a blocking I/O operation occurs in the "..." part of your sample code?

On Tue, Jun 3, 2008 at 12:17 PM, Hélia Pouyllau <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>> wrote:


    Sorry, to insist but I have tried all that (new Client object,
    etc.). The maximum number of connection per host is the one I have
    set. This is why I though the problem could maybe come from the
    server side.

    Thx again for your help

    Hélia






Reply via email to