You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by ru...@apache.org on 2009/10/11 18:06:40 UTC
svn commit: r824095 - in
/webservices/commons/branches/modules/transport/1.0.0/modules/base/src/main/java/org/apache/axis2/transport/base:
AbstractTransportListener.java BaseUtils.java TransportConfiguration.java
Author: ruwan
Date: Sun Oct 11 16:06:39 2009
New Revision: 824095
URL: http://svn.apache.org/viewvc?rev=824095&view=rev
Log:
Making the threadpool created by the AbstractTransportListener configurable (WSCOMMONS-469)
Added:
webservices/commons/branches/modules/transport/1.0.0/modules/base/src/main/java/org/apache/axis2/transport/base/TransportConfiguration.java
Modified:
webservices/commons/branches/modules/transport/1.0.0/modules/base/src/main/java/org/apache/axis2/transport/base/AbstractTransportListener.java
webservices/commons/branches/modules/transport/1.0.0/modules/base/src/main/java/org/apache/axis2/transport/base/BaseUtils.java
Modified: webservices/commons/branches/modules/transport/1.0.0/modules/base/src/main/java/org/apache/axis2/transport/base/AbstractTransportListener.java
URL: http://svn.apache.org/viewvc/webservices/commons/branches/modules/transport/1.0.0/modules/base/src/main/java/org/apache/axis2/transport/base/AbstractTransportListener.java?rev=824095&r1=824094&r2=824095&view=diff
==============================================================================
--- webservices/commons/branches/modules/transport/1.0.0/modules/base/src/main/java/org/apache/axis2/transport/base/AbstractTransportListener.java (original)
+++ webservices/commons/branches/modules/transport/1.0.0/modules/base/src/main/java/org/apache/axis2/transport/base/AbstractTransportListener.java Sun Oct 11 16:06:39 2009
@@ -70,6 +70,8 @@
private TransportMBeanSupport mbeanSupport;
/** Metrics collector for this transport */
protected MetricsCollector metrics = new MetricsCollector();
+ /** Transport Configuration for the respective transports */
+ protected TransportConfiguration config;
/**
* A constructor that makes subclasses pick up the correct logger
@@ -92,13 +94,19 @@
this.cfgCtx = cfgCtx;
this.transportIn = transportIn;
this.transportOut = cfgCtx.getAxisConfiguration().getTransportOut(getTransportName());
+ this.config = TransportConfiguration.getConfiguration(getTransportName());
if (useAxis2ThreadPool) {
//this.workerPool = cfgCtx.getThreadPool(); not yet implemented
throw new AxisFault("Unsupported thread pool for task execution - Axis2 thread pool");
} else {
this.workerPool = WorkerPoolFactory.getWorkerPool(
- 10, 20, 5, -1, getTransportName() + "Server Worker thread group", getTransportName() + "-Worker");
+ config.getServerCoreThreads(),
+ config.getServerMaxThreads(),
+ config.getServerKeepalive(),
+ config.getServerQueueLen(),
+ getTransportName() + "Server Worker thread group",
+ getTransportName() + "-Worker");
}
// register to receive updates on services for lifetime management
Modified: webservices/commons/branches/modules/transport/1.0.0/modules/base/src/main/java/org/apache/axis2/transport/base/BaseUtils.java
URL: http://svn.apache.org/viewvc/webservices/commons/branches/modules/transport/1.0.0/modules/base/src/main/java/org/apache/axis2/transport/base/BaseUtils.java?rev=824095&r1=824094&r2=824095&view=diff
==============================================================================
--- webservices/commons/branches/modules/transport/1.0.0/modules/base/src/main/java/org/apache/axis2/transport/base/BaseUtils.java (original)
+++ webservices/commons/branches/modules/transport/1.0.0/modules/base/src/main/java/org/apache/axis2/transport/base/BaseUtils.java Sun Oct 11 16:06:39 2009
@@ -19,16 +19,6 @@
package org.apache.axis2.transport.base;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.StringTokenizer;
-
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMOutputFormat;
import org.apache.axiom.om.impl.builder.StAXBuilder;
@@ -39,16 +29,24 @@
import org.apache.axis2.Constants;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.description.AxisService;
-import org.apache.axis2.description.Parameter;
import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.axis2.format.BinaryFormatter;
+import org.apache.axis2.format.PlainTextFormatter;
import org.apache.axis2.transport.MessageFormatter;
import org.apache.axis2.transport.TransportUtils;
-import org.apache.axis2.util.JavaUtils;
-import org.apache.axis2.context.OperationContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.axis2.format.BinaryFormatter;
-import org.apache.axis2.format.PlainTextFormatter;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Properties;
+import java.util.StringTokenizer;
public class BaseUtils {
@@ -229,4 +227,50 @@
}
return h;
}
+
+ /**
+ * Loads the properties from a given property file path
+ *
+ * @param filePath Path of the property file
+ * @return Properties loaded from given file
+ */
+ public static Properties loadProperties(String filePath) {
+
+ Properties properties = new Properties();
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+
+ if (log.isDebugEnabled()) {
+ log.debug("Loading a file '" + filePath + "' from classpath");
+ }
+
+ InputStream in = cl.getResourceAsStream(filePath);
+ if (in == null) {
+ if (log.isDebugEnabled()) {
+ log.debug("Unable to load file '" + filePath + "'");
+ }
+
+ filePath = "conf" +
+ File.separatorChar + filePath;
+ if (log.isDebugEnabled()) {
+ log.debug("Loading a file '" + filePath + "' from classpath");
+ }
+
+ in = cl.getResourceAsStream(filePath);
+ if (in == null) {
+ if (log.isDebugEnabled()) {
+ log.debug("Unable to load file ' " + filePath + " '");
+ }
+ }
+ }
+ if (in != null) {
+ try {
+ properties.load(in);
+ } catch (IOException e) {
+ String msg = "Error loading properties from a file at :" + filePath;
+ log.error(msg, e);
+ throw new BaseTransportException(msg, e);
+ }
+ }
+ return properties;
+ }
}
Added: webservices/commons/branches/modules/transport/1.0.0/modules/base/src/main/java/org/apache/axis2/transport/base/TransportConfiguration.java
URL: http://svn.apache.org/viewvc/webservices/commons/branches/modules/transport/1.0.0/modules/base/src/main/java/org/apache/axis2/transport/base/TransportConfiguration.java?rev=824095&view=auto
==============================================================================
--- webservices/commons/branches/modules/transport/1.0.0/modules/base/src/main/java/org/apache/axis2/transport/base/TransportConfiguration.java (added)
+++ webservices/commons/branches/modules/transport/1.0.0/modules/base/src/main/java/org/apache/axis2/transport/base/TransportConfiguration.java Sun Oct 11 16:06:39 2009
@@ -0,0 +1,146 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.axis2.transport.base;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.Properties;
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ *
+ */
+public class TransportConfiguration {
+
+ // defaults
+ private static final int WORKERS_CORE_THREADS = 20;
+ private static final int WORKERS_MAX_THREADS = 100;
+ private static final int WORKER_KEEP_ALIVE = 5;
+ private static final int BLOCKING_QUEUE_LENGTH = -1;
+
+ // server listener
+ private static final String S_T_CORE = "snd_t_core";
+ private static final String S_T_MAX = "snd_t_max";
+ private static final String S_T_ALIVE = "snd_alive_sec";
+ private static final String S_T_QLEN = "snd_qlen";
+
+ // client sender
+ private static final String C_T_CORE = "lst_t_core";
+ private static final String C_T_MAX = "lst_t_max";
+ private static final String C_T_ALIVE = "lst_alive_sec";
+ private static final String C_T_QLEN = "lst_qlen";
+
+ private static final Log log = LogFactory.getLog(TransportConfiguration.class);
+ private static Map<String, TransportConfiguration> _configurations
+ = new HashMap<String, TransportConfiguration>();
+ private Properties props;
+
+ private TransportConfiguration(String transportName) {
+ try {
+ props = BaseUtils.loadProperties(transportName + ".properties");
+ } catch (Exception ignore) {}
+ }
+
+ public static TransportConfiguration getConfiguration(String transportName) {
+ if (_configurations.containsKey(transportName)) {
+ return _configurations.get(transportName);
+ } else {
+ TransportConfiguration config = new TransportConfiguration(transportName);
+ _configurations.put(transportName, config);
+ return config;
+ }
+ }
+
+ public int getServerCoreThreads() {
+ return getProperty(S_T_CORE, WORKERS_CORE_THREADS);
+ }
+
+ public int getServerMaxThreads() {
+ return getProperty(S_T_MAX, WORKERS_MAX_THREADS);
+ }
+
+ public int getServerKeepalive() {
+ return getProperty(S_T_ALIVE, WORKER_KEEP_ALIVE);
+ }
+
+ public int getServerQueueLen() {
+ return getProperty(S_T_QLEN, BLOCKING_QUEUE_LENGTH);
+ }
+
+ public int getClientCoreThreads() {
+ return getProperty(C_T_CORE, WORKERS_CORE_THREADS);
+ }
+
+ public int getClientMaxThreads() {
+ return getProperty(C_T_MAX, WORKERS_MAX_THREADS);
+ }
+
+ public int getClientKeepalive() {
+ return getProperty(C_T_ALIVE, WORKER_KEEP_ALIVE);
+ }
+
+ public int getClientQueueLen() {
+ return getProperty(C_T_QLEN, BLOCKING_QUEUE_LENGTH);
+ }
+
+ /**
+ * Get properties that tune nhttp transport. Preference to system properties
+ * @param name name of the system/config property
+ * @param def default value to return if the property is not set
+ * @return the value of the property to be used
+ */
+ public int getProperty(String name, int def) {
+ String val = System.getProperty(name);
+ if (val == null) {
+ val = props.getProperty(name);
+ }
+
+ if (val != null && Integer.valueOf(val) > 0) {
+ if (log.isDebugEnabled()) {
+ log.debug("Using transport tuning parameter : " + name + " = " + val);
+ }
+ return Integer.valueOf(val);
+ }
+ return def;
+ }
+
+ /**
+ * Get properties that tune nhttp transport. Preference to system properties
+ * @param name name of the system/config property
+ * @param def default value to return if the property is not set
+ * @return the value of the property to be used
+ */
+ public boolean getBooleanValue(String name, boolean def) {
+ String val = System.getProperty(name);
+ if (val == null) {
+ val = props.getProperty(name);
+ }
+
+ if (val != null && Boolean.parseBoolean(val)) {
+ if (log.isDebugEnabled()) {
+ log.debug("Using transport tuning parameter : " + name);
+ }
+ return true;
+ }
+ return def;
+ }
+}