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

Fix whitespaces #2109

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> parameterNames;
pzygielo marked this conversation as resolved.
Show resolved Hide resolved

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");
pzygielo marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think all parameters listed here are required, for example -debug or -port - do they support values with spaces?

Copy link
Author

@kalinchan kalinchan Oct 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe I removed the right parameters.

}

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)
Expand Down Expand Up @@ -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);
}
}
}

Expand Down Expand Up @@ -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<String> 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 + " ");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With that, I'm getting trailing space in final element that was not present in the input.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be resolved

}

if (!builderValue.isEmpty()) {
v.add(builderValue.toString());
}
}

/**
* Create the in-JVM broker instance
*
Expand Down
Loading