From 51f3763393377e1832476793a72e5fc9db339ff3 Mon Sep 17 00:00:00 2001 From: Kalin Chan Date: Mon, 23 Sep 2024 11:30:29 +0100 Subject: [PATCH 1/2] Fix whitespaces --- .../jms/blc/EmbeddedBrokerRunner.java | 43 +++++++++++++++++-- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/mq/main/mq-jmsra/jmsra-ra/src/main/java/com/sun/messaging/jms/blc/EmbeddedBrokerRunner.java b/mq/main/mq-jmsra/jmsra-ra/src/main/java/com/sun/messaging/jms/blc/EmbeddedBrokerRunner.java index 3703cbe6c..23a9e3870 100644 --- a/mq/main/mq-jmsra/jmsra-ra/src/main/java/com/sun/messaging/jms/blc/EmbeddedBrokerRunner.java +++ b/mq/main/mq-jmsra/jmsra-ra/src/main/java/com/sun/messaging/jms/blc/EmbeddedBrokerRunner.java @@ -19,6 +19,7 @@ import java.util.Enumeration; import java.util.Properties; +import java.util.Set; import java.util.StringTokenizer; import java.util.Vector; import java.util.logging.Level; @@ -56,6 +57,12 @@ public class EmbeddedBrokerRunner implements BrokerEventListener { protected static final String _lgrMID_ERR = _lgrMIDPrefix + "3001: "; protected static final String _lgrMID_EXC = _lgrMIDPrefix + "4001: "; + private static final Set parameterNames; + + static { + parameterNames = Set.of("-loglevel", "-save", "-shared", "-debug", "-dbuser", "-dbpassword", "-dbpwd", "-diag", "-name", "-port", "-nobind", "-metrics", "-password", "-pwd", "-ldappassword", "-ldappwd", "-read-stdin", "-passfile", "-backup", "-restore", "-cluster", "-force", "-silent", "-s", "-ttyerrors", "-te", "-tty", "-D", "-varhome", "-jmqvarhome", "-imqhome", "-libhome", "-javahome", "-jrehome", "-bgnd", "-init", "-version", "-v", "-ntservice", "-adminkeyfile", "-help", "-h", "-remove", "-reset", "-upgrade-store-nobackup", "-useRmiRegistry", "-startRmiRegistry", "-rmiRegistryPort", "-activateServices"); + } + public EmbeddedBrokerRunner(String brokerInstanceName, String brokerBindAddress, int brokerPort, String brokerHomeDir, String brokerLibDir, String brokerVarDir, String brokerJavaDir, String brokerExtraArgs, boolean useJNDIRMIServiceURL, int rmiRegistryPort, boolean startRMIRegistry, boolean useSSLJMXConnector, boolean doBind, Properties sysProps) @@ -167,9 +174,13 @@ private String[] assembleBrokerArgs(String brokerInstanceName, int brokerPort, S // Add extra args first; explicit config will override args if (brokerExtraArgs != null && !("".equals(brokerExtraArgs))) { StringTokenizer st = new StringTokenizer(brokerExtraArgs, " "); - while (st.hasMoreTokens()) { - String t = st.nextToken(); - v.add(t); + if (st.countTokens() > 2) { + processBrokerExtraArgs(st, v); + } else { + while (st.hasMoreTokens()) { + String t = st.nextToken(); + v.add(t); + } } } @@ -225,6 +236,32 @@ private String[] assembleBrokerArgs(String brokerInstanceName, int brokerPort, S return brokerArgs; } + /** + * This method separates the parameter names from the values considering blank spaces + * + * @param st StringTokenizer containing the available tokens + * @param v Reference of the Vector object to save the parameter and the value in consecutive order + */ + private static void processBrokerExtraArgs(StringTokenizer st, Vector v) { + StringBuilder builderValue = new StringBuilder(); + while (st.hasMoreTokens()) { + String s = st.nextToken(); + if (parameterNames.contains(s)) { + if (!builderValue.isEmpty()) { + v.add(builderValue.toString()); + builderValue.delete(0, builderValue.length()); + } + v.add(s); + continue; + } + builderValue.append(s + " "); + } + + if (!builderValue.isEmpty()) { + v.add(builderValue.toString()); + } + } + /** * Create the in-JVM broker instance * From e55a0d6141f5ee05c1c1069d88a3354eddd1a773 Mon Sep 17 00:00:00 2001 From: Kalin Chan Date: Thu, 3 Oct 2024 12:38:41 +0100 Subject: [PATCH 2/2] Review comments --- .../jms/blc/EmbeddedBrokerRunner.java | 44 ++++++++++++++----- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/mq/main/mq-jmsra/jmsra-ra/src/main/java/com/sun/messaging/jms/blc/EmbeddedBrokerRunner.java b/mq/main/mq-jmsra/jmsra-ra/src/main/java/com/sun/messaging/jms/blc/EmbeddedBrokerRunner.java index 23a9e3870..08f9a1774 100644 --- a/mq/main/mq-jmsra/jmsra-ra/src/main/java/com/sun/messaging/jms/blc/EmbeddedBrokerRunner.java +++ b/mq/main/mq-jmsra/jmsra-ra/src/main/java/com/sun/messaging/jms/blc/EmbeddedBrokerRunner.java @@ -57,11 +57,30 @@ public class EmbeddedBrokerRunner implements BrokerEventListener { protected static final String _lgrMID_ERR = _lgrMIDPrefix + "3001: "; protected static final String _lgrMID_EXC = _lgrMIDPrefix + "4001: "; - private static final Set parameterNames; - - static { - parameterNames = Set.of("-loglevel", "-save", "-shared", "-debug", "-dbuser", "-dbpassword", "-dbpwd", "-diag", "-name", "-port", "-nobind", "-metrics", "-password", "-pwd", "-ldappassword", "-ldappwd", "-read-stdin", "-passfile", "-backup", "-restore", "-cluster", "-force", "-silent", "-s", "-ttyerrors", "-te", "-tty", "-D", "-varhome", "-jmqvarhome", "-imqhome", "-libhome", "-javahome", "-jrehome", "-bgnd", "-init", "-version", "-v", "-ntservice", "-adminkeyfile", "-help", "-h", "-remove", "-reset", "-upgrade-store-nobackup", "-useRmiRegistry", "-startRmiRegistry", "-rmiRegistryPort", "-activateServices"); - } + private static final Set PARAMETER_NAMES = Set.of( + "-debug", + "-dbuser", + "-dbpassword", + "-dbpwd", + "-name", + "-nobind", + "-password", + "-pwd", + "-ldappassword", + "-ldappwd", + "-passfile", + "-backup", + "-restore", + "-cluster", + "-varhome", + "-jmqvarhome", + "-imqhome", + "-libhome", + "-javahome", + "-jrehome", + "-adminkeyfile", + "-reset", + "-activateServices"); public EmbeddedBrokerRunner(String brokerInstanceName, String brokerBindAddress, int brokerPort, String brokerHomeDir, String brokerLibDir, String brokerVarDir, String brokerJavaDir, String brokerExtraArgs, boolean useJNDIRMIServiceURL, int rmiRegistryPort, @@ -163,7 +182,7 @@ private void logSysPropsInbrokerLog(Properties props) { /** * Assemble a String[] of broker arguments corresponding to the supplied method arguments - * + * * @return The String[] of broker arguments */ private String[] assembleBrokerArgs(String brokerInstanceName, int brokerPort, String brokerHomeDir, String brokerLibDir, String brokerVarDir, @@ -246,7 +265,7 @@ private static void processBrokerExtraArgs(StringTokenizer st, Vector v) StringBuilder builderValue = new StringBuilder(); while (st.hasMoreTokens()) { String s = st.nextToken(); - if (parameterNames.contains(s)) { + if (PARAMETER_NAMES.contains(s)) { if (!builderValue.isEmpty()) { v.add(builderValue.toString()); builderValue.delete(0, builderValue.length()); @@ -254,7 +273,10 @@ private static void processBrokerExtraArgs(StringTokenizer st, Vector v) v.add(s); continue; } - builderValue.append(s + " "); + builderValue.append(s); + if (st.hasMoreTokens()){ + builderValue.append(" "); + } } if (!builderValue.isEmpty()) { @@ -264,7 +286,7 @@ private static void processBrokerExtraArgs(StringTokenizer st, Vector v) /** * Create the in-JVM broker instance - * + * * Requires field: brokerType Sets fields: directBroker */ private void createTheInVMBrokerInstance() throws ClassNotFoundException, IllegalAccessException, InstantiationException { @@ -289,9 +311,9 @@ private void createTheInVMBrokerInstance() throws ClassNotFoundException, Illega /** * Parse the supplied broker arguments and convert them into a Properties object - * + * * Requires fields: brokerType, apiDirectBroker or raDirectBroker - * + * * @param brokerArgs the supplied broker arguments * @return a Properties object corresponding to the supplied arguments */