Search in sources :

Example 51 with JCommander

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();
}
Also used : Message(com.yahoo.pulsar.client.api.Message) MessageListener(com.yahoo.pulsar.client.api.MessageListener) Properties(java.util.Properties) DefaultThreadFactory(io.netty.util.concurrent.DefaultThreadFactory) Consumer(com.yahoo.pulsar.client.api.Consumer) JCommander(com.beust.jcommander.JCommander) DestinationName(com.yahoo.pulsar.common.naming.DestinationName) ConsumerConfiguration(com.yahoo.pulsar.client.api.ConsumerConfiguration) ParameterException(com.beust.jcommander.ParameterException) PulsarClient(com.yahoo.pulsar.client.api.PulsarClient) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) FileInputStream(java.io.FileInputStream) RateLimiter(com.google.common.util.concurrent.RateLimiter) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) EventLoopGroup(io.netty.channel.EventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) Future(java.util.concurrent.Future) PulsarClientImpl(com.yahoo.pulsar.client.impl.PulsarClientImpl) ClientConfiguration(com.yahoo.pulsar.client.api.ClientConfiguration)

Example 52 with JCommander

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);
}
Also used : JCommander(com.beust.jcommander.JCommander) RemoteArgs(org.testng.remote.RemoteArgs)

Example 53 with JCommander

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");
    }
}
Also used : ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) JCommander(com.beust.jcommander.JCommander) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue)

Example 54 with JCommander

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();
    }
}
Also used : JCommander(com.beust.jcommander.JCommander) ConnectionFailedException(alluxio.exception.ConnectionFailedException)

Example 55 with JCommander

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");
    }
}
Also used : JCommander(com.beust.jcommander.JCommander) Instant(java.time.Instant) OutputStreamWriter(java.io.OutputStreamWriter) Duration(java.time.Duration) PrintWriter(java.io.PrintWriter)

Aggregations

JCommander (com.beust.jcommander.JCommander)68 ParameterException (com.beust.jcommander.ParameterException)15 IOException (java.io.IOException)10 Map (java.util.Map)6 ParameterDescription (com.beust.jcommander.ParameterDescription)4 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3 Console (com.beust.jcommander.internal.Console)2 DefaultCommand (com.evolveum.midpoint.cli.common.DefaultCommand)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Charsets (com.google.common.base.Charsets)2 Throwables (com.google.common.base.Throwables)2 HostAndPort (com.google.common.net.HostAndPort)2 Service (com.google.common.util.concurrent.Service)2 CreationException (com.google.inject.CreationException)2 SystemException (com.torodb.core.exceptions.SystemException)2 BackendPasswordConfig (com.torodb.packaging.config.model.backend.BackendPasswordConfig)2 AbstractDerby (com.torodb.packaging.config.model.backend.derby.AbstractDerby)2 AbstractPostgres (com.torodb.packaging.config.model.backend.postgres.AbstractPostgres)2 AbstractReplication (com.torodb.packaging.config.model.protocol.mongo.AbstractReplication)2