diff --git a/jpos/src/main/java/org/jpos/q2/Q2.java b/jpos/src/main/java/org/jpos/q2/Q2.java index 6318160ab9..ce044b83fd 100644 --- a/jpos/src/main/java/org/jpos/q2/Q2.java +++ b/jpos/src/main/java/org/jpos/q2/Q2.java @@ -164,7 +164,32 @@ public class Q2 implements FileFilter, Runnable { private boolean noShutdownHook; private long shutdownHookDelay = 0L; - public Q2 (String[] args) { + /** + * Constructs a new {@code Q2} instance with the specified command-line arguments and class loader. + * This constructor initializes various configurations, processes command-line arguments, + * sets up directories, and registers necessary components for the application. + * + * @param args an array of {@code String} containing the command-line arguments. + * @param classLoader the {@code ClassLoader} to be used by the application. + * If {@code null}, the class loader of the current class is used. + * + *
Key Initialization Steps:
+ *Note: The {@code deployDir} directory is created if it does not already exist.
+ * + * @see #parseCmdLine(String[], boolean) + * @see #registerMicroMeter() + * @see #registerQ2() + */ + public Q2 (String[] args, ClassLoader classLoader) { super(); parseCmdLine (args, true); this.args = environmentArgs(args); @@ -174,13 +199,56 @@ public Q2 (String[] args) { libDir = new File (deployDir, "lib"); dirMap = new TreeMap<>(); deployDir.mkdirs (); - mainClassLoader = getClass().getClassLoader(); + mainClassLoader = classLoader == null ? getClass().getClassLoader() : classLoader; registerMicroMeter(); registerQ2(); } + + /** + * Constructs a new {@code Q2} instance with the specified command-line arguments + * and the default class loader. + * + * @param args an array of {@code String} containing the command-line arguments. + * If no arguments are provided, the application initializes with + * default settings. + * + *This constructor delegates to {@link #Q2(String[], ClassLoader)} with + * a {@code null} class loader, causing the default class loader to be used.
+ * + * @see #Q2(String[], ClassLoader) + */ + public Q2 (String[] args) { + this (args, null); + } + + /** + * Constructs a new {@code Q2} instance with no command-line arguments + * and the default class loader. + * + *This constructor is equivalent to calling {@code Q2(new String[]{})}. + * It initializes the application with default settings.
+ * + * @see #Q2(String[], ClassLoader) + * @see #Q2(String[]) + */ + public Q2 () { this (new String[] {}); } + + /** + * Constructs a new {@code Q2} instance with the specified deployment directory + * and the default class loader. + * + * @param deployDir a {@code String} specifying the path to the deployment directory. + * This is passed as a command-line argument using the {@code -d} option. + * + *This constructor is equivalent to calling {@code Q2(new String[]{"-d", deployDir})}. + * It sets the deployment directory and initializes the application.
+ * + * @see #Q2(String[], ClassLoader) + * @see #Q2(String[]) + */ public Q2 (String deployDir) { this (new String[] { "-d", deployDir }); }