diff --git a/activemq-core/src/main/java/org/activemq/broker/Main.java b/activemq-core/src/main/java/org/activemq/broker/Main.java index 8d2148d852..599b16fe08 100755 --- a/activemq-core/src/main/java/org/activemq/broker/Main.java +++ b/activemq-core/src/main/java/org/activemq/broker/Main.java @@ -18,122 +18,545 @@ **/ package org.activemq.broker; +import javax.management.remote.JMXServiceURL; +import javax.management.remote.JMXConnector; +import javax.management.remote.JMXConnectorFactory; +import javax.management.MBeanServerConnection; +import javax.management.ObjectName; +import javax.management.ObjectInstance; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Iterator; +import java.util.Set; +import java.util.Map; +import java.util.HashMap; import java.io.File; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.net.JarURLConnection; import java.net.MalformedURLException; -import java.net.URI; -import java.net.URISyntaxException; import java.net.URL; import java.net.URLClassLoader; -import java.util.ArrayList; -import java.util.Iterator; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.JarURLConnection; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.InvocationTargetException; /** * Main class that can bootstrap a ActiveMQ Broker. Handles command line * argument parsing to set up the broker classpath and System properties. - * + * * @version $Revision$ */ public class Main { + public static final int HELP_MAIN_APP = 0; + public static final int HELP_START_BROKER = 1; + public static final int HELP_STOP_BROKER = 2; + public static final int HELP_LIST_BROKER = 3; + public static final int HELP_STAT_BROKER = 4; + + public static final int TASK_NONE = -1; + public static final int TASK_START_BROKER = 0; + public static final int TASK_STOP_BROKER = 1; + public static final int TASK_LIST_BROKER = 2; + public static final int TASK_STAT_BROKER = 3; + public static final int TASK_PRINT_MAIN_HELP = 4; + public static final int TASK_PRINT_START_HELP = 5; + public static final int TASK_PRINT_STOP_HELP = 6; + public static final int TASK_PRINT_LIST_HELP = 7; + public static final int TASK_PRINT_STAT_HELP = 8; + public static final int TASK_PRINT_ALL_HELP = 9; + public static final int TASK_PRINT_VER = 10; private static final String BROKER_FACTORY_CLASS = "org.activemq.broker.BrokerFactory"; - private static File activeMQHome; + private static final String DEFAULT_CONFIG_URI = "xbean:activemq.xml"; + private static final String DEFAULT_JMX_URL = "service:jmx:rmi:///jndi/rmi://localhost:1099/jmxconnector"; + private static final String DEFAULT_JMX_DOMAIN = "org.activemq"; + + private static final String DEFAULT_KEY_BROKER_NAME = "BrokerName"; + private static final String DEFAULT_METHOD_BROKER_STOP = "terminateJVM"; + private static final Object[] DEFAULT_PARAM_BROKER_STOP = new Object[] {new Integer(0)}; + private static final String[] DEFAULT_SIGN_BROKER_STOP = new String[] {"int"}; + + // Stat retrieve flags + private static final int STAT_BROKER = Integer.parseInt("0001", 2); + private static final int STAT_ALL = Integer.parseInt("1111", 2); + + private static final String[] STAT_BROKER_MAP = new String[] { + "TotalEnqueueCount", "TotalDequeueCount", "TotalConsumerCount", "TotalMessages", + "TotalMessagesCached", "MemoryPercentageUsed", "MemoryLimit" + }; + + // Stat display flags + private static final int STAT_DISP_BROKER = Integer.parseInt("0001", 2); + private static final int STAT_DISP_ALL = Integer.parseInt("1111", 2); + private final ArrayList extensions = new ArrayList(); - private URI uri; - private ClassLoader classLoader; - public static void main(String[] args) throws Throwable { - Main main = new Main(); - - for (int i = 0; i < args.length; i++) { - if (args[i].startsWith("-D")) { - String key = args[i].substring(2); - String value = ""; - int pos = key.indexOf("="); - if (pos >= 0) { - value = key.substring(pos + 1); - key = key.substring(0, pos); - } - System.setProperty(key, value); - } else if (args[i].equals("--extdir")) { - if( !canUseExtdir() ) { - System.out.println("Extension directory feature not available due to the system classpath being able to load: "+BROKER_FACTORY_CLASS); - printUsage(); - return; - } - i++; - if (i >= args.length) { - System.out.println("Extension directory not specified."); - printUsage(); - return; - } + private int taskType = TASK_NONE; + private boolean stopAll = false; + private JMXServiceURL jmxUrl; + private URI configURI; + private File activeMQHome; + private ClassLoader classLoader; - File directory = new File(args[i]); - if (!directory.isDirectory()) { - System.out.println("Extension directory specified is not valid directory: " + directory); - printUsage(); - return; - } - main.addExtensionDirectory(directory); + public static void main(String[] args) { + Main app = new Main(); - } else if (args[i].equals("--version")) { - System.out.println(); - System.out.println("ActiveMQ " + main.getVersion()); - System.out.println("For help or more information please see: http://www.logicblaze.com"); - System.out.println(); - return; - } else if (args[i].equals("-h") || args[i].equals("--help") || args[i].equals("-?")) { - printUsage(); - return; - } else { - if (main.getUri() != null) { - System.out.println("Multiple configuration uris cannot be specified."); - printUsage(); - return; - } + // Convert arguments to collection for easier management + ArrayList tokens = new ArrayList(Arrays.asList(args)); + + // First token should be task type (start|stop|list|-h|-?|--help|--version) + app.setTaskType(app.parseTask(tokens)); + + // Succeeding tokens should be task specific options identified by "-" at the start + app.parseOptions(tokens); + + // Succeeding tokens should be the task data + switch (app.getTaskType()) { + case TASK_START_BROKER: try { - main.setUri(new URI(args[i])); + app.taskStartBrokers(tokens); + } catch (Throwable e) { + System.out.println("Failed to start broker. Reason: " + e.getMessage()); + } + break; + + case TASK_STOP_BROKER: + try { + app.taskStopBrokers(tokens); + } catch (Throwable e) { + System.out.println("Failed to stop broker(s). Reason: " + e.getMessage()); + } + break; + + case TASK_LIST_BROKER: + try { + app.taskListBrokers(); + } catch (Throwable e) { + e.printStackTrace(); + System.out.println("Failed to list broker(s). Reason: " + e.getMessage()); + } + break; + + case TASK_STAT_BROKER: + try { + app.taskStatBrokers(tokens); + } catch (Throwable e) { + System.out.println("Failed to print broker statistics. Reason: " + e.getMessage()); + } + break; + + case TASK_PRINT_MAIN_HELP: + app.printHelp(HELP_MAIN_APP); + break; + + case TASK_PRINT_START_HELP: + app.printHelp(HELP_START_BROKER); + break; + + case TASK_PRINT_STOP_HELP: + app.printHelp(HELP_STOP_BROKER); + break; + + case TASK_PRINT_LIST_HELP: + app.printHelp(HELP_LIST_BROKER); + break; + + case TASK_PRINT_STAT_HELP: + app.printHelp(HELP_STAT_BROKER); + break; + + case TASK_PRINT_VER: + app.printVersion(); + break; + + case TASK_PRINT_ALL_HELP: + app.printAllHelp(); + break; + + case TASK_NONE: + default: + break; + } + } + + protected void taskStartBrokers(List brokerURIs) throws Throwable { + + // Flag an error if there are multiple configuration uris + if (brokerURIs.size() > 1) { + printError("Multiple configuration uris or broker names cannot be specified."); + brokerURIs.clear(); + return; + } + + // Add the default directories. + if(canUseExtdir()) { + this.addExtensionDirectory(new File(this.getActiveMQHome(), "conf")); + this.addExtensionDirectory(new File(this.getActiveMQHome(), "lib")); + this.addExtensionDirectory(new File(new File(this.getActiveMQHome(), "lib"), "optional")); + } + + // If no config uri, use default setting + if (brokerURIs.isEmpty()) { + this.setConfigUri(this.getDefaultUri()); + this.startBroker(this.getConfigUri()); + + // Set configuration data, if available, which in this case would be the config URI + } else { + String strConfigURI; +// while (!brokerURIs.isEmpty()) { + strConfigURI = (String)brokerURIs.remove(0); + + try { + this.setConfigUri(new URI(strConfigURI)); } catch (URISyntaxException e) { - System.out.println("Invalid broker configuration URI: " + args[i] + ", reason: " + e.getMessage()); - printUsage(); + printError("Invalid broker configuration URI: " + strConfigURI + ", reason: " + e.getMessage()); return; } + + this.startBroker(this.getConfigUri()); +// } + } + } + + protected void taskStopBrokers(List brokerNames) throws Throwable { + // Check if there is a user-specified JMX URL + if (this.getJmxUrl() == null) { + this.setJmxUrl(this.getDefaultJmxUrl()); + } + + // Stop all brokers + if (this.isStopAllBrokers()) { + JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxUrl); + MBeanServerConnection server = jmxConnector.getMBeanServerConnection(); + + ObjectName brokerObjName = new ObjectName(DEFAULT_JMX_DOMAIN + ":Type=Broker,*"); + + this.stopBroker(server, brokerObjName); + + jmxConnector.close(); + brokerNames.clear(); + + return; + } + + // Stop the default broker + if (brokerNames.isEmpty()) { + Set brokerList = this.getBrokerList(this.getJmxUrl()); + + // If there is no broker to stop + if (brokerList.isEmpty()) { + System.out.println("There are no brokers to stop."); + return; + + // There should only be one broker to stop + } else if (brokerList.size() > 1) { + System.out.println("There are multiple brokers to stop. Please select the broker(s) to stop or use --all to stop all brokers."); + System.out.println(); + printHelp(HELP_STOP_BROKER); + printBrokerList(brokerList); + return; + + // Stop the only running broker + } else { + Iterator brokerIter = brokerList.iterator(); + + JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxUrl); + MBeanServerConnection server = jmxConnector.getMBeanServerConnection(); + + this.stopBroker(server, ((ObjectInstance)brokerIter.next()).getObjectName()); + + // Maybe no need to close, since context is already closed by broker + //jmxConnector.close(); + return; + } + } + + // Stop each specified broker + String brokerName; + + JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxUrl); + MBeanServerConnection server = jmxConnector.getMBeanServerConnection(); + + while (!brokerNames.isEmpty()) { + brokerName = (String)brokerNames.remove(0); + this.stopBroker(server, brokerName); + } + + // Maybe be no need to close, since context is already closed by broker + //jmxConnector.close(); + } + + protected void taskListBrokers() throws Throwable { + // Check if there is a user-specified JMX URL + if (this.getJmxUrl() == null) { + this.setJmxUrl(this.getDefaultJmxUrl()); + } + + printBrokerList(this.getBrokerList(this.getJmxUrl())); + } + + protected void taskStatBrokers(List brokerNames) throws Throwable { + // Check if there is a user-specified JMX URL + if (this.getJmxUrl() == null) { + this.setJmxUrl(this.getDefaultJmxUrl()); + } + + // Print the statistics for the default broker + if (brokerNames.isEmpty()) { + Set brokerList = this.getBrokerList(this.getJmxUrl()); + + // If there is no broker to stop + if (brokerList.isEmpty()) { + System.out.println("There are no brokers running."); + return; + + // There should only be one broker to stop + } else if (brokerList.size() > 1) { + System.out.println("There are multiple brokers running. Please select the broker to display the statistics for."); + System.out.println(); + printHelp(HELP_STAT_BROKER); + printBrokerList(brokerList); + return; + + // Print the statistics for the only running broker + } else { + Iterator brokerIter = brokerList.iterator(); + + JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxUrl); + MBeanServerConnection server = jmxConnector.getMBeanServerConnection(); + + ObjectName brokerObjName = ((ObjectInstance)brokerIter.next()).getObjectName(); + this.printBrokerStat(brokerObjName.getKeyProperty(DEFAULT_KEY_BROKER_NAME), this.getBrokerStat(server, brokerObjName)); + + jmxConnector.close(); + return; + } + } + + // Print the statistics for each specified broker + String brokerName; + + JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxUrl); + MBeanServerConnection server = jmxConnector.getMBeanServerConnection(); + + while (!brokerNames.isEmpty()) { + brokerName = (String)brokerNames.remove(0); + System.out.println("-----------------------------------------------------"); + this.printBrokerStat(brokerName, this.getBrokerStat(server, brokerName)); + System.out.println(); + } + + jmxConnector.close(); + } + + public int parseTask(List tokens) { + if (tokens.isEmpty()) { + // If no defined arguments, assume start task and default uri + return TASK_START_BROKER; + } + + // Process task token + String taskToken = (String)tokens.get(0); + + if (taskToken.equals("start")) { + tokens.remove(0); + return TASK_START_BROKER; + } else if (taskToken.equals("stop")) { + tokens.remove(0); + return TASK_STOP_BROKER; + } else if (taskToken.equals("list")) { + tokens.remove(0); + return TASK_LIST_BROKER; + } else if (taskToken.equals("stat")) { + tokens.remove(0); + return TASK_STAT_BROKER; + } else if (taskToken.equals("-h") || taskToken.equals("-?") || taskToken.equals("--help")) { + // No need to parse other tokens + tokens.clear(); + return TASK_PRINT_MAIN_HELP; + } else if (taskToken.equals("--version")) { + // No need to parse other tokens + tokens.clear(); + return TASK_PRINT_VER; + } else { + // If not a valid task, assume start task and succeeding args are options + return TASK_START_BROKER; + } + } + + public void parseOptions(List tokens) { + String token; + + while (!tokens.isEmpty()) { + token = (String)tokens.get(0); + + // If token is an option + if (token.startsWith("-")) { + + // Consider token to be processed + tokens.remove(0); + + // If token is a help option + if (token.equals("-h") || token.equals("-?") || token.equals("--help")) { + switch (this.getTaskType()) { + case TASK_STOP_BROKER: + this.setTaskType(TASK_PRINT_STOP_HELP); + tokens.clear(); + return; + + case TASK_LIST_BROKER: + this.setTaskType(TASK_PRINT_LIST_HELP); + tokens.clear(); + return; + + case TASK_STAT_BROKER: + this.setTaskType(TASK_PRINT_STAT_HELP); + tokens.clear(); + return; + + case TASK_START_BROKER: + default: + this.setTaskType(TASK_PRINT_START_HELP); + tokens.clear(); + return; + + } + + // If token is a version option + } else if (token.equals("--version")) { + this.setTaskType(TASK_PRINT_VER); + tokens.clear(); + return; + + // If token is an extension dir option + } else if (token.equals("--extdir")) { + if(!canUseExtdir()) { + printError("Extension directory feature not available due to the system classpath being able to load: " + BROKER_FACTORY_CLASS); + tokens.clear(); + return; + } + + if (tokens.isEmpty()) { + printError("Extension directory not specified."); + return; + } + + // Process extension dir token + File extDir = new File((String)tokens.remove(0)); + if (!extDir.isDirectory()) { + printError("Extension directory specified is not valid directory: " + extDir); + return; + } + + this.addExtensionDirectory(extDir); + } + + // If token is a system property define option + else if (token.startsWith("-D")) { + String key = token.substring(2); + String value = ""; + int pos = key.indexOf("="); + if (pos >= 0) { + value = key.substring(pos + 1); + key = key.substring(0, pos); + } + System.setProperty(key, value); + } + + // If token is a JMX URL option + else if (token.startsWith("--jmxurl")) { + if (tokens.isEmpty()) { + printError("JMX URL not specified."); + return; + } + + if (getJmxUrl() != null) { + printError("Multiple JMX URL cannot be specified."); + tokens.clear(); + return; + } + + String strJmxUrl = (String)tokens.remove(0); + try { + this.setJmxUrl(new JMXServiceURL(strJmxUrl)); + } catch (MalformedURLException e) { + printError("Invalid JMX URL format: " + strJmxUrl); + tokens.clear(); + return; + } + + // If token is stop all broker option + } else if (token.equals("--all")) { + this.setStopAllBrokers(true); + + // Ignore unknown options + } else { + System.out.println("Ignoring unrecognized option: " + token); + } } } - - // Add the default directories. - if( canUseExtdir() ) { - main.addExtensionDirectory(new File(main.getActiveMQHome(), "conf")); - main.addExtensionDirectory(new File(main.getActiveMQHome(), "lib")); - main.addExtensionDirectory(new File(new File(main.getActiveMQHome(), "lib"), "optional")); - } - - - if (main.getUri() == null) { - main.setUri(getDefaultUri()); - } - main.run(); } + public void addExtensionDirectory(File directory) { + extensions.add(directory); + } - public static URI getDefaultUri() { + public void startBroker(URI configURI) throws Throwable { + System.out.println("Loading Message Broker from: " + configURI); + System.out.println("ACTIVEMQ_HOME: "+ getActiveMQHome()); + + ClassLoader cl = getClassLoader(); + + // Use reflection to start the broker up. + Object broker; try { - return new URI("xbean:activemq.xml"); - } catch (URISyntaxException e) { - throw new RuntimeException(e); + Class brokerFactory = cl.loadClass(BROKER_FACTORY_CLASS); + Method createBroker = brokerFactory.getMethod("createBroker", new Class[] { URI.class }); + broker = createBroker.invoke(null, new Object[] { configURI }); + + Method start = broker.getClass().getMethod("start", new Class[]{}); + start.invoke(broker, new Object[]{}); + + } catch (InvocationTargetException e) { + throw e.getCause(); + } catch (Throwable e) { + throw e; + } + } + + public void stopBroker(MBeanServerConnection server, String brokerName) { + ObjectName brokerObjName = null; + try { + brokerObjName = new ObjectName(DEFAULT_JMX_DOMAIN + ":Type=Broker," + DEFAULT_KEY_BROKER_NAME + "=" + brokerName); + } catch (Exception e) { + System.out.println("Invalid broker name: " + brokerName); + return; + } + stopBroker(server, brokerObjName); + } + + public void stopBroker(MBeanServerConnection server, ObjectName brokerObjName) { + String brokerName = brokerObjName.getKeyProperty(DEFAULT_KEY_BROKER_NAME); + + try { + server.invoke(brokerObjName, DEFAULT_METHOD_BROKER_STOP, DEFAULT_PARAM_BROKER_STOP, DEFAULT_SIGN_BROKER_STOP); + System.out.println("Succesfully stopped broker: " + brokerName); + } catch (Exception e) { + // TODO: Check the exceptions thrown + // System.out.println("Failed to stop broker: [ " + brokerName + " ]. Reason: " + e.getMessage()); + return; } } /** - * The extension directory feature will not work if the broker factory is already in the classpath + * The extension directory feature will not work if the broker factory is already in the classpath * since we have to load him from a child ClassLoader we build for it to work correctly. - * + * * @return */ - public static boolean canUseExtdir() { + public boolean canUseExtdir() { try { Main.class.getClassLoader().loadClass(BROKER_FACTORY_CLASS); return false; @@ -141,41 +564,91 @@ public class Main { return true; } } - - private static void printUsage() { - System.out.println(); - System.out.println("Usage: Main [options] uri"); - System.out.println(); - System.out.println("Options:"); - if( canUseExtdir() ) { - System.out.println(" --extdir dir Add the jar files in the directory to the classpath."); + + public void printHelp(int helpIndex) { + for (int i=0; i"); + } + System.out.println("For help or more information please see: http://www.logicblaze.com"); System.out.println(); } + public void printBrokerList(Set brokerList) { + Object[] brokerArray = brokerList.toArray(); + + System.out.println("List of available brokers:"); + for (int i=0; i \(.*\)$'` + if expr "$link" : '.*/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi + done + + ACTIVEMQ_HOME=`dirname "$PRG"`/.. + + cd "$saveddir" + + # make it fully qualified + ACTIVEMQ_HOME=`cd "$ACTIVEMQ_HOME" && pwd` +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$ACTIVEMQ_HOME" ] && + ACTIVEMQ_HOME=`cygpath --unix "$ACTIVEMQ_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD=`which java 2> /dev/null ` + if [ -z "$JAVACMD" ] ; then + JAVACMD=java + fi + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." + echo " We cannot execute $JAVACMD" + exit 1 +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + ACTIVEMQ_HOME=`cygpath --windows "$ACTIVEMQ_HOME"` + JAVA_HOME=`cygpath --windows "$JAVA_HOME"` + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + CYGHOME=`cygpath --windows "$HOME"` +fi + + +if [ -n "ACTIVEMQ_OPTS" ] ; then + ACTIVEMQ_OPTS="-Xmx512M -Dderby.system.home=../data -Dderby.storage.fileSyncTransactionLog=true" +fi + +# Uncomment to enable YourKit profiling +#ACTIVEMQ_DEBUG_OPTS="-Xrunyjpagent" + +# Uncomment to enable remote debugging +#ACTIVEMQ_DEBUG_OPTS="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005" + +ACTIVEMQ_TASK="stop" +if [ -n "$CYGHOME" ]; then + exec "$JAVACMD" $ACTIVEMQ_DEBUG_OPTS $ACTIVEMQ_OPTS -classpath "" -Dactivemq.home="${ACTIVEMQ_HOME}" -Dcygwin.user.home="$CYGHOME" -jar ${ACTIVEMQ_HOME}/bin/run.jar $ACTIVEMQ_TASK $@ +else + exec "$JAVACMD" $ACTIVEMQ_DEBUG_OPTS $ACTIVEMQ_OPTS -classpath "" -Dactivemq.home="${ACTIVEMQ_HOME}" -jar ${ACTIVEMQ_HOME}/bin/run.jar $ACTIVEMQ_TASK $@ +fi + diff --git a/assembly/src/release/bin/shutdown.bat b/assembly/src/release/bin/shutdown.bat new file mode 100644 index 0000000000..de186aec99 --- /dev/null +++ b/assembly/src/release/bin/shutdown.bat @@ -0,0 +1,106 @@ +@echo off + +REM ActiveMQ shell script +REM +REM $Id: shutdown.bat,v 1.1.1.1 2005/12/09 21:14:04 aco Exp $ +REM +REM This script is heavily based on the Ant script +REM +REM Copyright (c) 2001-2003 The Apache Software Foundation. All rights +REM reserved. + +if exist "%HOME%\activemqrc_pre.bat" call "%HOME%\activemqrc_pre.bat" + +if "%OS%"=="Windows_NT" @setlocal + +rem %~dp0 is expanded pathname of the current script under NT +set DEFAULT_ACTIVEMQ_HOME=%~dp0.. + +if "%ACTIVEMQ_HOME%"=="" set ACTIVEMQ_HOME=%DEFAULT_ACTIVEMQ_HOME% +set DEFAULT_ACTIVEMQ_HOME= + +rem Slurp the command line arguments. This loop allows for an unlimited number +rem of arguments (up to the command line limit, anyway). +set ACTIVEMQ_CMD_LINE_ARGS=%1 +if ""%1""=="""" goto doneStart +shift +:setupArgs +if ""%1""=="""" goto doneStart +set ACTIVEMQ_CMD_LINE_ARGS=%ACTIVEMQ_CMD_LINE_ARGS% %1 +shift +goto setupArgs +rem This label provides a place for the argument list loop to break out +rem and for NT handling to skip to. + +:doneStart +rem find ACTIVEMQ_HOME if it does not exist due to either an invalid value passed +rem by the user or the %0 problem on Windows 9x +if exist "%ACTIVEMQ_HOME%\README.txt" goto checkJava + +rem check for activemq in Program Files on system drive +if not exist "%SystemDrive%\Program Files\activemq" goto checkSystemDrive +set ACTIVEMQ_HOME=%SystemDrive%\Program Files\activemq +goto checkJava + +:checkSystemDrive +rem check for activemq in root directory of system drive +if not exist %SystemDrive%\activemq\README.txt goto checkCDrive +set ACTIVEMQ_HOME=%SystemDrive%\activemq +goto checkJava + +:checkCDrive +rem check for activemq in C:\activemq for Win9X users +if not exist C:\activemq\README.txt goto noAntHome +set ACTIVEMQ_HOME=C:\activemq +goto checkJava + +:noAntHome +echo ACTIVEMQ_HOME is set incorrectly or activemq could not be located. Please set ACTIVEMQ_HOME. +goto end + +:checkJava +set _JAVACMD=%JAVACMD% +set LOCALCLASSPATH=%CLASSPATH% + +set JAVA_EXT_DIRS=%JAVA_HOME%\lib\ext;%ACTIVEMQ_HOME%;%ACTIVEMQ_HOME%\lib;%ACTIVEMQ_HOME%\lib\optional + +if "%JAVA_HOME%" == "" goto noJavaHome +if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHome +if "%_JAVACMD%" == "" set _JAVACMD=%JAVA_HOME%\bin\java.exe +goto runAnt + +:noJavaHome +if "%_JAVACMD%" == "" set _JAVACMD=java.exe +echo. +echo Warning: JAVA_HOME environment variable is not set. +echo. + +:runAnt + +if "%ACTIVEMQ_OPTS%" == "" set ACTIVEMQ_OPTS=-Xmx512M -Dderby.system.home="..\data" -Dderby.storage.fileSyncTransactionLog=true + +REM Uncomment to enable YourKit profiling +REM SET ACTIVEMQ_DEBUG_OPTS="-Xrunyjpagent" + +REM Uncomment to enable remote debugging +REM SET ACTIVEMQ_DEBUG_OPTS=-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 + +set LOCALCLASSPATH=%ACTIVEMQ_HOME%\conf;%LOCALCLASSPATH% + +set ACTIVEMQ_TASK="stop" +"%_JAVACMD%" %ACTIVEMQ_DEBUG_OPTS% %ACTIVEMQ_OPTS% -Djava.ext.dirs="%JAVA_EXT_DIRS%" -classpath "%LOCALCLASSPATH%" -jar %ACTIVEMQ_HOME%/bin/run.jar %ACTIVEMQ_TASK% %ACTIVEMQ_CMD_LINE_ARGS% + + +goto end + + +:end +set LOCALCLASSPATH= +set _JAVACMD= +set ACTIVEMQ_CMD_LINE_ARGS= + +if "%OS%"=="Windows_NT" @endlocal + +:mainEnd +if exist "%HOME%\activemqrc_post.bat" call "%HOME%\activemqrc_post.bat" +