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