summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Ritchie <ritchiem@apache.org>2007-08-01 13:34:11 +0000
committerMartin Ritchie <ritchiem@apache.org>2007-08-01 13:34:11 +0000
commit326741e927301ccf036a3ec98718bc622ca9e435 (patch)
treecfabe8a5b265e200041cd43d44d94fabc4b0c600
parent59f5427b7f2b9f6959aebf257b1e6f11d237b03d (diff)
downloadqpid-python-326741e927301ccf036a3ec98718bc622ca9e435.tar.gz
Fix for a bug in the Broker Tools, preventing them working.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/branches/M2@561794 13f79535-47bb-0310-9956-ffa450edef68
-rwxr-xr-xjava/broker/bin/msTool.sh18
-rw-r--r--java/broker/src/main/java/org/apache/qpid/tools/messagestore/MessageStoreTool.java4
-rw-r--r--java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Copy.java9
-rw-r--r--java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Move.java51
-rw-r--r--java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Purge.java4
-rw-r--r--java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Select.java2
6 files changed, 67 insertions, 21 deletions
diff --git a/java/broker/bin/msTool.sh b/java/broker/bin/msTool.sh
index 4d55ee7811..73b1eb2ec7 100755
--- a/java/broker/bin/msTool.sh
+++ b/java/broker/bin/msTool.sh
@@ -18,9 +18,6 @@
# under the License.
#
-# Set classpath to include Qpid jar with all required jars in manifest
-QPID_LIBS=$QPID_TOOLS/lib/qpid-incubating.jar
-
die() {
if [[ $1 = -usage ]]; then
shift
@@ -39,18 +36,25 @@ if [[ "$(uname -a | fgrep Cygwin)" != "" ]]; then
cygwin=true
fi
+if [ -z "$QPID_TOOLS" ]; then
+ if [ -z "$QPID_HOME" ]; then
+ die "QPID_TOOLS must be set"
+ else
+ QPID_TOOLS=$QPID_HOME
+ fi
+fi
+
if $cygwin; then
QPID_TOOLS=$(cygpath -w $QPID_TOOLS)
fi
+# Set classpath to include Qpid jar with all required jars in manifest
+QPID_LIBS=$QPID_TOOLS/lib/qpid-incubating.jar
+
# Set other variables used by the qpid-run script before calling
export JAVA=java \
JAVA_VM=-server \
JAVA_OPTS=-Dlog4j.configuration=file:$QPID_TOOLS/etc/mstool-log4j.xml \
QPID_CLASSPATH=$QPID_LIBS
-if [ -z "$QPID_TOOLS" ]; then
- die "QPID_TOOLS be set"
-fi
-
. qpid-run org.apache.qpid.tools.messagestore.MessageStoreTool "$@"
diff --git a/java/broker/src/main/java/org/apache/qpid/tools/messagestore/MessageStoreTool.java b/java/broker/src/main/java/org/apache/qpid/tools/messagestore/MessageStoreTool.java
index afa7916074..edc900f401 100644
--- a/java/broker/src/main/java/org/apache/qpid/tools/messagestore/MessageStoreTool.java
+++ b/java/broker/src/main/java/org/apache/qpid/tools/messagestore/MessageStoreTool.java
@@ -40,6 +40,8 @@ import org.apache.qpid.tools.messagestore.commands.Load;
import org.apache.qpid.tools.messagestore.commands.Quit;
import org.apache.qpid.tools.messagestore.commands.Select;
import org.apache.qpid.tools.messagestore.commands.Show;
+import org.apache.qpid.tools.messagestore.commands.Move;
+import org.apache.qpid.tools.messagestore.commands.Purge;
import org.apache.qpid.tools.utils.CommandParser;
import org.apache.qpid.tools.utils.Console;
import org.apache.qpid.tools.utils.SimpleCommandParser;
@@ -241,6 +243,8 @@ public class MessageStoreTool
_commands.put("help", new Help(this));
_commands.put("list", new List(this));
_commands.put("load", new Load(this));
+ _commands.put("move", new Move(this));
+ _commands.put("purge", new Purge(this));
_commands.put("quit", new Quit(this));
_commands.put("select", new Select(this));
_commands.put("show", new Show(this));
diff --git a/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Copy.java b/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Copy.java
index 96ecb36952..a5b3a87616 100644
--- a/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Copy.java
+++ b/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Copy.java
@@ -21,7 +21,6 @@
package org.apache.qpid.tools.messagestore.commands;
import org.apache.qpid.server.queue.AMQQueue;
-import org.apache.qpid.server.store.StoreContext;
import org.apache.qpid.tools.messagestore.MessageStoreTool;
public class Copy extends Move
@@ -33,9 +32,9 @@ public class Copy extends Move
public String help()
{
- return "Copy messages between queues.\n" +
+ return "Copy messages between queues.";/*\n" +
"The currently selected message set will be copied to the specifed queue.\n" +
- "Alternatively the values can be provided on the command line.";
+ "Alternatively the values can be provided on the command line."; */
}
public String usage()
@@ -48,9 +47,9 @@ public class Copy extends Move
return "copy";
}
- protected void doCommand(AMQQueue fromQueue, long start, long end, AMQQueue toQueue, StoreContext storeContext)
+ protected void doCommand(AMQQueue fromQueue, long start, long end, AMQQueue toQueue)
{
- fromQueue.copyMessagesToAnotherQueue(start, end, toQueue.getName().toString(), storeContext);
+ fromQueue.copyMessagesToAnotherQueue(start, end, toQueue.getName().toString(), _storeContext);
}
}
diff --git a/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Move.java b/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Move.java
index a9497fd23e..25cff27445 100644
--- a/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Move.java
+++ b/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Move.java
@@ -21,10 +21,12 @@
package org.apache.qpid.tools.messagestore.commands;
import org.apache.qpid.framing.AMQShortString;
+import org.apache.qpid.server.queue.AMQMessage;
import org.apache.qpid.server.queue.AMQQueue;
import org.apache.qpid.server.store.StoreContext;
import org.apache.qpid.tools.messagestore.MessageStoreTool;
+import java.util.LinkedList;
import java.util.List;
public class Move extends AbstractCommand
@@ -34,7 +36,7 @@ public class Move extends AbstractCommand
* Since the Coopy command is not associated with a real channel we can safely create our own store context
* for use in the few methods that require one.
*/
- private StoreContext _storeContext = new StoreContext();
+ protected StoreContext _storeContext = new StoreContext();
public Move(MessageStoreTool tool)
{
@@ -43,9 +45,9 @@ public class Move extends AbstractCommand
public String help()
{
- return "Move messages between queues.\n" +
+ return "Move messages between queues.";/*\n" +
"The currently selected message set will be moved to the specifed queue.\n" +
- "Alternatively the values can be provided on the command line.";
+ "Alternatively the values can be provided on the command line.";*/
}
public String usage()
@@ -110,6 +112,17 @@ public class Move extends AbstractCommand
Long previous = null;
Long start = null;
+ if (msgids == null)
+ {
+ msgids = allMessageIDs(fromQueue);
+ }
+
+ if (msgids == null || msgids.size() == 0)
+ {
+ _console.println("No Messages to move.");
+ return;
+ }
+
for (long id : msgids)
{
if (previous != null)
@@ -126,18 +139,44 @@ public class Move extends AbstractCommand
if (start != null)
{
//move a range of ids
- doCommand(fromQueue, start, id, toQueue, _storeContext);
+ doCommand(fromQueue, start, id, toQueue);
+ start = null;
}
else
{
//move a single id
- doCommand(fromQueue, id, id, toQueue, _storeContext);
+ doCommand(fromQueue, id, id, toQueue);
}
}
}
previous = id;
}
+
+ if (start != null)
+ {
+ //move a range of ids
+ doCommand(fromQueue, start, previous, toQueue);
+ }
+ }
+
+ private List<Long> allMessageIDs(AMQQueue fromQueue)
+ {
+ List<Long> ids = new LinkedList<Long>();
+
+ if (fromQueue != null)
+ {
+ List<AMQMessage> messages = fromQueue.getMessagesOnTheQueue();
+ if (messages != null)
+ {
+ for (AMQMessage msg : messages)
+ {
+ ids.add(msg.getMessageId());
+ }
+ }
+ }
+
+ return ids;
}
protected boolean checkRequirements(AMQQueue fromQueue, AMQQueue toQueue, List<Long> msgids)
@@ -159,7 +198,7 @@ public class Move extends AbstractCommand
return true;
}
- protected void doCommand(AMQQueue fromQueue, long start, long id, AMQQueue toQueue, StoreContext storeContext)
+ protected void doCommand(AMQQueue fromQueue, long start, long id, AMQQueue toQueue)
{
fromQueue.moveMessagesToAnotherQueue(start, id, toQueue.getName().toString(), _storeContext);
}
diff --git a/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Purge.java b/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Purge.java
index 7154159b40..f187e26593 100644
--- a/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Purge.java
+++ b/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Purge.java
@@ -61,8 +61,8 @@ public class Purge extends Move
return true;
}
- protected void doCommand(AMQQueue fromQueue, long start, long end, AMQQueue toQueue, StoreContext storeContext)
+ protected void doCommand(AMQQueue fromQueue, long start, long end, AMQQueue toQueue)
{
- fromQueue.removeMessagesFromQueue(start, end, storeContext);
+ fromQueue.removeMessagesFromQueue(start, end, _storeContext);
}
}
diff --git a/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Select.java b/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Select.java
index 5e9b7028e9..fd7d4c3f13 100644
--- a/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Select.java
+++ b/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Select.java
@@ -45,7 +45,7 @@ public class Select extends AbstractCommand
public String usage()
{
- return "select virtualhost <name> |exchange <name> |queue <name> | msgs id=<msgids eg. 1,2,4-10>";
+ return "select virtualhost <name> |exchange <name> |queue <name> | msg id=<msgids eg. 1,2,4-10>";
}
public String getCommand()