Author: jfrederic.clere(a)jboss.com
Date: 2009-10-09 11:54:26 -0400 (Fri, 09 Oct 2009)
New Revision: 1188
Modified:
branches/2.1.x/java/org/apache/catalina/ha/backend/CollectedInfo.java
branches/2.1.x/java/org/apache/catalina/ha/backend/HeartbeatListener.java
branches/2.1.x/java/org/apache/catalina/ha/backend/MultiCastSender.java
branches/2.1.x/java/org/apache/catalina/ha/backend/TcpSender.java
Log:
Add a local bind for box with multi IP otherwise httpd may use the wrong port.
Modified: branches/2.1.x/java/org/apache/catalina/ha/backend/CollectedInfo.java
===================================================================
--- branches/2.1.x/java/org/apache/catalina/ha/backend/CollectedInfo.java 2009-10-09
15:06:35 UTC (rev 1187)
+++ branches/2.1.x/java/org/apache/catalina/ha/backend/CollectedInfo.java 2009-10-09
15:54:26 UTC (rev 1188)
@@ -44,11 +44,15 @@
int ready;
int busy;
+ int port = 0;
+ String host = null;
+
public CollectedInfo(String host, int port) throws Exception {
init(host, port);
}
public void init(String host, int port) throws Exception {
- String sport = Integer.toString(port);
+ int iport = 0;
+ String shost = null;
mBeanServer = Registry.getRegistry(null, null).getMBeanServer();
String onStr = "*:type=ThreadPool,*";
ObjectName objectName = new ObjectName(onStr);
@@ -58,24 +62,29 @@
ObjectInstance oi = iterator.next();
objName = oi.getObjectName();
String name = objName.getKeyProperty("name");
+
/* Name are:
* http-8080
* jk-10.33.144.3-8009
* jk-jfcpc%2F10.33.144.3-8009
*/
+ String [] elenames = name.split("-");
+ String sport = elenames[elenames.length-1];
+ iport = Integer.parseInt(sport);
+ String [] shosts = elenames[1].split("%2F");
+ shost = shosts[0];
+
if (port==0 && host==null)
break; /* Take the first one */
- String [] elenames = name.split("-");
- if (elenames[elenames.length-1].compareTo(sport) != 0)
- continue; /* port doesn't match */
- if (host==null)
+ if (host==null && iport==port)
break; /* Only port done */
- String [] shosts = elenames[1].split("%2F");
- if (shosts[0].compareTo(host) == 0)
+ if (shost.compareTo(host) == 0)
break; /* Done port and host are the expected ones */
}
if (objName == null)
- throw(new Exception("Can't find connector for " + host +
":" + sport));
+ throw(new Exception("Can't find connector for " + host +
":" + port));
+ this.port = iport;
+ this.host = shost;
}
Modified: branches/2.1.x/java/org/apache/catalina/ha/backend/HeartbeatListener.java
===================================================================
--- branches/2.1.x/java/org/apache/catalina/ha/backend/HeartbeatListener.java 2009-10-09
15:06:35 UTC (rev 1187)
+++ branches/2.1.x/java/org/apache/catalina/ha/backend/HeartbeatListener.java 2009-10-09
15:54:26 UTC (rev 1188)
@@ -85,27 +85,32 @@
sender = new MultiCastSender();
else
sender = new TcpSender();
-
- try {
- sender.init(this);
- } catch (Exception ex) {
- log.error("Unable to initialize Sender: " + ex);
- sender = null;
- return;
- }
}
/* Read busy and ready */
if (coll == null) {
try {
coll = new CollectedInfo(host, port);
+ this.port = coll.port;
+ this.host = coll.host;
} catch (Exception ex) {
log.error("Unable to initialize info collection: " + ex);
coll = null;
return;
}
}
+
+ /* Start or restart sender */
try {
+ sender.init(this);
+ } catch (Exception ex) {
+ log.error("Unable to initialize Sender: " + ex);
+ sender = null;
+ return;
+ }
+
+ /* refresh the connector information and send it */
+ try {
coll.refresh();
} catch (Exception ex) {
log.error("Unable to collect load information: " + ex);
Modified: branches/2.1.x/java/org/apache/catalina/ha/backend/MultiCastSender.java
===================================================================
--- branches/2.1.x/java/org/apache/catalina/ha/backend/MultiCastSender.java 2009-10-09
15:06:35 UTC (rev 1187)
+++ branches/2.1.x/java/org/apache/catalina/ha/backend/MultiCastSender.java 2009-10-09
15:54:26 UTC (rev 1188)
@@ -22,6 +22,7 @@
import java.net.MulticastSocket;
import java.net.InetAddress;
+import java.net.InetSocketAddress;
import java.net.DatagramPacket;
import java.io.UnsupportedEncodingException;
@@ -47,7 +48,13 @@
if (s == null) {
try {
group = InetAddress.getByName(config.getGroup());
- s = new MulticastSocket(config.getMultiport());
+ if (config.host != null) {
+ InetAddress addr = InetAddress.getByName(config.host);
+ InetSocketAddress addrs = new InetSocketAddress(addr,
config.getMultiport());
+ s = new MulticastSocket(addrs);
+ } else
+ s = new MulticastSocket(config.getMultiport());
+
s.setTimeToLive(config.getTtl());
s.joinGroup(group);
} catch (Exception ex) {
Modified: branches/2.1.x/java/org/apache/catalina/ha/backend/TcpSender.java
===================================================================
--- branches/2.1.x/java/org/apache/catalina/ha/backend/TcpSender.java 2009-10-09 15:06:35
UTC (rev 1187)
+++ branches/2.1.x/java/org/apache/catalina/ha/backend/TcpSender.java 2009-10-09 15:54:26
UTC (rev 1188)
@@ -26,6 +26,7 @@
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.InetAddress;
+import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.StringTokenizer;
@@ -89,7 +90,16 @@
for (int i = 0; i < connections.length; i++) {
if (connections[i] == null) {
try {
- connections[i] = new Socket(proxies[i].address, proxies[i].port);
+ if (config.host != null) {
+ connections[i] = new Socket();
+ InetAddress addr = InetAddress.getByName(config.host);
+ InetSocketAddress addrs = new InetSocketAddress(addr, 0);
+ connections[i].setReuseAddress(true);
+ connections[i].bind(addrs);
+ addrs = new InetSocketAddress(proxies[i].address,
proxies[i].port);
+ connections[i].connect(addrs);
+ } else
+ connections[i] = new Socket(proxies[i].address,
proxies[i].port);
connectionReaders[i] = new BufferedReader(new
InputStreamReader(connections[i].getInputStream()));
connectionWriters[i] = new BufferedWriter(new
OutputStreamWriter(connections[i].getOutputStream()));
} catch (Exception ex) {
Show replies by date