activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r417653 - in /incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool: properties/ spi/
Date Wed, 28 Jun 2006 03:11:11 GMT
Author: aco
Date: Tue Jun 27 20:11:11 2006
New Revision: 417653

URL: http://svn.apache.org/viewvc?rev=417653&view=rev
Log:
Added ability to load extension dirs to the spi classes.

Added:
    incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/spi/ActiveMQReflectionSPI.java
      - copied, changed from r417127, incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/spi/ActiveMQClassLoaderSPI.java
    incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/spi/ReflectionSPIConnectionFactory.java
Removed:
    incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/spi/ActiveMQClassLoaderSPI.java
Modified:
    incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/properties/JmsClientSystemProperties.java
    incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/spi/ClassLoaderSPIConnectionFactory.java

Modified: incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/properties/JmsClientSystemProperties.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/properties/JmsClientSystemProperties.java?rev=417653&r1=417652&r2=417653&view=diff
==============================================================================
--- incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/properties/JmsClientSystemProperties.java
(original)
+++ incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/properties/JmsClientSystemProperties.java
Tue Jun 27 20:11:11 2006
@@ -33,7 +33,7 @@
 
     protected String samplers = SAMPLER_TP + "," + SAMPLER_CPU; // Start both samplers
 
-    protected String spiClass = "org.apache.activemq.tool.spi.ActiveMQClassLoaderSPI";
+    protected String spiClass = "org.apache.activemq.tool.spi.ActiveMQReflectionSPI";
     protected String clientPrefix = "JmsClient";
     protected int numClients = 1;
     protected int totalDests = 1;

Copied: incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/spi/ActiveMQReflectionSPI.java
(from r417127, incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/spi/ActiveMQClassLoaderSPI.java)
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/spi/ActiveMQReflectionSPI.java?p2=incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/spi/ActiveMQReflectionSPI.java&p1=incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/spi/ActiveMQClassLoaderSPI.java&r1=417127&r2=417653&rev=417653&view=diff
==============================================================================
--- incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/spi/ActiveMQClassLoaderSPI.java
(original)
+++ incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/spi/ActiveMQReflectionSPI.java
Tue Jun 27 20:11:11 2006
@@ -16,7 +16,7 @@
  */
 package org.apache.activemq.tool.spi;
 
-public class ActiveMQClassLoaderSPI extends ClassLoaderSPIConnectionFactory {
+public class ActiveMQReflectionSPI extends ReflectionSPIConnectionFactory {
     public String getClassName() {
         return "org.apache.activemq.ActiveMQConnectionFactory";
     }

Modified: incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/spi/ClassLoaderSPIConnectionFactory.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/spi/ClassLoaderSPIConnectionFactory.java?rev=417653&r1=417652&r2=417653&view=diff
==============================================================================
--- incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/spi/ClassLoaderSPIConnectionFactory.java
(original)
+++ incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/spi/ClassLoaderSPIConnectionFactory.java
Tue Jun 27 20:11:11 2006
@@ -16,22 +16,65 @@
  */
 package org.apache.activemq.tool.spi;
 
-import org.apache.activemq.tool.properties.ReflectionUtil;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 import javax.jms.ConnectionFactory;
 import java.util.Properties;
+import java.util.StringTokenizer;
+import java.util.List;
+import java.util.ArrayList;
+import java.io.File;
+import java.net.URL;
+import java.net.URLClassLoader;
 
 public abstract class ClassLoaderSPIConnectionFactory implements SPIConnectionFactory {
-    public ConnectionFactory createConnectionFactory(Properties settings) throws Exception
{
-        Class factoryClass = Class.forName(getClassName());
-        ConnectionFactory factory = (ConnectionFactory)factoryClass.newInstance();
-        configureConnectionFactory(factory, settings);
-        return factory;
+    private static final Log log = LogFactory.getLog(ClassLoaderSPIConnectionFactory.class);
+
+    public static final String KEY_EXT_DIR = "extDir";
+
+    public final ConnectionFactory createConnectionFactory(Properties settings) throws Exception
{
+
+        // Load new context class loader
+        ClassLoader newClassLoader = getContextClassLoader(settings);
+        Thread.currentThread().setContextClassLoader(newClassLoader);
+
+        return instantiateConnectionFactory(newClassLoader, settings);
     }
 
-    public void configureConnectionFactory(ConnectionFactory jmsFactory, Properties settings)
throws Exception {
-        ReflectionUtil.configureClass(jmsFactory, settings);
+    protected ClassLoader getContextClassLoader(Properties settings) {
+        String extDir = (String)settings.remove(KEY_EXT_DIR);
+        if (extDir != null) {
+            StringTokenizer tokens = new StringTokenizer(extDir, ";,");
+            List urls = new ArrayList();
+            while (tokens.hasMoreTokens()) {
+                String dir = tokens.nextToken();
+                try {
+                    File f = new File(dir);
+                    dir = f.getAbsolutePath();
+                    System.out.println(dir);
+                    urls.add(f.toURL());
+
+                    File[] files = f.listFiles();
+                    if( files!=null ) {
+                        for (int j = 0; j < files.length; j++) {
+                            if( files[j].getName().endsWith(".zip") || files[j].getName().endsWith(".jar")
) {
+                                dir = files[j].getAbsolutePath();
+                                urls.add(files[j].toURL());
+                            }
+                        }
+                    }
+                } catch (Exception e) {
+                    log.warn("Failed to load ext dir: " + dir + ". Reason: " + e);
+                }
+            }
+
+            URL u[] = new URL[urls.size()];
+            urls.toArray(u);
+            return new URLClassLoader(u, ClassLoaderSPIConnectionFactory.class.getClassLoader());
+        }
+        return ClassLoaderSPIConnectionFactory.class.getClassLoader();
     }
 
-    public abstract String getClassName();
+    protected abstract ConnectionFactory instantiateConnectionFactory(ClassLoader cl, Properties
settings) throws Exception;
 }

Added: incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/spi/ReflectionSPIConnectionFactory.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/spi/ReflectionSPIConnectionFactory.java?rev=417653&view=auto
==============================================================================
--- incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/spi/ReflectionSPIConnectionFactory.java
(added)
+++ incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/spi/ReflectionSPIConnectionFactory.java
Tue Jun 27 20:11:11 2006
@@ -0,0 +1,38 @@
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ * Licensed 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.activemq.tool.spi;
+
+import org.apache.activemq.tool.properties.ReflectionUtil;
+
+import javax.jms.ConnectionFactory;
+import java.util.Properties;
+
+public abstract class ReflectionSPIConnectionFactory extends ClassLoaderSPIConnectionFactory
{
+
+    public ConnectionFactory instantiateConnectionFactory(ClassLoader cl, Properties settings)
throws Exception {
+        Class factoryClass = cl.loadClass(getClassName());
+        ConnectionFactory factory = (ConnectionFactory)factoryClass.newInstance();
+        configureConnectionFactory(factory, settings);
+        return factory;
+    }
+
+    public void configureConnectionFactory(ConnectionFactory jmsFactory, Properties settings)
throws Exception {
+        ReflectionUtil.configureClass(jmsFactory, settings);
+    }
+
+    public abstract String getClassName();
+}



Mime
View raw message