[jboss-cvs] JBossRemoting/src/main/org/jboss/remoting/transport ...
Ron Sigal
ron_sigal at yahoo.com
Fri Oct 19 15:29:52 EDT 2007
User: rsigal
Date: 07/10/19 15:29:52
Modified: src/main/org/jboss/remoting/transport Tag: remoting_2_x
Connector.java
Log:
JBREM-63: Can now be configured by an org.jboss.remoting.ServerConfiguration.
Revision Changes Path
No revision
No revision
1.27.2.5 +187 -36 JBossRemoting/src/main/org/jboss/remoting/transport/Connector.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Connector.java
===================================================================
RCS file: /cvsroot/jboss/JBossRemoting/src/main/org/jboss/remoting/transport/Connector.java,v
retrieving revision 1.27.2.4
retrieving revision 1.27.2.5
diff -u -b -r1.27.2.4 -r1.27.2.5
--- Connector.java 23 May 2007 04:58:03 -0000 1.27.2.4
+++ Connector.java 19 Oct 2007 19:29:52 -0000 1.27.2.5
@@ -26,6 +26,7 @@
import org.jboss.remoting.ConnectionListener;
import org.jboss.remoting.InvokerLocator;
import org.jboss.remoting.InvokerRegistry;
+import org.jboss.remoting.ServerConfiguration;
import org.jboss.remoting.ServerInvocationHandler;
import org.jboss.remoting.ServerInvoker;
import org.jboss.remoting.marshal.MarshalFactory;
@@ -111,7 +112,7 @@
* @author <a href="mailto:d_jencks at users.sourceforge.net">David Jencks</a>
* @author <a href="mailto:juha at jboss.org">Juha Lindfors</a>
* @author <a href="mailto:tom at jboss.org">Tom Elrod</a>
- * @version $Revision: 1.27.2.4 $
+ * @version $Revision: 1.27.2.5 $
* @jmx.mbean description = "An MBean wrapper around a ServerInvoker."
* @jboss.xmbean
*/
@@ -122,6 +123,7 @@
private String locatorURI;
private Element xml;
+ private ServerConfiguration serverConfiguration;
private Map configuration = new HashMap();
@@ -304,6 +306,14 @@
// want to have handlers registered before starting, so if someone makes invocation,
// there is something to handle it.
configureHandlers();
+ if (serverConfiguration != null)
+ {
+ configureHandlersFromServerConfiguration();
+ }
+ else if (xml != null)
+ {
+ configureHandlersFromXML();
+ }
// if marshaller loader not started, start it
if (!isMarshallerLoader)
@@ -374,10 +384,15 @@
if (locatorURI == null)
{
- // nothing set for the InvokerLocator attribute, check to see if is part of Configuration attribute
- if (xml != null)
+ // InvokerLocator attribute not set; check to see if serverConfiguration is set.
+ if (serverConfiguration != null)
+ {
+ getInvokerConfigFromServerConfiguration(invokerConfig);
+ }
+ // Check to see if Configuration attribute is set.
+ else if (xml != null)
{
- getInvokerConfig(invokerConfig);
+ getInvokerConfigFromXML(invokerConfig);
}
configuration.putAll(invokerConfig);
@@ -468,7 +483,7 @@
return marshallerLoader;
}
- private void getInvokerConfig(Map invokerConfig)
+ private void getInvokerConfigFromXML(Map invokerConfig)
{
try
{
@@ -568,10 +583,137 @@
}
}
+ private void getInvokerConfigFromServerConfiguration(Map invokerConfig)
+ {
+ try
+ {
+ String transport = serverConfiguration.getTransport();
+
+ if (transport == null)
+ {
+ log.error("ServerConfiguration must contain a non-null transport attribute.");
+ return;
+ }
+
+ Map locatorParameters = new HashMap(serverConfiguration.getInvokerLocatorParameters());
+ String clientConnectAddress = (String) locatorParameters.remove("clientConnectAddress");
+ String clientConnectPort = (String) locatorParameters.remove("clientConnectPort");
+ String serverBindAddress = (String) locatorParameters.remove("serverBindAddress");
+ String serverBindPort = (String) locatorParameters.remove("serverBindPort");
+ String path = (String) locatorParameters.remove("path");
+
+ String host = clientConnectAddress != null
+ ? clientConnectAddress
+ : serverBindAddress != null
+ ? serverBindAddress
+ : InetAddress.getLocalHost().getHostAddress();
+
+ int port = clientConnectPort != null
+ ? Integer.parseInt(clientConnectPort)
+ : serverBindPort != null
+ ? Integer.parseInt(serverBindPort)
+ : PortUtil.findFreePort(serverBindAddress != null
+ ? serverBindAddress
+ : InetAddress.getLocalHost().getHostAddress());
+
+ String tempURI = transport + "://" + host + ":" + port + ((path != null) ? ("/" + path) : "");
+
+ // any params to add to the uri?
+ if (locatorParameters.size() > 0)
+ {
+ tempURI += "/?";
+ Iterator keyItr = locatorParameters.keySet().iterator();
+ if (keyItr.hasNext())
+ {
+ Object name = keyItr.next();
+ Object value = locatorParameters.get(name);
+ tempURI += name + "=" + value;
+ }
+ while (keyItr.hasNext())
+ {
+ tempURI += "&";
+ Object name = keyItr.next();
+ Object value = locatorParameters.get(name);
+ tempURI += name + "=" + value;
+ }
+ }
+
+ locatorURI = tempURI;
+
+ invokerConfig.putAll(serverConfiguration.getServerParameters());
+ invokerConfig.putAll((serverConfiguration.getInvokerLocatorParameters()));
+ }
+ catch (Exception e)
+ {
+ log.error("Error configuring invoker for connector.", e);
+ throw new IllegalStateException("Error configuring invoker from configuration POJO. Can not continue without invoker.");
+ }
+ }
+
private void configureHandlers()
throws Exception
{
- if (xml != null)
+ }
+
+ private void configureHandlersFromServerConfiguration() throws Exception
+ {
+ Map handlerMap = serverConfiguration.getInvocationHandlers();
+ if (handlerMap.size() == 0 &&
+ (getInvocationHandlers() == null || getInvocationHandlers().length == 0))
+ {
+ throw new IllegalArgumentException("invocationHandlers list empty and are no registered handlers found.");
+ }
+
+
+ Iterator it = handlerMap.keySet().iterator();
+ while (it.hasNext())
+ {
+ String subsystems = (String) it.next();
+ Object value = handlerMap.get(subsystems);
+ ServerInvocationHandler handler = null;
+
+ if (value instanceof ServerInvocationHandler)
+ {
+ handler = (ServerInvocationHandler) value;
+ }
+ else if (value instanceof String)
+ {
+ //first check to see if this is an ObjectName
+ String valueString = (String) value;
+ boolean isObjName = false;
+ try
+ {
+ ObjectName objName = new ObjectName(valueString);
+ handler = createHandlerProxy(objName);
+ isObjName = true;
+ }
+ catch (MalformedObjectNameException e)
+ {
+ log.debug("Handler supplied is not an object name.");
+ }
+
+ if (!isObjName)
+ {
+ Class serverInvocationHandlerClass = ClassLoaderUtility.loadClass(valueString, Connector.class);
+ handler = (ServerInvocationHandler) serverInvocationHandlerClass.newInstance();
+ }
+ }
+ else
+ {
+ throw new IllegalArgumentException("handler has invalid type: " + value);
+ }
+
+ StringTokenizer tok = new StringTokenizer(subsystems, ",");
+
+ while (tok.hasMoreTokens())
+ {
+ String subsystem = tok.nextToken();
+ addInvocationHandler(subsystem, handler);
+ }
+ }
+ }
+
+ private void configureHandlersFromXML() throws Exception
{
NodeList handlersNodes = xml.getElementsByTagName("handler");
@@ -626,7 +768,6 @@
}
}
}
- }
private ServerInvocationHandler createHandlerProxy(ObjectName objName)
{
@@ -1057,4 +1198,14 @@
return socketFactory;
}
}
+
+ public ServerConfiguration getServerConfiguration()
+ {
+ return serverConfiguration;
+ }
+
+ public void setServerConfiguration(ServerConfiguration serverConfig)
+ {
+ this.serverConfiguration = serverConfig;
+ }
}
More information about the jboss-cvs-commits
mailing list