Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added lots of javadoc #1628

Draft
wants to merge 12 commits into
base: develop
Choose a base branch
from
22 changes: 19 additions & 3 deletions src/main/java/net/openhft/chronicle/queue/BufferMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,26 @@

package net.openhft.chronicle.queue;

/**
* Enum representing the different buffer modes that can be used within Chronicle Queue.
* Each mode has a specific use case and behavior depending on the configuration.
*/
public enum BufferMode {
None, // The default
/**
* The default buffer mode.
* No additional buffering or special handling is applied.
*/
None, // Default mode, no buffering
peter-lawrey marked this conversation as resolved.
Show resolved Hide resolved

Copy, // used in conjunction with encryption
/**
* Buffer mode used in conjunction with encryption.
* Data is copied into a buffer before being processed.
*/
Copy, // Used when encryption is enabled to handle buffered copies

Asynchronous // used by chronicle-ring [ which is an enterprise product ]
/**
* Buffer mode used for asynchronous processing.
* This mode is specific to Chronicle Ring, an enterprise product.
*/
Asynchronous // Asynchronous buffering used by Chronicle Ring (enterprise feature)
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,44 +19,68 @@
package net.openhft.chronicle.queue;

import net.openhft.chronicle.queue.reader.ChronicleHistoryReader;
import net.openhft.chronicle.wire.MessageHistory;
import org.apache.commons.cli.*;
import org.jetbrains.annotations.NotNull;

import java.io.PrintWriter;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

/**
* Reads @see MessageHistory from a chronicle and outputs histograms for
* The main class for reading {@link MessageHistory} from a Chronicle queue
* and generating histograms for:
* <ul>
* <li>latencies for each component that has processed a message</li>
* <li>latencies between each component that has processed a message</li>
* <li>Latencies for each component that has processed a message</li>
* <li>Latencies between each component that has processed a message</li>
* </ul>
*
* @author Jerry Shea
* This class provides options to configure the reader via command line arguments and outputs the results
* to the console.
*/
public class ChronicleHistoryReaderMain {

/**
* Entry point of the application.
* Initializes the {@link ChronicleHistoryReaderMain} and passes command-line arguments.
*
* @param args Command-line arguments
*/
public static void main(@NotNull String[] args) {
new ChronicleHistoryReaderMain().run(args);
}

/**
* Runs the ChronicleHistoryReader setup and execution.
* Parses command-line options and configures the {@link ChronicleHistoryReader}.
*
* @param args Command-line arguments
*/
protected void run(String[] args) {
final Options options = options();
final CommandLine commandLine = parseCommandLine(args, options);
final Options options = options(); // Initialize command line options
final CommandLine commandLine = parseCommandLine(args, options); // Parse command line arguments

try (final ChronicleHistoryReader chronicleHistoryReader = chronicleHistoryReader()) {
// Setup and execute the history reader
setup(commandLine, chronicleHistoryReader);
chronicleHistoryReader.execute();
}
}

/**
* Configures the {@link ChronicleHistoryReader} based on the command-line options.
*
* @param commandLine Parsed command-line options
* @param chronicleHistoryReader The history reader to configure
*/
protected void setup(@NotNull final CommandLine commandLine, @NotNull final ChronicleHistoryReader chronicleHistoryReader) {
chronicleHistoryReader.
withMessageSink(System.out::println).
withProgress(commandLine.hasOption('p')).
withHistosByMethod(commandLine.hasOption('m')).
withBasePath(Paths.get(commandLine.getOptionValue('d')));
// Set message sink to output to System.out
chronicleHistoryReader.withMessageSink(System.out::println)
.withProgress(commandLine.hasOption('p')) // Enable progress if '-p' is specified
.withHistosByMethod(commandLine.hasOption('m')) // Enable histograms by method if '-m' is specified
.withBasePath(Paths.get(commandLine.getOptionValue('d'))); // Set base path from the directory option

// Optionally configure time unit, items to ignore, window duration, and summary output
if (commandLine.hasOption('t'))
chronicleHistoryReader.withTimeUnit(TimeUnit.valueOf(commandLine.getOptionValue('t')));
if (commandLine.hasOption('i'))
Expand All @@ -67,36 +91,66 @@ protected void setup(@NotNull final CommandLine commandLine, @NotNull final Chro
chronicleHistoryReader.withSummaryOutput(Integer.parseInt(commandLine.getOptionValue('u')));
}

/**
* Initializes a new instance of {@link ChronicleHistoryReader}.
*
* @return A new {@link ChronicleHistoryReader} instance
*/
@NotNull
protected ChronicleHistoryReader chronicleHistoryReader() {
return new ChronicleHistoryReader();
}

/**
* Parses command-line arguments using Apache Commons CLI.
* If help is requested, it prints the help message and exits.
*
* @param args Command-line arguments
* @param options Available command-line options
* @return Parsed {@link CommandLine} object
*/
protected CommandLine parseCommandLine(@NotNull final String[] args, final Options options) {
final CommandLineParser parser = new DefaultParser();
final CommandLineParser parser = new DefaultParser(); // Initialize command-line parser
CommandLine commandLine = null;

try {
commandLine = parser.parse(options, args);
commandLine = parser.parse(options, args); // Parse arguments

// If help option is selected, print help and exit
if (commandLine.hasOption('h')) {
printHelpAndExit(options, 0);
}
} catch (ParseException e) {
printHelpAndExit(options, 1, e.getMessage());
// If parsing fails, print help with an error message and exit
String cmdLine = Arrays.toString(args);
printHelpAndExit(options, "[-h]".equals(cmdLine) ? 0 : 1, e.getMessage());
}

return commandLine;
}

/**
* Prints help and exits the program.
*
* @param options Command-line options
* @param status Exit status
*/
protected void printHelpAndExit(final Options options, int status) {
printHelpAndExit(options, status, null);
}

/**
* Prints help and exits the program, optionally with a message.
*
* @param options Command-line options
* @param status Exit status
* @param message Optional message to print before help
*/
protected void printHelpAndExit(final Options options, int status, String message) {
final PrintWriter writer = new PrintWriter(System.out);
new HelpFormatter().printHelp(
writer,
180,
180, // Line width for formatting help output
peter-lawrey marked this conversation as resolved.
Show resolved Hide resolved
this.getClass().getSimpleName(),
message,
options,
Expand All @@ -105,21 +159,26 @@ protected void printHelpAndExit(final Options options, int status, String messag
null,
true
);
writer.flush();
System.exit(status);
writer.flush(); // Ensure everything is printed
System.exit(status); // Exit with provided status
peter-lawrey marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Configures command-line options for the ChronicleHistoryReaderMain.
*
* @return Configured {@link Options} object
*/
@NotNull
protected Options options() {
final Options options = new Options();
final Options options = new Options(); // Initialize options
ChronicleReaderMain.addOption(options, "d", "directory", true, "Directory containing chronicle queue files", true);
ChronicleReaderMain.addOption(options, "h", "help-message", false, "Print this help and exit", false);
ChronicleReaderMain.addOption(options, "t", "time unit", true, "Time unit. Default nanos", false);
ChronicleReaderMain.addOption(options, "i", "ignore", true, "How many items to ignore from start", false);
ChronicleReaderMain.addOption(options, "w", "window", true, "Window duration in time unit. Instead of one output at the end, will output every window period", false);
ChronicleReaderMain.addOption(options, "u", "histo offset", true, "Summary output. Instead of histograms, will show one value only, in CSV format. Set this to 0 for 50th, 1 for 90th etc., -1 for worst", false);
options.addOption(new Option("p", false, "Show progress"));
options.addOption(new Option("m", false, "By method"));
options.addOption(new Option("p", false, "Show progress")); // Add 'p' option for showing progress
options.addOption(new Option("m", false, "By method")); // Add 'm' option for histogram by method
return options;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.openhft.chronicle.queue;

import net.openhft.chronicle.core.io.Closeable;
Expand Down
Loading