Author: ron.sigal(a)jboss.com
Date: 2011-04-25 14:34:07 -0400 (Mon, 25 Apr 2011)
New Revision: 6335
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/coyote/CoyoteInvoker.java
Log:
JBREM-1283: Added special handling for setting the tomcat executor.
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/coyote/CoyoteInvoker.java
===================================================================
---
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/coyote/CoyoteInvoker.java 2011-04-25
15:34:52 UTC (rev 6334)
+++
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/coyote/CoyoteInvoker.java 2011-04-25
18:34:07 UTC (rev 6335)
@@ -17,6 +17,9 @@
package org.jboss.remoting.transport.coyote;
+import org.apache.catalina.Executor;
+import org.apache.catalina.LifecycleException;
+import org.apache.catalina.core.StandardThreadExecutor;
import org.apache.coyote.ActionCode;
import org.apache.coyote.Adapter;
import org.apache.coyote.ProtocolHandler;
@@ -187,18 +190,19 @@
}
protocolHandler.setAdapter(this);
- // Pass all attributes to the protocol handler
- Iterator keys = config.keySet().iterator();
- while(keys.hasNext())
+ // Pass all attributes to the protocol handler
+ Iterator keys = config.keySet().iterator();
+ while(keys.hasNext())
+ {
+ String key = (String) keys.next();
+ Object obj = config.get(key);
+ if ("executor".equals(key) && obj instanceof String)
{
- String key = (String) keys.next();
- Object obj = config.get(key);
- if (obj instanceof String)
- {
- String val = (String) obj;
- setProperty(protocolHandler, key, val);
- }
+ createAndSetExecutor(protocolHandler, (String) obj);
+ continue;
}
+ setProperty(protocolHandler, key, obj);
+ }
// need to convert standard remoting timeout config to tomcat timeout
String timeoutValue = (String)config.get(TIMEOUT);
@@ -1051,7 +1055,7 @@
* int or boolean we'll convert value to the right type before) - that means
* you can have setDebug(1).
*/
- public static boolean setProperty(final Object o, String name, final String value)
+ public static boolean setProperty(final Object o, String name, final Object value)
{
String setter = "set" + capitalize(name);
@@ -1075,108 +1079,144 @@
}
Method setPropertyMethod = null;
+ Method setAttributeMethod = null;
+ Method setExecutorMethod = null;
- // First, the ideal case - a setFoo( String ) method
- for(int i = 0; i < methods.length; i++)
+ // Try a setFoo( String) or setFoo ( int ) or ( boolean )
+ if (value instanceof String)
{
- Class paramT[] = methods[i].getParameterTypes();
- if(setter.equals(methods[i].getName()) && paramT.length == 1
- && "java.lang.String".equals(paramT[0].getName()))
+ String stringValue = (String) value;
+ for(int i = 0; i < methods.length; i++)
{
+ boolean ok = true;
+ if(setter.equals(methods[i].getName())
+ && methods[i].getParameterTypes().length == 1)
+ {
- methods[i].invoke(o, new Object[]{value});
- return true;
- }
- }
+ // match - find the type and invoke it
+ Class paramType = methods[i].getParameterTypes()[0];
+ Object params[] = new Object[1];
- // Try a setFoo ( int ) or ( boolean )
- for(int i = 0; i < methods.length; i++)
- {
- boolean ok = true;
- if(setter.equals(methods[i].getName())
- && methods[i].getParameterTypes().length == 1)
- {
-
- // match - find the type and invoke it
- Class paramType = methods[i].getParameterTypes()[0];
- Object params[] = new Object[1];
-
- // Try a setFoo ( int )
- if("java.lang.Integer".equals(paramType.getName())
- || "int".equals(paramType.getName()))
- {
- try
+ // Try a setFoo ( String )
+ if("java.lang.String".equals(paramType.getName()))
{
- params[0] = new Integer(value);
+ params[0] = stringValue;
}
- catch(NumberFormatException ex)
+ // Try a setFoo ( int )
+ else if("java.lang.Integer".equals(paramType.getName())
+ || "int".equals(paramType.getName()))
{
- ok = false;
+ try
+ {
+ params[0] = new Integer(stringValue);
+ }
+ catch(NumberFormatException ex)
+ {
+ ok = false;
+ }
+ // Try a setFoo ( long )
}
- // Try a setFoo ( long )
- }
- else if("java.lang.Long".equals(paramType.getName())
- || "long".equals(paramType.getName()))
- {
- try
+ else if("java.lang.Long".equals(paramType.getName())
+ || "long".equals(paramType.getName()))
{
- params[0] = new Long(value);
+ try
+ {
+ params[0] = new Long(stringValue);
+ }
+ catch(NumberFormatException ex)
+ {
+ ok = false;
+ }
+
+ // Try a setFoo ( boolean )
}
- catch(NumberFormatException ex)
+ else if("java.lang.Boolean".equals(paramType.getName())
+ || "boolean".equals(paramType.getName()))
{
- ok = false;
+ params[0] = new Boolean(stringValue);
+
+ // Try a setFoo ( InetAddress )
}
+ else if("java.net.InetAddress".equals(paramType
+ .getName()))
+ {
+ try
+ {
+ params[0] = InetAddress.getByName(stringValue);
+ }
+ catch(UnknownHostException exc)
+ {
+ ok = false;
+ }
- // Try a setFoo ( boolean )
- }
- else if("java.lang.Boolean".equals(paramType.getName())
- || "boolean".equals(paramType.getName()))
- {
- params[0] = new Boolean(value);
+ // Unknown type
+ }
- // Try a setFoo ( InetAddress )
- }
- else if("java.net.InetAddress".equals(paramType.getName()))
- {
- try
+ if(ok)
{
- params[0] = getAddressByName(value);
+ methods[i].invoke(o, params);
+ return true;
}
- catch(UnknownHostException exc)
- {
- ok = false;
- }
-
- // Unknown type
}
-
- if(ok)
+ // save "setProperty" for later
+ if ("setAttribute".equals(methods[i].getName()))
{
- methods[i].invoke(o, params);
- return true;
+ setAttributeMethod = methods[i];
}
+ else if("setProperty".equals(methods[i].getName()))
+ {
+ setPropertyMethod = methods[i];
+ }
}
-
- // save "setProperty" for later
- if("setProperty".equals(methods[i].getName()))
+ }
+ else
+ {
+ for(int i = 0; i < methods.length; i++)
{
- setPropertyMethod = methods[i];
+ // save "setProperty" for later
+ if ("setAttribute".equals(methods[i].getName()))
+ {
+ setAttributeMethod = methods[i];
+ }
+ else if("setProperty".equals(methods[i].getName()))
+ {
+ setPropertyMethod = methods[i];
+ }
+ else if ("setExecutor".equals(methods[i].getName()))
+ {
+ setExecutorMethod = methods[i];
+ }
}
}
- // Ok, no setXXX found, try a setProperty("name", "value")
- if(setPropertyMethod != null)
+ // Ok, no setXXX found, try a setProperty("name", "value")
or setAttribute("name", "value")
+ if(setExecutorMethod != null && value instanceof Executor)
{
+ Object params[] = new Object[1];
+ params[0] = value;
+ setExecutorMethod.invoke(o, params);
+ return true;
+ }
+ else if(setAttributeMethod != null)
+ {
Object params[] = new Object[2];
params[0] = name;
params[1] = value;
+ setAttributeMethod.invoke(o, params);
+ return true;
+ }
+ else if(setPropertyMethod != null)
+ {
+ Object params[] = new Object[2];
+ params[0] = name;
+ params[1] = value;
setPropertyMethod.invoke(o, params);
return true;
}
-
}
catch(Exception e)
{
+ log.debug("unable to set property " + name + " to " + value
+ ": " + e.getMessage());
return false;
}
return false;
@@ -1211,6 +1251,34 @@
return contentType.indexOf('\n') + contentType.indexOf('\r') >
-2;
}
+ static private void createAndSetExecutor(ProtocolHandler protocolHandler, String
executorConfig)
+ {
+ Executor executor = new StandardThreadExecutor();
+ log.debug("setting executor to " + executor + " with
properties:");
+ if (executorConfig != null)
+ {
+ String[] ss = executorConfig.split(",");
+ for (int i = 0; i < ss.length; i++)
+ {
+ int pos = ss[i].indexOf('=');
+ setProperty(executor, ss[i].substring(0, pos).trim(), ss[i].substring(pos +
1).trim());
+ log.debug(ss[i].substring(0, pos).trim() + ": " +
ss[i].substring(pos + 1).trim());
+ }
+ }
+
+ try
+ {
+ executor.start();
+ }
+ catch (LifecycleException e)
+ {
+ log.warn("unable to start executor " + executor, e);
+ return;
+ }
+
+ setProperty(protocolHandler, "executor", executor);
+ }
+
static private Object forName(final String className) throws ClassNotFoundException
{
if (SecurityUtility.skipAccessControl())
Show replies by date