mirror of
https://github.com/apache/activemq.git
synced 2025-02-17 07:24:51 +00:00
Added ability to load extension dirs to the spi classes.
git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@417653 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ffcbd0c015
commit
6086520836
@ -33,7 +33,7 @@ public class JmsClientSystemProperties extends AbstractObjectProperties {
|
||||
|
||||
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;
|
||||
|
@ -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";
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user