use of com.beust.jcommander.JCommander in project pulsar by yahoo.
the class PerformanceConsumer method main.
public static void main(String[] args) throws Exception {
final Arguments arguments = new Arguments();
JCommander jc = new JCommander(arguments);
jc.setProgramName("pulsar-perf-consumer");
try {
jc.parse(args);
} catch (ParameterException e) {
System.out.println(e.getMessage());
jc.usage();
System.exit(-1);
}
if (arguments.help) {
jc.usage();
System.exit(-1);
}
if (arguments.topic.size() != 1) {
System.out.println("Only one destination name is allowed");
jc.usage();
System.exit(-1);
}
if (arguments.confFile != null) {
Properties prop = new Properties(System.getProperties());
prop.load(new FileInputStream(arguments.confFile));
if (arguments.serviceURL == null) {
arguments.serviceURL = prop.getProperty("brokerServiceUrl");
}
if (arguments.serviceURL == null) {
arguments.serviceURL = prop.getProperty("webServiceUrl");
}
// fallback to previous-version serviceUrl property to maintain backward-compatibility
if (arguments.serviceURL == null) {
arguments.serviceURL = prop.getProperty("serviceUrl", "http://localhost:8080/");
}
if (arguments.authPluginClassName == null) {
arguments.authPluginClassName = prop.getProperty("authPlugin", null);
}
if (arguments.authParams == null) {
arguments.authParams = prop.getProperty("authParams", null);
}
}
// Dump config variables
ObjectMapper m = new ObjectMapper();
ObjectWriter w = m.writerWithDefaultPrettyPrinter();
log.info("Starting Pulsar performance consumer with config: {}", w.writeValueAsString(arguments));
final DestinationName prefixDestinationName = DestinationName.get(arguments.topic.get(0));
final RateLimiter limiter = arguments.rate > 0 ? RateLimiter.create(arguments.rate) : null;
MessageListener listener = new MessageListener() {
public void received(Consumer consumer, Message msg) {
messagesReceived.increment();
bytesReceived.add(msg.getData().length);
if (limiter != null) {
limiter.acquire();
}
consumer.acknowledgeAsync(msg);
}
};
EventLoopGroup eventLoopGroup;
if (SystemUtils.IS_OS_LINUX) {
eventLoopGroup = new EpollEventLoopGroup(Runtime.getRuntime().availableProcessors() * 2, new DefaultThreadFactory("pulsar-perf-consumer"));
} else {
eventLoopGroup = new NioEventLoopGroup(Runtime.getRuntime().availableProcessors(), new DefaultThreadFactory("pulsar-perf-consumer"));
}
ClientConfiguration clientConf = new ClientConfiguration();
clientConf.setConnectionsPerBroker(arguments.maxConnections);
clientConf.setStatsInterval(arguments.statsIntervalSeconds, TimeUnit.SECONDS);
if (isNotBlank(arguments.authPluginClassName)) {
clientConf.setAuthentication(arguments.authPluginClassName, arguments.authParams);
}
PulsarClient pulsarClient = new PulsarClientImpl(arguments.serviceURL, clientConf, eventLoopGroup);
List<Future<Consumer>> futures = Lists.newArrayList();
ConsumerConfiguration consumerConfig = new ConsumerConfiguration();
consumerConfig.setMessageListener(listener);
consumerConfig.setReceiverQueueSize(arguments.receiverQueueSize);
for (int i = 0; i < arguments.numDestinations; i++) {
final DestinationName destinationName = (arguments.numDestinations == 1) ? prefixDestinationName : DestinationName.get(String.format("%s-%d", prefixDestinationName, i));
log.info("Adding {} consumers on destination {}", arguments.numConsumers, destinationName);
for (int j = 0; j < arguments.numConsumers; j++) {
String subscriberName;
if (arguments.numConsumers > 1) {
subscriberName = String.format("%s-%d", arguments.subscriberName, j);
} else {
subscriberName = arguments.subscriberName;
}
futures.add(pulsarClient.subscribeAsync(destinationName.toString(), subscriberName, consumerConfig));
}
}
for (Future<Consumer> future : futures) {
future.get();
}
log.info("Start receiving from {} consumers on {} destinations", arguments.numConsumers, arguments.numDestinations);
long oldTime = System.nanoTime();
while (true) {
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
break;
}
long now = System.nanoTime();
double elapsed = (now - oldTime) / 1e9;
double rate = messagesReceived.sumThenReset() / elapsed;
double throughput = bytesReceived.sumThenReset() / elapsed * 8 / 1024 / 1024;
log.info("Throughput received: {} msg/s -- {} Mbit/s", dec.format(rate), dec.format(throughput));
oldTime = now;
}
pulsarClient.close();
}
use of com.beust.jcommander.JCommander in project intellij-community by JetBrains.
the class TestNGForkedStarter method main.
public static void main(String[] args) throws Exception {
final IDEARemoteTestNG testNG = new IDEARemoteTestNG(null);
CommandLineArgs cla = new CommandLineArgs();
RemoteArgs ra = new RemoteArgs();
new JCommander(Arrays.asList(cla, ra), args);
testNG.configure(cla);
testNG.run();
System.exit(0);
}
use of com.beust.jcommander.JCommander in project zxing by zxing.
the class CommandLineRunner method main.
public static void main(String[] args) throws Exception {
DecoderConfig config = new DecoderConfig();
JCommander jCommander = new JCommander(config, args);
jCommander.setProgramName(CommandLineRunner.class.getSimpleName());
if (config.help) {
jCommander.usage();
return;
}
List<URI> inputs = new ArrayList<>(config.inputPaths.size());
for (String inputPath : config.inputPaths) {
URI uri;
try {
uri = new URI(inputPath);
} catch (URISyntaxException use) {
// Assume it must be a file
if (!Files.exists(Paths.get(inputPath))) {
throw use;
}
uri = new URI("file", inputPath, null);
}
inputs.add(uri);
}
do {
inputs = retainValid(expand(inputs), config.recursive);
} while (config.recursive && isExpandable(inputs));
int numInputs = inputs.size();
if (numInputs == 0) {
jCommander.usage();
return;
}
Queue<URI> syncInputs = new ConcurrentLinkedQueue<>(inputs);
int numThreads = Math.min(numInputs, Runtime.getRuntime().availableProcessors());
int successful = 0;
if (numThreads > 1) {
ExecutorService executor = Executors.newFixedThreadPool(numThreads);
Collection<Future<Integer>> futures = new ArrayList<>(numThreads);
for (int x = 0; x < numThreads; x++) {
futures.add(executor.submit(new DecodeWorker(config, syncInputs)));
}
executor.shutdown();
for (Future<Integer> future : futures) {
successful += future.get();
}
} else {
successful += new DecodeWorker(config, syncInputs).call();
}
if (!config.brief && numInputs > 1) {
System.out.println("\nDecoded " + successful + " files out of " + numInputs + " successfully (" + (successful * 100 / numInputs) + "%)\n");
}
}
use of com.beust.jcommander.JCommander in project alluxio by Alluxio.
the class AlluxioFrameworkIntegrationTest method main.
/**
* @param args arguments
* @throws Exception if an exception occurs
*/
public static void main(String[] args) throws Exception {
AlluxioFrameworkIntegrationTest test = new AlluxioFrameworkIntegrationTest();
JCommander jc = new JCommander(test);
jc.setProgramName(AlluxioFrameworkIntegrationTest.class.getName());
try {
jc.parse(args);
} catch (Exception e) {
LOG.error(e.getMessage());
jc.usage();
System.exit(1);
}
if (test.mHelp) {
jc.usage();
} else {
test.run();
}
}
use of com.beust.jcommander.JCommander in project VocabHunter by VocabHunter.
the class VocabHunterConsoleExecutable method main.
public static void main(final String... args) {
try {
Instant start = Instant.now();
VocabHunterConsoleArguments bean = new VocabHunterConsoleArguments();
JCommander jCommander = JCommander.newBuilder().addObject(bean).build();
jCommander.parse(args);
if (bean.isHelpRequested()) {
StringBuilder buffer = new StringBuilder(HELP_BUFFER_SIZE);
jCommander.usage(buffer);
LOG.info("{}", buffer);
} else {
String output = bean.getOutput();
if (output == null) {
processInput(bean, new PrintWriter(new OutputStreamWriter(System.out, CoreConstants.CHARSET), true));
} else {
try (PrintWriter out = new PrintWriter(Files.newBufferedWriter(Paths.get(output)))) {
processInput(bean, out);
}
}
Instant end = Instant.now();
Duration duration = Duration.between(start, end);
LOG.info("\nExecution time: {}ms", duration.toMillis());
}
} catch (final Exception e) {
LOG.error("Application error", e);
LOG.error("Use -help to show the command-line options");
}
}
Aggregations