Author: remy.maucherat(a)jboss.com
Date: 2008-05-21 09:44:21 -0400 (Wed, 21 May 2008)
New Revision: 634
Modified:
trunk/java/org/jboss/web/cluster/ClusterListener.java
Log:
- Modify a bit the code to find the local address along with the jvmRoute.
Modified: trunk/java/org/jboss/web/cluster/ClusterListener.java
===================================================================
--- trunk/java/org/jboss/web/cluster/ClusterListener.java 2008-05-21 11:51:36 UTC (rev
633)
+++ trunk/java/org/jboss/web/cluster/ClusterListener.java 2008-05-21 13:44:21 UTC (rev
634)
@@ -103,8 +103,8 @@
* JMX registration information.
*/
protected ObjectName oname;
-
-
+
+
// ------------------------------------------------------------- Properties
@@ -125,7 +125,9 @@
public void setAddress(InetAddress proxyAddress) { this.proxyAddress = proxyAddress;
}
- // FIXME: probably useless
+ /**
+ * Most likely only useful for testing.
+ */
protected String proxyURL = "/";
public String getProxyURL() { return proxyURL; }
public void setProxyURL(String proxyURL) { this.proxyURL = proxyURL; }
@@ -270,33 +272,43 @@
services[i].getContainer().addContainerListener(this);
Engine engine = (Engine) services[i].getContainer();
- if (engine.getJvmRoute() == null) {
+ Connector connector =
findProxyConnector(engine.getService().findConnectors());
+ InetAddress localAddress =
+ (InetAddress)
IntrospectionUtils.getProperty(connector.getProtocolHandler(), "address");
+ if (engine.getJvmRoute() == null || localAddress == null) {
// Automagical JVM route (address + port + engineName)
try {
- Connector connector =
findProxyConnector(engine.getService().findConnectors());
- InetAddress localAddress =
- (InetAddress)
IntrospectionUtils.getProperty(connector.getProtocolHandler(), "address");
- String hostName = null;
if (localAddress == null) {
Socket connection = null;
if (proxyAddress == null) {
- connection = new Socket("127.0.0.1", proxyPort);
+ connection = new Socket(InetAddress.getLocalHost(),
proxyPort);
} else {
connection = new Socket(proxyAddress, proxyPort);
}
localAddress = connection.getLocalAddress();
+ if (localAddress != null) {
+
IntrospectionUtils.setProperty(connector.getProtocolHandler(), "address",
localAddress.getHostAddress());
+ } else {
+ // Should not happen
+
IntrospectionUtils.setProperty(connector.getProtocolHandler(), "address",
"127.0.0.1");
+ }
+ connection.close();
+ log.info("Detected local adress: [" +
localAddress.getHostAddress() + "]");
}
- if (localAddress != null) {
- hostName = localAddress.getHostName();
- } else {
- // Fallback
- hostName = "127.0.0.1";
+ if (engine.getJvmRoute() == null) {
+ String hostName = null;
+ if (localAddress != null) {
+ hostName = localAddress.getHostName();
+ } else {
+ // Fallback
+ hostName = "127.0.0.1";
+ }
+ String jvmRoute = hostName + ":" + connector.getPort()
+ ":" + engine.getName();
+ engine.setJvmRoute(jvmRoute);
+ log.info("Engine [" + engine.getName() + "] will
use jvmRoute value: [" + jvmRoute + "]");
}
- String jvmRoute = hostName + ":" + connector.getPort() +
":" + engine.getName();
- engine.setJvmRoute(jvmRoute);
- log.info("Engine [" + engine.getName() + "] will use
jvmRoute value: [" + jvmRoute + "]");
} catch (Exception e) {
- throw new IllegalStateException("JVMRoute must be set, automatic
generation failed", e);
+ throw new IllegalStateException("JVMRoute and Address must be
set on the connector", e);
}
}
@@ -584,7 +596,7 @@
InetAddress inetAddress =
(InetAddress) IntrospectionUtils.getProperty(connector.getProtocolHandler(),
"address");
if (inetAddress == null) {
- // FIXME: Return local address ? This is hard ...
+ // Should not happen
return "127.0.0.1";
} else {
return inetAddress.toString();
Show replies by date