Author: remy.maucherat(a)jboss.com
Date: 2008-06-10 07:14:12 -0400 (Tue, 10 Jun 2008)
New Revision: 663
Modified:
trunk/java/org/jboss/web/cluster/ClusterListener.java
trunk/java/org/jboss/web/cluster/mbeans-descriptors.xml
Log:
- Add addProxy and removeProxy.
- Found NPE location (it is a harmless info logging, why is it always reported as a major
issue ?).
Modified: trunk/java/org/jboss/web/cluster/ClusterListener.java
===================================================================
--- trunk/java/org/jboss/web/cluster/ClusterListener.java 2008-06-10 09:39:24 UTC (rev
662)
+++ trunk/java/org/jboss/web/cluster/ClusterListener.java 2008-06-10 11:14:12 UTC (rev
663)
@@ -138,6 +138,18 @@
protected boolean init = false;
+ /**
+ * Add proxy list.
+ */
+ protected ArrayList<Proxy> addProxies = new ArrayList<Proxy>();
+
+
+ /**
+ * Remove proxy list.
+ */
+ protected ArrayList<Proxy> removeProxies = new ArrayList<Proxy>();
+
+
// ------------------------------------------------------------- Properties
@@ -456,6 +468,11 @@
if (source instanceof Server) {
if (this.proxyList == null) {
+ // if (advertise) {
+ // FIXME: enable simple advertise service in this case, most likely
+ // using a flag
+ // } else {
+ // Default to a httpd on localhost on the default port
proxies = new Proxy[1];
proxies[0] = new Proxy();
} else {
@@ -521,6 +538,37 @@
/**
+ * Add proxy.
+ */
+ public synchronized void addProxy(String host, int port) {
+ Proxy proxy = new Proxy();
+ try {
+ proxy.address = InetAddress.getByName(host);
+ } catch (Exception e) {
+ throw new IllegalArgumentException(e);
+ }
+ proxy.port = port;
+ proxy.state = State.ERROR;
+ addProxies.add(proxy);
+ }
+
+
+ /**
+ * Remove proxy.
+ */
+ public synchronized void removeProxy(String host, int port) {
+ Proxy proxy = new Proxy();
+ try {
+ proxy.address = InetAddress.getByName(host);
+ } catch (Exception e) {
+ throw new IllegalArgumentException(e);
+ }
+ proxy.port = port;
+ removeProxies.add(proxy);
+ }
+
+
+ /**
* Retrieves the full proxy configuration. To be used through JMX or similar.
*
* response: HTTP/1.1 200 OK
@@ -611,39 +659,6 @@
/**
- * Parse proxy list.
- */
- protected void parseProxyList(String list) {
- if (list == null) {
- proxies = new Proxy[1];
- proxies[0] = new Proxy();
- } else {
- ArrayList<Proxy> proxyList = new ArrayList<Proxy>();
- StringTokenizer tok = new StringTokenizer(list, ",");
- while (tok.hasMoreTokens()) {
- String token = tok.nextToken().trim();
- Proxy proxy = new Proxy();
- int pos = token.indexOf(':');
- String address = null;
- if (pos > 0) {
- address = token.substring(0, pos);
- proxy.port = Integer.parseInt(token.substring(pos + 1));
- } else {
- address = token;
- }
- try {
- proxy.address = InetAddress.getByName(address);
- } catch (Exception e) {
- throw new IllegalArgumentException(e);
- }
- proxyList.add(proxy);
- }
- proxies = proxyList.toArray(new Proxy[0]);
- }
- }
-
-
- /**
* Send commands to the front end server assocaited with the startup of the
* node.
*/
@@ -882,6 +897,39 @@
* @param engine
*/
protected void status(Engine engine) {
+
+ // Check to add or remove proxies, and rebuild a new list if needed
+ synchronized (this) {
+ if (!addProxies.isEmpty() || !removeProxies.isEmpty()) {
+ ArrayList<Proxy> currentProxies = new ArrayList<Proxy>();
+ for (int i = 0; i < proxies.length; i++) {
+ currentProxies.add(proxies[i]);
+ }
+ for (int i = 0; i < addProxies.size(); i++) {
+ if (!currentProxies.contains(addProxies.get(i))) {
+ currentProxies.add(addProxies.get(i));
+ }
+ }
+ for (int i = 0; i < removeProxies.size(); i++) {
+ if (currentProxies.contains(removeProxies.get(i))) {
+ currentProxies.remove(removeProxies.get(i));
+ }
+ }
+ addProxies.clear();
+ removeProxies.clear();
+ proxies = currentProxies.toArray(new Proxy[0]);
+ // Reset all connections
+ if (connections != null) {
+ for (int i = 0; i < connections.length; i++) {
+ closeConnection(i);
+ }
+ }
+ connections = new Socket[proxies.length];
+ connectionReaders = new BufferedReader[proxies.length];
+ connectionWriters = new BufferedWriter[proxies.length];
+ }
+ }
+
Proxy[] local = proxies;
for (int i = 0; i < local.length; i++) {
if (local[i].state == State.ERROR) {
@@ -1179,27 +1227,29 @@
String message = null;
String errorType = null;
int contentLength = 0;
- try {
- responseStatus =
responseStatus.substring(responseStatus.indexOf(' ') + 1,
responseStatus.indexOf(' ', responseStatus.indexOf(' ') + 1));
- status = Integer.parseInt(responseStatus);
- String header = reader.readLine();
- while (!"".equals(header)) {
- int colon = header.indexOf(':');
- String headerName = header.substring(0, colon).trim();
- String headerValue = header.substring(colon + 1).trim();
- if ("version".equalsIgnoreCase(headerName)) {
- version = headerValue;
- } else if ("type".equalsIgnoreCase(headerName)) {
- errorType = headerValue;
- } else if ("mess".equalsIgnoreCase(headerName)) {
- message = headerValue;
- } else if
("content-length".equalsIgnoreCase(headerName)) {
- contentLength = Integer.parseInt(headerValue);
+ if (responseStatus != null) {
+ try {
+ responseStatus =
responseStatus.substring(responseStatus.indexOf(' ') + 1,
responseStatus.indexOf(' ', responseStatus.indexOf(' ') + 1));
+ status = Integer.parseInt(responseStatus);
+ String header = reader.readLine();
+ while (!"".equals(header)) {
+ int colon = header.indexOf(':');
+ String headerName = header.substring(0, colon).trim();
+ String headerValue = header.substring(colon + 1).trim();
+ if ("version".equalsIgnoreCase(headerName)) {
+ version = headerValue;
+ } else if ("type".equalsIgnoreCase(headerName)) {
+ errorType = headerValue;
+ } else if ("mess".equalsIgnoreCase(headerName)) {
+ message = headerValue;
+ } else if
("content-length".equalsIgnoreCase(headerName)) {
+ contentLength = Integer.parseInt(headerValue);
+ }
+ header = reader.readLine();
}
- header = reader.readLine();
+ } catch (Exception e) {
+ log.info(sm.getString("clusterListener.error.parse",
command), e);
}
- } catch (Exception e) {
- log.info(sm.getString("clusterListener.error.parse",
command), e);
}
// Mark as error if the front end server did not return 200; the
configuration will
@@ -1355,6 +1405,23 @@
}
}
+ public boolean equals(Object o) {
+ if (o instanceof Proxy) {
+ Proxy compare = (Proxy) o;
+ if (port != compare.port) {
+ return false;
+ }
+ if (compare.address == null) {
+ if (address == null) {
+ return true;
+ }
+ } else if ((compare.address.equals(address)) && port ==
compare.port) {
+ return true;
+ }
+ }
+ return false;
+ }
+
}
Modified: trunk/java/org/jboss/web/cluster/mbeans-descriptors.xml
===================================================================
--- trunk/java/org/jboss/web/cluster/mbeans-descriptors.xml 2008-06-10 09:39:24 UTC (rev
662)
+++ trunk/java/org/jboss/web/cluster/mbeans-descriptors.xml 2008-06-10 11:14:12 UTC (rev
663)
@@ -93,6 +93,30 @@
impact="ACTION"
returnType="boolean"/>
+ <operation name="addProxy"
+ description="Add a proxy"
+ impact="ACTION"
+ returnType="void">
+ <parameter name="host"
+ description="Proxy address"
+ type="java.lang.String"/>
+ <parameter name="port"
+ description="Proxy port"
+ type="int"/>
+ </operation>
+
+ <operation name="removeProxy"
+ description="Remove a proxy"
+ impact="ACTION"
+ returnType="void">
+ <parameter name="host"
+ description="Proxy address"
+ type="java.lang.String"/>
+ <parameter name="port"
+ description="Proxy port"
+ type="int"/>
+ </operation>
+
</mbean>
</mbeans-descriptors>
Show replies by date