This closes #134 Improving bootstrap
This commit is contained in:
commit
436df8afdd
|
@ -25,6 +25,7 @@ import java.net.URLClassLoader;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -35,19 +36,31 @@ import java.util.Comparator;
|
||||||
public class Artemis {
|
public class Artemis {
|
||||||
|
|
||||||
public static void main(String[] args) throws Throwable {
|
public static void main(String[] args) throws Throwable {
|
||||||
ArrayList<File> dirs = new ArrayList<File>();
|
|
||||||
|
|
||||||
String home = System.getProperty("artemis.home");
|
String home = System.getProperty("artemis.home");
|
||||||
if (home != null) {
|
|
||||||
dirs.add(new File(new File(home), "lib"));
|
File fileHome = home != null ? new File(home) : null;
|
||||||
}
|
|
||||||
|
|
||||||
String instance = System.getProperty("artemis.instance");
|
String instance = System.getProperty("artemis.instance");
|
||||||
File instanceFile = null;
|
File fileInstance = instance != null ? new File(instance) : null;
|
||||||
if (instance != null) {
|
execute(fileHome, fileInstance, args);
|
||||||
instanceFile = new File(instance);
|
}
|
||||||
dirs.add(new File(instanceFile, "lib"));
|
|
||||||
|
|
||||||
|
/** This is a good method for booting an embedded command */
|
||||||
|
public static void execute(File artemisHome, File artemisInstance, List<String> args) throws Throwable {
|
||||||
|
execute(artemisHome, artemisInstance, (String[]) args.toArray(new String[args.size()]));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** This is a good method for booting an embedded command */
|
||||||
|
public static void execute(File fileHome, File fileInstance, String ... args) throws Throwable {
|
||||||
|
ArrayList<File> dirs = new ArrayList<File>();
|
||||||
|
if (fileHome != null) {
|
||||||
|
dirs.add(new File(fileHome, "lib"));
|
||||||
}
|
}
|
||||||
|
if (fileInstance != null) {
|
||||||
|
dirs.add(new File(fileInstance, "lib"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ArrayList<URL> urls = new ArrayList<URL>();
|
ArrayList<URL> urls = new ArrayList<URL>();
|
||||||
for (File bootdir : dirs) {
|
for (File bootdir : dirs) {
|
||||||
|
@ -75,8 +88,8 @@ public class Artemis {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (instance != null) {
|
if (fileInstance != null) {
|
||||||
System.setProperty("java.io.tmpdir", new File(new File(instance), "tmp").getCanonicalPath());
|
System.setProperty("java.io.tmpdir", new File(fileInstance, "tmp").getCanonicalPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lets try to covert the logging.configuration setting to a valid URI
|
// Lets try to covert the logging.configuration setting to a valid URI
|
||||||
|
@ -86,23 +99,28 @@ public class Artemis {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Without the etc on the config, things like JGroups configuration wouldn't be loaded
|
// Without the etc on the config, things like JGroups configuration wouldn't be loaded
|
||||||
if (instanceFile != null) {
|
if (fileInstance != null) {
|
||||||
File etcFile = new File(instance, "etc");
|
File etcFile = new File(fileInstance, "etc");
|
||||||
// Adding etc to the classLoader so modules can lookup for their configs
|
// Adding etc to the classLoader so modules can lookup for their configs
|
||||||
urls.add(etcFile.toURI().toURL());
|
urls.add(etcFile.toURI().toURL());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ClassLoader originalCL = Thread.currentThread().getContextClassLoader();
|
||||||
|
|
||||||
// Now setup our classloader..
|
// Now setup our classloader..
|
||||||
URLClassLoader loader = new URLClassLoader(urls.toArray(new URL[urls.size()]));
|
URLClassLoader loader = new URLClassLoader(urls.toArray(new URL[urls.size()]));
|
||||||
Thread.currentThread().setContextClassLoader(loader);
|
Thread.currentThread().setContextClassLoader(loader);
|
||||||
Class<?> clazz = loader.loadClass("org.apache.activemq.artemis.cli.Artemis");
|
Class<?> clazz = loader.loadClass("org.apache.activemq.artemis.cli.Artemis");
|
||||||
Method method = clazz.getMethod("main", args.getClass());
|
Method method = clazz.getMethod("execute", File.class, File.class, args.getClass());
|
||||||
try {
|
try {
|
||||||
method.invoke(null, (Object) args);
|
method.invoke(null, fileHome, fileInstance, args);
|
||||||
}
|
}
|
||||||
catch (InvocationTargetException e) {
|
catch (InvocationTargetException e) {
|
||||||
throw e.getTargetException();
|
throw e.getTargetException();
|
||||||
}
|
}
|
||||||
|
finally {
|
||||||
|
Thread.currentThread().setContextClassLoader(originalCL);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,13 +44,26 @@ public class Artemis {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static void main(String... args) throws Exception {
|
public static void main(String... args) throws Exception {
|
||||||
|
execute(null, null, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Object internalExecute(String... args) throws Exception {
|
||||||
|
return internalExecute(null, null, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Object execute(File artemisHome, File artemisInstance, List<String> args) throws Exception {
|
||||||
|
return execute(artemisHome, artemisInstance, (String[]) args.toArray(new String[args.size()]));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Object execute(File artemisHome, File artemisInstance, String... args) throws Exception {
|
||||||
try {
|
try {
|
||||||
execute(args);
|
return internalExecute(artemisHome, artemisInstance, args);
|
||||||
}
|
}
|
||||||
catch (ConfigurationException configException) {
|
catch (ConfigurationException configException) {
|
||||||
System.err.println(configException.getMessage());
|
System.err.println(configException.getMessage());
|
||||||
System.out.println();
|
System.out.println();
|
||||||
System.out.println("Configuration should be specified as 'scheme:location'. Default configuration is 'xml:${ARTEMIS_INSTANCE}/etc/bootstrap.xml'");
|
System.out.println("Configuration should be specified as 'scheme:location'. Default configuration is 'xml:${ARTEMIS_INSTANCE}/etc/bootstrap.xml'");
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
catch (RuntimeException re) {
|
catch (RuntimeException re) {
|
||||||
System.err.println(re.getMessage());
|
System.err.println(re.getMessage());
|
||||||
|
@ -59,18 +72,13 @@ public class Artemis {
|
||||||
Cli<Action> parser = builder(null).build();
|
Cli<Action> parser = builder(null).build();
|
||||||
|
|
||||||
parser.parse("help").execute(ActionContext.system());
|
parser.parse("help").execute(ActionContext.system());
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object execute(String... args) throws Exception {
|
/** This method is used to validate exception returns.
|
||||||
return execute(null, null, args);
|
* Useful on test cases */
|
||||||
}
|
public static Object internalExecute(File artemisHome, File artemisInstance, String[] args) throws Exception {
|
||||||
|
|
||||||
public static Object execute(File artemisHome, File artemisInstance, List<String> args) throws Exception {
|
|
||||||
return execute(artemisHome, artemisInstance, (String[]) args.toArray(new String[args.size()]));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Object execute(File artemisHome, File artemisInstance, String... args) throws Exception {
|
|
||||||
Action action = builder(artemisInstance).build().parse(args);
|
Action action = builder(artemisInstance).build().parse(args);
|
||||||
action.setHomeValues(artemisHome, artemisInstance);
|
action.setHomeValues(artemisHome, artemisInstance);
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,10 @@ public class ActionContext {
|
||||||
this.err = err;
|
this.err = err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ActionContext() {
|
||||||
|
this(System.in, System.out, System.err);
|
||||||
|
}
|
||||||
|
|
||||||
public InputStream in;
|
public InputStream in;
|
||||||
public PrintStream out;
|
public PrintStream out;
|
||||||
public PrintStream err;
|
public PrintStream err;
|
||||||
|
|
|
@ -91,7 +91,7 @@ public class ArtemisTest {
|
||||||
Artemis.main("create", temporaryFolder.getRoot().getAbsolutePath(), "--force", "--silent", "--no-web", "--queues", queues, "--topics", topics);
|
Artemis.main("create", temporaryFolder.getRoot().getAbsolutePath(), "--force", "--silent", "--no-web", "--queues", queues, "--topics", topics);
|
||||||
System.setProperty("artemis.instance", temporaryFolder.getRoot().getAbsolutePath());
|
System.setProperty("artemis.instance", temporaryFolder.getRoot().getAbsolutePath());
|
||||||
// Some exceptions may happen on the initialization, but they should be ok on start the basic core protocol
|
// Some exceptions may happen on the initialization, but they should be ok on start the basic core protocol
|
||||||
Artemis.execute("run");
|
Artemis.internalExecute("run");
|
||||||
|
|
||||||
try (ServerLocator locator = ServerLocatorImpl.newLocator("tcp://localhost:61616");
|
try (ServerLocator locator = ServerLocatorImpl.newLocator("tcp://localhost:61616");
|
||||||
ClientSessionFactory factory = locator.createSessionFactory();
|
ClientSessionFactory factory = locator.createSessionFactory();
|
||||||
|
@ -106,8 +106,8 @@ public class ArtemisTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.assertEquals(Integer.valueOf(1000), Artemis.execute("producer", "--message-count", "1000", "--verbose"));
|
Assert.assertEquals(Integer.valueOf(1000), Artemis.internalExecute("producer", "--message-count", "1000", "--verbose"));
|
||||||
Assert.assertEquals(Integer.valueOf(1000), Artemis.execute("consumer", "--verbose", "--break-on-null", "--receive-timeout", "100"));
|
Assert.assertEquals(Integer.valueOf(1000), Artemis.internalExecute("consumer", "--verbose", "--break-on-null", "--receive-timeout", "100"));
|
||||||
|
|
||||||
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:61616");
|
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:61616");
|
||||||
Connection connection = cf.createConnection();
|
Connection connection = cf.createConnection();
|
||||||
|
@ -128,22 +128,22 @@ public class ArtemisTest {
|
||||||
connection.close();
|
connection.close();
|
||||||
cf.close();
|
cf.close();
|
||||||
|
|
||||||
Assert.assertEquals(Integer.valueOf(1), Artemis.execute("browser", "--txt-size", "50", "--verbose", "--filter", "fruit='banana'"));
|
Assert.assertEquals(Integer.valueOf(1), Artemis.internalExecute("browser", "--txt-size", "50", "--verbose", "--filter", "fruit='banana'"));
|
||||||
|
|
||||||
Assert.assertEquals(Integer.valueOf(100), Artemis.execute("browser", "--txt-size", "50", "--verbose", "--filter", "fruit='orange'"));
|
Assert.assertEquals(Integer.valueOf(100), Artemis.internalExecute("browser", "--txt-size", "50", "--verbose", "--filter", "fruit='orange'"));
|
||||||
|
|
||||||
Assert.assertEquals(Integer.valueOf(101), Artemis.execute("browser", "--txt-size", "50", "--verbose"));
|
Assert.assertEquals(Integer.valueOf(101), Artemis.internalExecute("browser", "--txt-size", "50", "--verbose"));
|
||||||
|
|
||||||
// should only receive 10 messages on browse as I'm setting messageCount=10
|
// should only receive 10 messages on browse as I'm setting messageCount=10
|
||||||
Assert.assertEquals(Integer.valueOf(10), Artemis.execute("browser", "--txt-size", "50", "--verbose", "--message-count", "10"));
|
Assert.assertEquals(Integer.valueOf(10), Artemis.internalExecute("browser", "--txt-size", "50", "--verbose", "--message-count", "10"));
|
||||||
|
|
||||||
// Nothing was consumed until here as it was only browsing, check it's receiving again
|
// Nothing was consumed until here as it was only browsing, check it's receiving again
|
||||||
Assert.assertEquals(Integer.valueOf(1), Artemis.execute("consumer", "--txt-size", "50", "--verbose", "--break-on-null", "--receive-timeout", "100", "--filter", "fruit='banana'"));
|
Assert.assertEquals(Integer.valueOf(1), Artemis.internalExecute("consumer", "--txt-size", "50", "--verbose", "--break-on-null", "--receive-timeout", "100", "--filter", "fruit='banana'"));
|
||||||
|
|
||||||
// Checking it was acked before
|
// Checking it was acked before
|
||||||
Assert.assertEquals(Integer.valueOf(100), Artemis.execute("consumer", "--txt-size", "50", "--verbose", "--break-on-null", "--receive-timeout", "100"));
|
Assert.assertEquals(Integer.valueOf(100), Artemis.internalExecute("consumer", "--txt-size", "50", "--verbose", "--break-on-null", "--receive-timeout", "100"));
|
||||||
|
|
||||||
Artemis.execute("stop");
|
Artemis.internalExecute("stop");
|
||||||
Assert.assertTrue(Run.latchRunning.await(5, TimeUnit.SECONDS));
|
Assert.assertTrue(Run.latchRunning.await(5, TimeUnit.SECONDS));
|
||||||
Assert.assertEquals(0, LibaioContext.getTotalMaxIO());
|
Assert.assertEquals(0, LibaioContext.getTotalMaxIO());
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,6 @@ import java.nio.file.Files;
|
||||||
import java.nio.file.LinkOption;
|
import java.nio.file.LinkOption;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
|
||||||
import org.apache.activemq.artemis.cli.Artemis;
|
|
||||||
import org.apache.activemq.artemis.cli.commands.Run;
|
import org.apache.activemq.artemis.cli.commands.Run;
|
||||||
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
|
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
|
||||||
import org.apache.maven.plugin.MojoExecutionException;
|
import org.apache.maven.plugin.MojoExecutionException;
|
||||||
|
@ -31,6 +30,7 @@ import org.apache.maven.plugins.annotations.LifecyclePhase;
|
||||||
import org.apache.maven.plugins.annotations.Mojo;
|
import org.apache.maven.plugins.annotations.Mojo;
|
||||||
import org.apache.maven.plugins.annotations.Parameter;
|
import org.apache.maven.plugins.annotations.Parameter;
|
||||||
import org.apache.maven.project.MavenProject;
|
import org.apache.maven.project.MavenProject;
|
||||||
|
import org.apache.activemq.artemis.boot.Artemis;
|
||||||
|
|
||||||
@Mojo(name = "cli", defaultPhase = LifecyclePhase.VERIFY)
|
@Mojo(name = "cli", defaultPhase = LifecyclePhase.VERIFY)
|
||||||
public class ArtemisCLIPlugin extends ArtemisAbstractPlugin {
|
public class ArtemisCLIPlugin extends ArtemisAbstractPlugin {
|
||||||
|
@ -158,7 +158,7 @@ public class ArtemisCLIPlugin extends ArtemisAbstractPlugin {
|
||||||
|
|
||||||
org.apache.activemq.artemis.cli.process.ProcessBuilder.cleanupProcess();
|
org.apache.activemq.artemis.cli.process.ProcessBuilder.cleanupProcess();
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Throwable e) {
|
||||||
throw new MojoExecutionException(e.getMessage(), e);
|
throw new MojoExecutionException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.activemq.artemis.cli.Artemis;
|
import org.apache.activemq.artemis.boot.Artemis;
|
||||||
import org.apache.activemq.artemis.utils.FileUtil;
|
import org.apache.activemq.artemis.utils.FileUtil;
|
||||||
import org.apache.maven.plugin.MojoExecutionException;
|
import org.apache.maven.plugin.MojoExecutionException;
|
||||||
import org.apache.maven.plugin.MojoFailureException;
|
import org.apache.maven.plugin.MojoFailureException;
|
||||||
|
@ -351,7 +351,7 @@ public class ArtemisCreatePlugin extends ArtemisAbstractPlugin {
|
||||||
getLog().info("###################################################################################################");
|
getLog().info("###################################################################################################");
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Throwable e) {
|
||||||
getLog().error(e);
|
getLog().error(e);
|
||||||
throw new MojoFailureException(e.getMessage());
|
throw new MojoFailureException(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
|
@ -148,15 +148,10 @@ public class RemotingServiceImpl implements RemotingService, ConnectionLifeCycle
|
||||||
this.protocolMap.put(coreProtocolManagerFactory.getProtocols()[0], coreProtocolManagerFactory.createProtocolManager(server, coreProtocolManagerFactory.filterInterceptors(incomingInterceptors), coreProtocolManagerFactory.filterInterceptors(outgoingInterceptors)));
|
this.protocolMap.put(coreProtocolManagerFactory.getProtocols()[0], coreProtocolManagerFactory.createProtocolManager(server, coreProtocolManagerFactory.filterInterceptors(incomingInterceptors), coreProtocolManagerFactory.filterInterceptors(outgoingInterceptors)));
|
||||||
|
|
||||||
if (config.isResolveProtocols()) {
|
if (config.isResolveProtocols()) {
|
||||||
ServiceLoader<ProtocolManagerFactory> serviceLoader = ServiceLoader.load(ProtocolManagerFactory.class, this.getClass().getClassLoader());
|
resolveProtocols(server, this.getClass().getClassLoader());
|
||||||
if (serviceLoader != null) {
|
|
||||||
for (ProtocolManagerFactory next : serviceLoader) {
|
if (this.getClass().getClassLoader() != Thread.currentThread().getContextClassLoader()) {
|
||||||
String[] protocols = next.getProtocols();
|
resolveProtocols(server, Thread.currentThread().getContextClassLoader());
|
||||||
for (String protocol : protocols) {
|
|
||||||
ActiveMQServerLogger.LOGGER.addingProtocolSupport(protocol, next.getModuleName());
|
|
||||||
protocolMap.put(protocol, next.createProtocolManager(server, next.filterInterceptors(incomingInterceptors), next.filterInterceptors(outgoingInterceptors)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,7 +166,18 @@ public class RemotingServiceImpl implements RemotingService, ConnectionLifeCycle
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemotingService implementation -------------------------------
|
private void resolveProtocols(ActiveMQServer server, ClassLoader loader) {
|
||||||
|
ServiceLoader<ProtocolManagerFactory> serviceLoader = ServiceLoader.load(ProtocolManagerFactory.class, loader);
|
||||||
|
if (serviceLoader != null) {
|
||||||
|
for (ProtocolManagerFactory next : serviceLoader) {
|
||||||
|
String[] protocols = next.getProtocols();
|
||||||
|
for (String protocol : protocols) {
|
||||||
|
ActiveMQServerLogger.LOGGER.addingProtocolSupport(protocol, next.getModuleName());
|
||||||
|
protocolMap.put(protocol, next.createProtocolManager(server, next.filterInterceptors(incomingInterceptors), next.filterInterceptors(outgoingInterceptors)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void setInterceptors(Configuration configuration) {
|
private void setInterceptors(Configuration configuration) {
|
||||||
incomingInterceptors.addAll(serviceRegistry.getIncomingInterceptors(configuration.getIncomingInterceptorClassNames()));
|
incomingInterceptors.addAll(serviceRegistry.getIncomingInterceptors(configuration.getIncomingInterceptorClassNames()));
|
||||||
|
|
2
pom.xml
2
pom.xml
|
@ -339,7 +339,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.activemq</groupId>
|
<groupId>org.apache.activemq</groupId>
|
||||||
<artifactId>activemq-client</artifactId>
|
<artifactId>activemq-client</artifactId>
|
||||||
<version>5.11.1</version>
|
<version>5.12.0</version>
|
||||||
<!-- License: Apache 2.0 -->
|
<!-- License: Apache 2.0 -->
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
Loading…
Reference in New Issue