From 33b81c91a6139f2cea0810183313a3bd68165c17 Mon Sep 17 00:00:00 2001 From: Clebert Suconic Date: Fri, 26 Jun 2015 13:16:09 -0400 Subject: [PATCH] ARTEMIS-145 moving compact command under tools https://issues.apache.org/jira/browse/ARTEMIS-145 --- .../apache/activemq/artemis/cli/Artemis.java | 6 ++- .../cli/commands/tools}/CompactJournal.java | 40 +++++++++---------- .../core/journal/impl/JournalImpl.java | 2 +- 3 files changed, 24 insertions(+), 24 deletions(-) rename {artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl => artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools}/CompactJournal.java (59%) diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/Artemis.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/Artemis.java index 1f4710e4c1..1b09ea46df 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/Artemis.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/Artemis.java @@ -31,6 +31,7 @@ import org.apache.activemq.artemis.cli.commands.Kill; import org.apache.activemq.artemis.cli.commands.Producer; import org.apache.activemq.artemis.cli.commands.Run; import org.apache.activemq.artemis.cli.commands.Stop; +import org.apache.activemq.artemis.cli.commands.tools.CompactJournal; import org.apache.activemq.artemis.cli.commands.tools.DecodeJournal; import org.apache.activemq.artemis.cli.commands.tools.EncodeJournal; import org.apache.activemq.artemis.cli.commands.tools.HelpData; @@ -101,9 +102,10 @@ public class Artemis builder.withGroup("data") - .withDescription("data tools group (print|exp|imp|exp|encode|decode) (example ./artemis data print)"). + .withDescription("data tools group (print|exp|imp|exp|encode|decode|compact) (example ./artemis data print)"). withDefaultCommand(HelpData.class).withCommands(PrintData.class, XmlDataExporter.class, - XmlDataImporter.class, DecodeJournal.class, EncodeJournal.class); + XmlDataImporter.class, DecodeJournal.class, EncodeJournal.class, + CompactJournal.class); if (instance != null) { diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/CompactJournal.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/CompactJournal.java similarity index 59% rename from artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/CompactJournal.java rename to artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/CompactJournal.java index 6f5b75c929..0239998984 100644 --- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/CompactJournal.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/CompactJournal.java @@ -14,42 +14,40 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.activemq.artemis.core.journal.impl; +package org.apache.activemq.artemis.cli.commands.tools; import java.io.File; +import io.airlift.airline.Command; +import org.apache.activemq.artemis.cli.commands.Action; +import org.apache.activemq.artemis.cli.commands.ActionContext; +import org.apache.activemq.artemis.core.config.Configuration; import org.apache.activemq.artemis.core.journal.IOCriticalErrorListener; +import org.apache.activemq.artemis.core.journal.impl.JournalImpl; +import org.apache.activemq.artemis.core.journal.impl.NIOSequentialFileFactory; -/** - * This is an undocumented class, that will open a journal and force compacting on it. - *

- * It may be used under special cases, but it shouldn't be needed under regular circumstances as the - * system should detect the need for compacting. The regular use is to configure min-compact - * parameters. - */ -public final class CompactJournal // NO_UCD +@Command(name = "compact", description = "Compacts the journal of a non running server") +public final class CompactJournal extends DataAbstract implements Action { - - public static void main(final String[] arg) + @Override + public Object execute(ActionContext context) throws Exception { - if (arg.length != 4) - { - System.err.println("Use: java -cp activemq-core.jar org.apache.activemq.artemis.core.journal.impl.CompactJournal "); - return; - } - + super.execute(context); try { - CompactJournal.compactJournal(new File(arg[0]), arg[1], arg[2], 2, Integer.parseInt(arg[3]), null); + Configuration configuration = getFileConfiguration(); + compactJournal(new File(getJournal()), "activemq-data", "amq", configuration.getJournalMinFiles(), configuration.getJournalFileSize(), null); + compactJournal(new File(getBinding()), "activemq-bindings", "bindings", 2, 1048576, null); } catch (Exception e) { - e.printStackTrace(); + treatError(e, "data", "compact"); } - + return null; } - static void compactJournal(final File directory, + + void compactJournal(final File directory, final String journalPrefix, final String journalSuffix, final int minFiles, diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalImpl.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalImpl.java index f394202e4d..6f411ebf00 100644 --- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalImpl.java +++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalImpl.java @@ -1459,7 +1459,7 @@ public class JournalImpl extends JournalBase implements TestableJournal, Journal * Note: only synchronized methods on journal are methods responsible for the life-cycle such as * stop, start records will still come as this is being executed */ - protected synchronized void compact() throws Exception + public synchronized void compact() throws Exception { if (compactor != null) {