servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r993398 - in /servicemix/smx4/nmr/trunk: assembly/src/main/filtered-resources/etc/ nmr/osgi/src/main/java/org/apache/servicemix/nmr/osgi/ nmr/osgi/src/main/resources/OSGI-INF/blueprint/
Date Tue, 07 Sep 2010 15:35:56 GMT
Author: gnodet
Date: Tue Sep  7 15:35:56 2010
New Revision: 993398

URL: http://svn.apache.org/viewvc?rev=993398&view=rev
Log:
SMX4NMR-222: Ability to configure thread pools for NMR endpoints

Added:
    servicemix/smx4/nmr/trunk/assembly/src/main/filtered-resources/etc/org.apache.servicemix.nmr.cfg
    servicemix/smx4/nmr/trunk/nmr/osgi/src/main/java/org/apache/servicemix/nmr/osgi/ExecutorConfigurator.java
Modified:
    servicemix/smx4/nmr/trunk/nmr/osgi/src/main/resources/OSGI-INF/blueprint/servicemix-nmr.xml

Added: servicemix/smx4/nmr/trunk/assembly/src/main/filtered-resources/etc/org.apache.servicemix.nmr.cfg
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/assembly/src/main/filtered-resources/etc/org.apache.servicemix.nmr.cfg?rev=993398&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/assembly/src/main/filtered-resources/etc/org.apache.servicemix.nmr.cfg
(added)
+++ servicemix/smx4/nmr/trunk/assembly/src/main/filtered-resources/etc/org.apache.servicemix.nmr.cfg
Tue Sep  7 15:35:56 2010
@@ -0,0 +1,37 @@
+################################################################################
+#
+#    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.
+#
+################################################################################
+
+# The values below can be used to configure the thread pool size for NMR endpoints.
+# - corePoolSize defines the core thread pool size (default is 4)
+# - maximumPoolSize defines the maximum thread pool size, -1 means an unbounded thread pool
size (default is -1)
+# - queueSize defines the executor queue size (default is 1024)
+# - allowCoreThreadTimeout allows the core threads to timeout (defaults to true)
+# - keepAliveTime is the amount of milliseconds a thread is kept alive when idle (defaults
to 60000)
+#
+# Endpoints are provided a ThreadPool with specific configuration.  If no configuration
+# can be found for the endpoint name, the default one can be used.
+# A given thread pool can be configured by prefixing the above properties with the name followed
by a dot.
+# For example:
+#   foo.bar.corePoolSize=16
+#
+corePoolSize=4
+maximumPoolSize=-1
+queueSize=1024
+allowCoreThreadTimeout=true
+keepAliveTime=60000

Added: servicemix/smx4/nmr/trunk/nmr/osgi/src/main/java/org/apache/servicemix/nmr/osgi/ExecutorConfigurator.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/osgi/src/main/java/org/apache/servicemix/nmr/osgi/ExecutorConfigurator.java?rev=993398&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/nmr/osgi/src/main/java/org/apache/servicemix/nmr/osgi/ExecutorConfigurator.java
(added)
+++ servicemix/smx4/nmr/trunk/nmr/osgi/src/main/java/org/apache/servicemix/nmr/osgi/ExecutorConfigurator.java
Tue Sep  7 15:35:56 2010
@@ -0,0 +1,112 @@
+/*
+ * 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.servicemix.nmr.osgi;
+
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.servicemix.executors.impl.ExecutorConfig;
+import org.apache.servicemix.executors.impl.ExecutorFactoryImpl;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.cm.ManagedService;
+
+/**
+ * A managed service that will update the configurations based on the ConfigAdmin configuration
+ */
+public class ExecutorConfigurator implements ManagedService {
+
+    private ExecutorFactoryImpl factory;
+
+    public ExecutorFactoryImpl getFactory() {
+        return factory;
+    }
+
+    public void setFactory(ExecutorFactoryImpl factory) {
+        this.factory = factory;
+    }
+
+    public void updated(Dictionary properties) throws ConfigurationException {
+        ExecutorConfig defaultConfig = new ExecutorConfig();
+        Map<String, ExecutorConfig> configs = new HashMap<String, ExecutorConfig>();
+        for (Enumeration e = properties.keys(); e.hasMoreElements();) {
+            String key = (String) e.nextElement();
+            if (key.endsWith(".corePoolSize")) {
+                getConfig(configs, key).setCorePoolSize(getInt(properties, key));
+            } else if (key.endsWith(".maximumPoolSize")) {
+                getConfig(configs, key).setMaximumPoolSize(getInt(properties, key));
+            } else if (key.endsWith(".keepAliveTime")) {
+                getConfig(configs, key).setKeepAliveTime(getLong(properties, key));
+            } else if (key.endsWith(".threadDaemon")) {
+                getConfig(configs, key).setThreadDaemon(getBool(properties, key));
+            } else if (key.endsWith(".threadPriority")) {
+                getConfig(configs, key).setThreadPriority(getInt(properties, key));
+            } else if (key.endsWith(".queueSize")) {
+                getConfig(configs, key).setQueueSize(getInt(properties, key));
+            } else if (key.endsWith(".shutdownDelay")) {
+                getConfig(configs, key).setShutdownDelay(getLong(properties, key));
+            } else if (key.endsWith(".allowCoreThreadsTimeout")) {
+                getConfig(configs, key).setAllowCoreThreadsTimeout(getBool(properties, key));
+            } else if (key.endsWith(".bypassIfSynchronous")) {
+                getConfig(configs, key).setBypassIfSynchronous(getBool(properties, key));
+            } else if (key.equals("corePoolSize")) {
+                defaultConfig.setCorePoolSize(getInt(properties, key));
+            } else if (key.equals("maximumPoolSize")) {
+                defaultConfig.setMaximumPoolSize(getInt(properties, key));
+            } else if (key.equals("keepAliveTime")) {
+                defaultConfig.setKeepAliveTime(getLong(properties, key));
+            } else if (key.equals("threadDaemon")) {
+                defaultConfig.setThreadDaemon(getBool(properties, key));
+            } else if (key.equals("threadPriority")) {
+                defaultConfig.setThreadPriority(getInt(properties, key));
+            } else if (key.equals("queueSize")) {
+                defaultConfig.setQueueSize(getInt(properties, key));
+            } else if (key.equals("shutdownDelay")) {
+                defaultConfig.setShutdownDelay(getLong(properties, key));
+            } else if (key.equals("allowCoreThreadsTimeout")) {
+                defaultConfig.setAllowCoreThreadsTimeout(getBool(properties, key));
+            } else if (key.equals("bypassIfSynchronous")) {
+                defaultConfig.setBypassIfSynchronous(getBool(properties, key));
+            }
+        }
+        factory.setDefaultConfig(defaultConfig);
+        factory.setConfigs(configs);
+    }
+
+    private ExecutorConfig getConfig(Map<String, ExecutorConfig> configs, String key)
{
+        String name = key.substring(0, key.lastIndexOf('.'));
+        ExecutorConfig config = configs.get(name);
+        if (config == null) {
+            config = new ExecutorConfig();
+            configs.put(name, config);
+        }
+        return config;
+    }
+
+    private int getInt(Dictionary properties, String key) {
+        return Integer.parseInt(properties.get(key).toString());
+    }
+
+    private long getLong(Dictionary properties, String key) {
+        return Long.parseLong(properties.get(key).toString());
+    }
+
+    private boolean getBool(Dictionary properties, String key) {
+        return Boolean.parseBoolean(properties.get(key).toString());
+    }
+}

