From 7d14ddb0d15c9221f35318661c98f4993b94e3bd Mon Sep 17 00:00:00 2001 From: Dejan Bosanac Date: Thu, 12 Feb 2015 11:35:06 +0100 Subject: [PATCH] https://issues.apache.org/jira/browse/AMQ-5558 - make activemq-all jar executable --- activemq-all/pom.xml | 15 +++ activemq-all/src/main/resources/activemq.xml | 109 ++++++++++++++++++ .../src/main/resources/log4j.properties | 43 +++++++ .../console/command/ConsumerCommand.java | 53 +++++---- .../console/command/ProducerCommand.java | 59 +++++----- .../console/command/ShellCommand.java | 4 + 6 files changed, 234 insertions(+), 49 deletions(-) create mode 100644 activemq-all/src/main/resources/activemq.xml create mode 100644 activemq-all/src/main/resources/log4j.properties diff --git a/activemq-all/pom.xml b/activemq-all/pom.xml index d26c9c8912..b750e024d1 100644 --- a/activemq-all/pom.xml +++ b/activemq-all/pom.xml @@ -71,6 +71,10 @@ org.slf4j slf4j-log4j12 + + org.slf4j + jcl-over-slf4j + @@ -116,7 +120,13 @@ org.apache.geronimo.specs:geronimo-annotation_1.0_spec org.slf4j:slf4j-api org.slf4j:slf4j-log4j12 + org.slf4j:jcl-over-slf4j log4j:log4j + org.springframework:spring-core + org.springframework:spring-beans + org.springframework:spring-context + org.springframework:spring-expression + org.apache.xbean:xbean-spring @@ -140,6 +150,11 @@ META-INF/spring.schemas + + + org.apache.activemq.console.command.ShellCommand + + diff --git a/activemq-all/src/main/resources/activemq.xml b/activemq-all/src/main/resources/activemq.xml new file mode 100644 index 0000000000..87e398fe4f --- /dev/null +++ b/activemq-all/src/main/resources/activemq.xml @@ -0,0 +1,109 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/activemq-all/src/main/resources/log4j.properties b/activemq-all/src/main/resources/log4j.properties new file mode 100644 index 0000000000..0cb38c4c4d --- /dev/null +++ b/activemq-all/src/main/resources/log4j.properties @@ -0,0 +1,43 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- + +# +# This file controls most of the logging in ActiveMQ which is mainly based around +# the commons logging API. +# +log4j.rootLogger=INFO, console +log4j.logger.org.apache.activemq.spring=WARN +log4j.logger.org.apache.activemq.web.handler=WARN +log4j.logger.org.springframework=WARN +log4j.logger.org.apache.xbean=WARN +log4j.logger.org.apache.camel=INFO +log4j.logger.org.eclipse.jetty=WARN + +# When debugging or reporting problems to the ActiveMQ team, +# comment out the above lines and uncomment the next. + +#log4j.rootLogger=DEBUG, logfile, console + +# Or for more fine grained debug logging uncomment one of these +#log4j.logger.org.apache.activemq=DEBUG +#log4j.logger.org.apache.camel=DEBUG + +# Console appender +log4j.appender.console=org.apache.log4j.ConsoleAppender +log4j.appender.console.layout=org.apache.log4j.PatternLayout +log4j.appender.console.layout.ConversionPattern=%5p | %m%n +log4j.appender.console.threshold=INFO \ No newline at end of file diff --git a/activemq-console/src/main/java/org/apache/activemq/console/command/ConsumerCommand.java b/activemq-console/src/main/java/org/apache/activemq/console/command/ConsumerCommand.java index 962b6ad799..3998610d59 100644 --- a/activemq-console/src/main/java/org/apache/activemq/console/command/ConsumerCommand.java +++ b/activemq-console/src/main/java/org/apache/activemq/console/command/ConsumerCommand.java @@ -48,31 +48,38 @@ public class ConsumerCommand extends AbstractCommand { LOG.info("Running " + parallelThreads + " parallel threads"); ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(brokerUrl); - Connection conn = factory.createConnection(user, password); - conn.start(); + Connection conn = null; + try { + conn = factory.createConnection(user, password); + conn.start(); - Session sess; - if (transactionBatchSize != 0) { - sess = conn.createSession(true, Session.SESSION_TRANSACTED); - } else { - sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); + Session sess; + if (transactionBatchSize != 0) { + sess = conn.createSession(true, Session.SESSION_TRANSACTED); + } else { + sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); + } + + + CountDownLatch active = new CountDownLatch(parallelThreads); + + for (int i = 1; i <= parallelThreads; i++) { + ConsumerThread consumer = new ConsumerThread(sess, ActiveMQDestination.createDestination(destination, ActiveMQDestination.QUEUE_TYPE)); + consumer.setName("consumer-" + i); + consumer.setBreakOnNull(false); + consumer.setMessageCount(messageCount); + consumer.setSleep(sleep); + consumer.setTransactionBatchSize(transactionBatchSize); + consumer.setFinished(active); + consumer.start(); + } + + active.await(); + } finally { + if (conn != null) { + conn.close(); + } } - - - CountDownLatch active = new CountDownLatch(parallelThreads); - - for (int i = 1; i <= parallelThreads; i++) { - ConsumerThread consumer = new ConsumerThread(sess, ActiveMQDestination.createDestination(destination, ActiveMQDestination.QUEUE_TYPE)); - consumer.setName("consumer-" + i); - consumer.setBreakOnNull(false); - consumer.setMessageCount(messageCount); - consumer.setSleep(sleep); - consumer.setTransactionBatchSize(transactionBatchSize); - consumer.setFinished(active); - consumer.start(); - } - - active.await(); } public String getBrokerUrl() { diff --git a/activemq-console/src/main/java/org/apache/activemq/console/command/ProducerCommand.java b/activemq-console/src/main/java/org/apache/activemq/console/command/ProducerCommand.java index ba696bbfb9..5f3ac92d6b 100644 --- a/activemq-console/src/main/java/org/apache/activemq/console/command/ProducerCommand.java +++ b/activemq-console/src/main/java/org/apache/activemq/console/command/ProducerCommand.java @@ -55,34 +55,41 @@ public class ProducerCommand extends AbstractCommand { LOG.info("Running " + parallelThreads + " parallel threads"); ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(brokerUrl); - Connection conn = factory.createConnection(user, password); - conn.start(); + Connection conn = null; + try { + conn = factory.createConnection(user, password); + conn.start(); - Session sess; - if (transactionBatchSize != 0) { - sess = conn.createSession(true, Session.SESSION_TRANSACTED); - } else { - sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); + Session sess; + if (transactionBatchSize != 0) { + sess = conn.createSession(true, Session.SESSION_TRANSACTED); + } else { + sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); + } + + CountDownLatch active = new CountDownLatch(parallelThreads); + + for (int i = 1; i <= parallelThreads; i++) { + ProducerThread producer = new ProducerThread(sess, ActiveMQDestination.createDestination(destination, ActiveMQDestination.QUEUE_TYPE)); + producer.setName("producer-" + i); + producer.setMessageCount(messageCount); + producer.setSleep(sleep); + producer.setMsgTTL(msgTTL); + producer.setPersistent(persistent); + producer.setTransactionBatchSize(transactionBatchSize); + producer.setMessageSize(messageSize); + producer.setMsgGroupID(msgGroupID); + producer.setTextMessageSize(textMessageSize); + producer.setFinished(active); + producer.start(); + } + + active.await(); + } finally { + if (conn != null) { + conn.close(); + } } - - CountDownLatch active = new CountDownLatch(parallelThreads); - - for (int i = 1; i <= parallelThreads; i++) { - ProducerThread producer = new ProducerThread(sess, ActiveMQDestination.createDestination(destination, ActiveMQDestination.QUEUE_TYPE)); - producer.setName("producer-" + i); - producer.setMessageCount(messageCount); - producer.setSleep(sleep); - producer.setMsgTTL(msgTTL); - producer.setPersistent(persistent); - producer.setTransactionBatchSize(transactionBatchSize); - producer.setMessageSize(messageSize); - producer.setMsgGroupID(msgGroupID); - producer.setTextMessageSize(textMessageSize); - producer.setFinished(active); - producer.start(); - } - - active.await(); } public String getBrokerUrl() { diff --git a/activemq-console/src/main/java/org/apache/activemq/console/command/ShellCommand.java b/activemq-console/src/main/java/org/apache/activemq/console/command/ShellCommand.java index 10074aaa21..ad6bfc5c39 100644 --- a/activemq-console/src/main/java/org/apache/activemq/console/command/ShellCommand.java +++ b/activemq-console/src/main/java/org/apache/activemq/console/command/ShellCommand.java @@ -109,6 +109,10 @@ public class ShellCommand extends AbstractCommand { } } + public static void main(String[] args) { + main(args, System.in, System.out); + } + public boolean isInteractive() { return interactive; }