"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "voter/src/main/java/org/terracotta/voter/TCVoterMain.java" between
terracotta-core-5.7.0.tar.gz and terracotta-core-5.7.1.tar.gz

About: Terracotta - Clustering technology for Java ("Network Attached Memory", "Distributed Cache"). Source code of the server (5.x) core components.

TCVoterMain.java  (terracotta-core-5.7.0):TCVoterMain.java  (terracotta-core-5.7.1)
skipping to change at line 34 skipping to change at line 34
import org.apache.commons.cli.Option; import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options; import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException; import org.apache.commons.cli.ParseException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.tc.config.schema.setup.ConfigurationSetupException; import com.tc.config.schema.setup.ConfigurationSetupException;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.util.Properties; import java.util.Properties;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import static org.terracotta.voter.TCVoterMain.Opt.HELP;
import static org.terracotta.voter.TCVoterMain.Opt.OVERRIDE;
import static org.terracotta.voter.TCVoterMain.Opt.SERVER;
public class TCVoterMain { public class TCVoterMain {
private static final Logger LOGGER = LoggerFactory.getLogger(TCVoterMain.class ); private static final Logger LOGGER = LoggerFactory.getLogger(TCVoterMain.class );
private static final String HELP = "h"; enum Opt {
private static final String OVERRIDE = "o"; HELP("h", "help"),
protected static final String SERVER = "s"; OVERRIDE("o", "override"),
SERVER("s", "server");
String shortName;
String longName;
Opt(String shortName, String longName) {
Objects.requireNonNull(shortName);
Objects.requireNonNull(longName);
this.shortName = shortName;
this.longName = longName;
}
public String getShortName() {
return shortName;
}
public String getLongName() {
return longName;
}
}
private static final String ID = UUID.randomUUID().toString(); private static final String ID = UUID.randomUUID().toString();
public void processArgs(String[] args) throws ConfigurationSetupException, Par seException { public void processArgs(String[] args) throws ConfigurationSetupException, Par seException {
DefaultParser parser = new DefaultParser(); DefaultParser parser = new DefaultParser();
Options voterOptions = voterOptions(); Options voterOptions = voterOptions();
CommandLine commandLine = parser.parse(voterOptions, args); CommandLine commandLine = parser.parse(voterOptions, args);
if (commandLine.getArgList().size() > 0) { if (commandLine.getArgList().size() > 0) {
throw new ConfigurationSetupException("Invalid arguments provided: " + com mandLine.getArgList()); throw new ConfigurationSetupException("Invalid arguments provided: " + com mandLine.getArgList());
} }
if (commandLine.hasOption(HELP)) { if (commandLine.hasOption(HELP.getShortName())) {
new HelpFormatter().printHelp("start-voter.sh[bat]", voterOptions); Options options = createHelpOptions();
HelpFormatter helpFormatter = new HelpFormatter();
helpFormatter.printHelp("start-voter.sh[bat]", options);
return; return;
} }
if (commandLine.getOptions().length == 0) { if (commandLine.getOptions().length == 0) {
throw new ConfigurationSetupException("Neither the override option -o nor the regular options -s provided"); throw new ConfigurationSetupException("Neither the override option -o nor the regular options -s provided");
} }
Optional<Properties> connectionProps = getConnectionProperties(commandLine); Optional<Properties> connectionProps = getConnectionProperties(commandLine);
if (commandLine.hasOption(SERVER)) { if (commandLine.hasOption(SERVER.getShortName())) {
processServerArg(connectionProps, commandLine.getOptionValues(SERVER)); processServerArg(connectionProps, commandLine.getOptionValues(SERVER.getSh
} else if (commandLine.hasOption(OVERRIDE)) { ortName()));
String hostPort = commandLine.getOptionValue(OVERRIDE); } else if (commandLine.hasOption(OVERRIDE.getShortName())) {
String hostPort = commandLine.getOptionValue(OVERRIDE.getShortName());
validateHostPort(hostPort); validateHostPort(hostPort);
getVoter(connectionProps).overrideVote(hostPort); getVoter(connectionProps).overrideVote(hostPort);
} else { } else {
throw new AssertionError("This should not happen"); throw new AssertionError("This should not happen");
} }
} }
protected Options createHelpOptions() {
// creating new options with long name just for display purposes.
Options helpOptions = new Options()
.addOption(Option.builder(HELP.getLongName()).desc("Help").hasArg(false)
.build())
.addOption(Option.builder(OVERRIDE.getLongName()).desc("Override vote").
hasArg().argName("host:port").build())
.addOption(Option.builder(SERVER.getLongName()).desc("Server host:port")
.hasArgs().argName("host:port[,host:port...]").valueSeparator().build());
return helpOptions;
}
protected Optional<Properties> getConnectionProperties(CommandLine commandLine ) { protected Optional<Properties> getConnectionProperties(CommandLine commandLine ) {
return Optional.empty(); return Optional.empty();
} }
protected void processServerArg(Optional<Properties> connectionProps, String[] stripes) throws ConfigurationSetupException { protected void processServerArg(Optional<Properties> connectionProps, String[] stripes) throws ConfigurationSetupException {
validateStripesLimit(SERVER, stripes); validateStripesLimit(SERVER.getShortName(), stripes);
String[] hostPorts = stripes[0].split(","); String[] hostPorts = stripes[0].split(",");
for (String hostPort : hostPorts) { for (String hostPort : hostPorts) {
validateHostPort(hostPort); validateHostPort(hostPort);
} }
startVoter(connectionProps, hostPorts); startVoter(connectionProps, hostPorts);
} }
protected TCVoter getVoter(Optional<Properties> connectionProps) { protected TCVoter getVoter(Optional<Properties> connectionProps) {
return new TCVoterImpl(); return new TCVoterImpl();
} }
skipping to change at line 108 skipping to change at line 144
} }
protected void validateStripesLimit(String option, String[] args) throws Confi gurationSetupException { protected void validateStripesLimit(String option, String[] args) throws Confi gurationSetupException {
if (args.length > 1) { if (args.length > 1) {
throw new ConfigurationSetupException("Usage of multiple -" + option + " o ptions not supported"); throw new ConfigurationSetupException("Usage of multiple -" + option + " o ptions not supported");
} }
} }
protected Options voterOptions() { protected Options voterOptions() {
return new Options() return new Options()
.addOption(Option.builder(HELP).desc("Help").hasArg(false).build()) .addOption(Option.builder(HELP.getShortName()).longOpt(HELP.getLongName(
.addOption(Option.builder(OVERRIDE).desc("Override vote").hasArg().argNa )).desc("Help").hasArg(false).build())
me("host:port").build()) .addOption(Option.builder(OVERRIDE.getShortName()).longOpt(OVERRIDE.getL
.addOption(Option.builder(SERVER).desc("Server host:port").hasArgs().arg ongName()).desc("Override vote").hasArg().argName("host:port").build())
Name("host:port[,host:port...]").valueSeparator().build()); .addOption(Option.builder(SERVER.getShortName()).longOpt(SERVER.getLongN
ame()).desc("Server host:port").hasArgs().argName("host:port[,host:port...]").va
lueSeparator().build());
} }
protected void validateHostPort(String hostPort) throws ConfigurationSetupExce ption { protected void validateHostPort(String hostPort) throws ConfigurationSetupExce ption {
URI uri; URI uri;
try { try {
uri = new URI("tc://" + hostPort); uri = new URI("tc://" + hostPort);
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
throw new ConfigurationSetupException(e); throw new ConfigurationSetupException(e);
} }
 End of changes. 8 change blocks. 
15 lines changed or deleted 57 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)