Modified: servicemix/smx4/nmr/trunk/nmr/osgi/src/main/resources/OSGI-INF/blueprint/servicemix-nmr.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/osgi/src/main/resources/OSGI-INF/blueprint/servicemix-nmr.xml?rev=993398&r1=993397&r2=993398&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/nmr/osgi/src/main/resources/OSGI-INF/blueprint/servicemix-nmr.xml
(original)
+++ servicemix/smx4/nmr/trunk/nmr/osgi/src/main/resources/OSGI-INF/blueprint/servicemix-nmr.xml
Tue Sep  7 15:35:56 2010
@@ -120,22 +120,32 @@
         <property name="defaultConfig">
             <bean class="org.apache.servicemix.executors.impl.ExecutorConfig">
                 <property name="allowCoreThreadsTimeout" value="${allowCoreThreadsTimeout}"
/>
-                <property name="corePoolSize" value="${threadPoolCorePoolSize}"/>
-                <property name="maximumPoolSize" value="${threadPoolMaximumPoolSize}"/>
-                <property name="queueSize" value="${threadPoolQueueSize}"/>
+                <property name="corePoolSize" value="${corePoolSize}"/>
+                <property name="maximumPoolSize" value="${maximumPoolSize}"/>
+                <property name="queueSize" value="${queueSize}"/>
                 <property name="bypassIfSynchronous" value="${bypassIfSynchronous}" />
             </bean>
         </property>
     </bean>
 
+    <bean id="executorConfigurator" class="org.apache.servicemix.nmr.osgi.ExecutorConfigurator">
+        <property name="executorFactory" ref="executorFactory"/>
+    </bean>
+
+    <service ref="executorConfigurator" interface="org.osgi.service.cm.ManagedService">
+        <service-properties>
+            <entry key="service.pid" value="org.apache.servicemix.nmr"/>
+        </service-properties>
+    </service>
+
     <!-- Property place holder -->
     <cm:property-placeholder persistent-id="org.apache.servicemix.nmr">
         <cm:default-properties>
             <cm:property name="nmrId" value="org.apache.servicemix.NMR"/>
             <cm:property name="allowCoreThreadsTimeout" value="true"/>
-            <cm:property name="threadPoolCorePoolSize" value="4"/>
-            <cm:property name="threadPoolMaximumPoolSize" value="-1"/>
-            <cm:property name="threadPoolQueueSize" value="1024"/>
+            <cm:property name="corePoolSize" value="4"/>
+            <cm:property name="maximumPoolSize" value="-1"/>
+            <cm:property name="queueSize" value="1024"/>
             <cm:property name="bypassIfSynchronous" value="true"/>
         </cm:default-properties>
     </cm:property-placeholder>



Mime
View raw message