Author: ron.sigal(a)jboss.com
Date: 2008-05-22 20:04:43 -0400 (Thu, 22 May 2008)
New Revision: 4232
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/Connector.java
Log:
JBREM-983: Added support for multihome facility in XML configuration.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transport/Connector.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transport/Connector.java 2008-05-22
22:38:41 UTC (rev 4231)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/Connector.java 2008-05-23
00:04:43 UTC (rev 4232)
@@ -50,8 +50,10 @@
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
@@ -538,6 +540,11 @@
// now create a map for all the sub attributes
Map paramConfig = new HashMap();
+
+ // In case of a multihome configuration.
+ List homes = new ArrayList();
+ List connectHomes = new ArrayList();
+
NodeList invokerAttributes = invokerNode.getChildNodes();
int len = invokerAttributes.getLength();
for (int x = 0; x < len; x++)
@@ -547,7 +554,18 @@
{
String name =
attr.getAttributes().getNamedItem("name").getNodeValue();
String value = attr.getFirstChild().getNodeValue();
- invokerConfig.put(name, value);
+ if ("homes".equals(name))
+ {
+ processHomes(attr, "home", homes);
+ }
+ else if ("connecthomes".equals(name))
+ {
+ processHomes(attr, "connecthome", connectHomes);
+ }
+ else
+ {
+ invokerConfig.put(name, value);
+ }
Node isParamAttribute =
attr.getAttributes().getNamedItem("isParam");
if (isParamAttribute != null &&
Boolean.valueOf(isParamAttribute.getNodeValue()).booleanValue())
{
@@ -555,32 +573,87 @@
}
}
}
+
+ if (homes.isEmpty() && !connectHomes.isEmpty())
+ {
+ throw new Exception("Configuration has a " +
InvokerLocator.CONNECT_HOMES_KEY +
+ " without a " +
InvokerLocator.HOMES_KEY);
+ }
// should now have my map with all my attributes, now need to look for
// specific attributes that will impact the locator uri.
+
String clientConnectAddress = (String)
invokerConfig.get("clientConnectAddress");
String clientConnectPort = (String)
invokerConfig.get("clientConnectPort");
String serverBindAddress = (String)
invokerConfig.get("serverBindAddress");
String serverBindPort = (String)
invokerConfig.get("serverBindPort");
+ String localHostAddress = SecurityUtility.getLocalHost().getHostAddress();
+
+ String tempURI = null;
String path = (String) invokerConfig.get("path");
-
- String localHostAddress = SecurityUtility.getLocalHost().getHostAddress();
- String host = clientConnectAddress != null ? clientConnectAddress :
serverBindAddress != null ? serverBindAddress : localHostAddress;
- int port = clientConnectPort != null ? Integer.parseInt(clientConnectPort)
: serverBindPort != null ? Integer.parseInt(serverBindPort) :
PortUtil.findFreePort(serverBindAddress != null ? serverBindAddress : localHostAddress);
-
- // finally, let's bild the invoker uri
- String tempURI = transport + "://" + host + ":" +
port;
-
- // append path if there is one
- if (path != null)
+
+ if (homes.isEmpty() && connectHomes.isEmpty())
{
- tempURI += "/" + path;
+ int port = clientConnectPort != null
+ ? Integer.parseInt(clientConnectPort)
+ : serverBindPort != null
+ ? Integer.parseInt(serverBindPort)
+ : PortUtil.findFreePort(serverBindAddress != null
+ ? serverBindAddress
+ : localHostAddress);
+ String host = clientConnectAddress != null
+ ? clientConnectAddress
+ : serverBindAddress != null
+ ? serverBindAddress
+ : localHostAddress;
+
+ // finally, let's build the invoker uri
+ tempURI = transport + "://" + host + ":" + port;
+ if (path != null)
+ {
+ tempURI += "/" + path;
+ }
}
+ else
+ {
+ String port = clientConnectPort != null
+ ? ":" + clientConnectPort
+ : serverBindPort != null
+ ? ":" + serverBindPort
+ : "";
+ tempURI = transport + "://multihome" + port;
+ if (path != null)
+ {
+ tempURI += "/" + path;
+ }
+ tempURI += "/?";
+
+ Iterator it = homes.iterator();
+ tempURI += "homes=" + it.next();
+ while (it.hasNext())
+ {
+ tempURI += "!" + it.next();
+ }
+
+ if (!connectHomes.isEmpty())
+ {
+ tempURI += "&connecthomes=";
+ it = connectHomes.iterator();
+ tempURI += it.next();
+ while (it.hasNext())
+ {
+ tempURI += "!" + it.next();
+ }
+ }
+ }
// any params to add to the uri?
if (paramConfig.size() > 0)
{
- tempURI += "/?";
+ if (tempURI.indexOf("/?") < 0)
+ tempURI += "/?";
+ else
+ tempURI += "&";
Iterator keyItr = paramConfig.keySet().iterator();
if (keyItr.hasNext())
{
@@ -602,15 +675,39 @@
{
log.error("Invoker element within Configuration attribute does not
contain a transport attribute.");
}
-
}
}
catch (Exception e)
{
+ log.error("Error configuring invoker for connector: " +
e.getMessage());
log.debug("Error configuring invoker for connector.", e);
throw new IllegalStateException("Error configuring invoker for connector.
Can not continue without invoker.");
}
}
+
+ private void processHomes(Node node, String homeType, List homes)
+ {
+ NodeList nodes = node.getChildNodes();
+ for (int i = 0; i < nodes.getLength(); i++)
+ {
+ Node child = nodes.item(i);
+ if (Node.ELEMENT_NODE == child.getNodeType())
+ {
+ if (homeType.equals(child.getNodeName()))
+ {
+ NodeList children = child.getChildNodes();
+ for (int k = 0; k < children.getLength(); k++)
+ {
+ Node grandchild = children.item(k);
+ if (Node.TEXT_NODE == grandchild.getNodeType())
+ {
+ homes.add(grandchild.getNodeValue());
+ }
+ }
+ }
+ }
+ }
+ }
private void getInvokerConfigFromServerConfiguration(Map invokerConfig) throws
Exception
{
@@ -755,6 +852,7 @@
}
catch (Exception e)
{
+ log.error("Error configuring invoker for connector: " +
e.getMessage());
log.debug("Error configuring invoker for connector.", e);
throw new IllegalStateException("Error configuring invoker from
configuration POJO. Can not continue without invoker.");
}
Show replies by date