Author: remy.maucherat(a)jboss.com
Date: 2008-05-13 12:20:12 -0400 (Tue, 13 May 2008)
New Revision: 618
Modified:
trunk/java/org/jboss/web/cluster/ClusterListener.java
Log:
- Timeout.
- Add load to STATUS.
- Add state field.
Modified: trunk/java/org/jboss/web/cluster/ClusterListener.java
===================================================================
--- trunk/java/org/jboss/web/cluster/ClusterListener.java 2008-05-13 15:40:30 UTC (rev
617)
+++ trunk/java/org/jboss/web/cluster/ClusterListener.java 2008-05-13 16:20:12 UTC (rev
618)
@@ -75,7 +75,10 @@
// ---------------------------------------------- Constants
+
+ protected enum State { OK, ERROR };
+
// ---------------------------------------------- Properties
@@ -94,7 +97,13 @@
public void setProxyURL(String proxyURL) { this.proxyURL = proxyURL; }
+ protected int socketTimeout = 5000;
+ public int getSocketTimeout() { return socketTimeout; }
+ public void setSocketTimeout(int socketTimeout) { this.socketTimeout = socketTimeout;
}
+
+
protected UEncoder encoder = new UEncoder();
+ protected State state = State.OK;
// ---------------------------------------------- LifecycleListener Methods
@@ -250,6 +259,7 @@
Connector connector = findProxyConnector(engine.getService().findConnectors());
HashMap<String, String> parameters = new HashMap<String, String>();
parameters.put("JVMRoute", engine.getJvmRoute());
+ parameters.put("Load", "1");
// Send STATUS request
sendRequest("STATUS", false, parameters);
@@ -352,6 +362,7 @@
Writer writer = null;
CharChunk keyCC = null;
Socket connection = null;
+ boolean ok = false;
try {
// First, encode the POST body
Iterator<String> keys = parameters.keySet().iterator();
@@ -363,7 +374,9 @@
}
keyCC = encoder.encodeURL(key, 0, key.length());
keyCC.append('=');
- keyCC = encoder.encodeURL(value, 0, value.length());
+ if (value != null) {
+ keyCC = encoder.encodeURL(value, 0, value.length());
+ }
if (keys.hasNext()) {
keyCC.append('&');
}
@@ -375,6 +388,7 @@
} else {
connection = new Socket(proxyAddress, proxyPort);
}
+ connection.setSoTimeout(socketTimeout);
String requestLine = command + " " + ((wildcard) ? "*" :
proxyURL) + " HTTP/1.0";
int contentLength = keyCC.getLength();
@@ -389,6 +403,18 @@
connection.setDoInput(true);
connection.setUseCaches(false);
connection.connect();*/
+
+ /*
+response: HTTP/1.1 200 OK
+response:
+node: [1:1] JVMRoute: node1 Domain: [øcx97;x97;¿À°] Host: 127.0.0.1 Port: 8009 Type:
ajp
+host: 1 [] vhost: 1 node: 1
+context: 1 [/] vhost: 1 node: 1 status: 1
+context: 2 [/myapp] vhost: 1 node: 1 status: 1
+context: 3 [/host-manager] vhost: 1 node: 1 status: 1
+context: 4 [/docs] vhost: 1 node: 1 status: 1
+context: 5 [/manager] vhost: 1 node: 1 status: 1
+ */
writer = new BufferedWriter(new
OutputStreamWriter(connection.getOutputStream()));
writer.write(requestLine);
@@ -414,6 +440,7 @@
}
//System.out.println("Response body: " + result.toString());
// FIXME: probably parse away the request header; generate an error if not
200 ?
+ ok = true;
return result.toString();
} catch (IOException e) {
@@ -443,6 +470,9 @@
// Ignore
}
}
+ if (!ok) {
+ state = State.ERROR;
+ }
}
return null;
}