Java Code Examples for org.apache.commons.cli.Options#addRequiredOption()

The following examples show how to use org.apache.commons.cli.Options#addRequiredOption() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ModelImpl.java    From SmoothNLP with GNU General Public License v3.0 6 votes vote down vote up
public boolean open(String[] args) {
    CommandLineParser parser = new DefaultParser();
    Options options = new Options();
    options.addRequiredOption("m", "model", true, "set FILE for model file");
    options.addOption("n", "nbest", true, "output n-best results");
    options.addOption("v", "verbose", true, "set INT for verbose level");
    options.addOption("c", "cost-factor", true, "set cost factor");

    CommandLine cmd;
    try {
        cmd = parser.parse(options, args);
    } catch(ParseException e) {
        System.err.println("invalid arguments");
        return false;
    }
    String model = cmd.getOptionValue("m");
    int nbest = Integer.valueOf(cmd.getOptionValue("n", "0"));
    int vlevel = Integer.valueOf(cmd.getOptionValue("v", "0"));
    double costFactor = Double.valueOf(cmd.getOptionValue("c", "1.0"));
    return open(model, nbest, vlevel, costFactor);
}
 
Example 2
Source File: DemoActorService.java    From java-sdk with MIT License 6 votes vote down vote up
/**
 * The main method of this app.
 * @param args The port the app will listen on.
 * @throws Exception An Exception.
 */
public static void main(String[] args) throws Exception {
  Options options = new Options();
  options.addRequiredOption("p", "port", true, "Port the will listen to.");

  CommandLineParser parser = new DefaultParser();
  CommandLine cmd = parser.parse(options, args);

  // If port string is not valid, it will throw an exception.
  final int port = Integer.parseInt(cmd.getOptionValue("port"));

  // Idle timeout until actor instance is deactivated.
  ActorRuntime.getInstance().getConfig().setActorIdleTimeout(Duration.ofSeconds(30));
  // How often actor instances are scanned for deactivation and balance.
  ActorRuntime.getInstance().getConfig().setActorScanInterval(Duration.ofSeconds(10));
  // How long to wait until for draining an ongoing API call for an actor instance.
  ActorRuntime.getInstance().getConfig().setDrainOngoingCallTimeout(Duration.ofSeconds(10));
  // Determines whether to drain API calls for actors instances being balanced.
  ActorRuntime.getInstance().getConfig().setDrainBalancedActors(true);

  // Register the Actor class.
  ActorRuntime.getInstance().registerActor(DemoActorImpl.class);

  // Start Dapr's callback endpoint.
  DaprApplication.start(port);
}
 
Example 3
Source File: AgentWithNettyMessaging.java    From rapid with Apache License 2.0 6 votes vote down vote up
public static void main(final String[] args) throws ParseException {
    final Options options = new Options();
    options.addRequiredOption("l", "listenAddress", true, "The listening addresses Rapid Cluster instances");
    options.addRequiredOption("s", "seedAddress", true, "The seed node's address for the bootstrap protocol");
    final CommandLineParser parser = new DefaultParser();
    final CommandLine cmd = parser.parse(options, args);

    // Get CLI options
    final HostAndPort listenAddress = HostAndPort.fromString(cmd.getOptionValue("listenAddress"));
    final HostAndPort seedAddress = HostAndPort.fromString(cmd.getOptionValue("seedAddress"));

    // Bring up Rapid node
    try {
        final AgentWithNettyMessaging agent = new AgentWithNettyMessaging(listenAddress, seedAddress);
        agent.startCluster();
        for (int i = 0; i < MAX_TRIES; i++) {
            agent.printClusterMembership();
            Thread.sleep(SLEEP_INTERVAL_MS);
        }
    } catch (final IOException | InterruptedException e) {
        LOG.error("Exception thrown by StandaloneAgent {}", e);
        Thread.currentThread().interrupt();
    }
}
 
Example 4
Source File: StandaloneAgent.java    From rapid with Apache License 2.0 6 votes vote down vote up
public static void main(final String[] args) throws ParseException {
    final Options options = new Options();
    options.addRequiredOption("l", "listenAddress", true, "The listening addresses Rapid Cluster instances");
    options.addRequiredOption("s", "seedAddress", true, "The seed node's address for the bootstrap protocol");
    final CommandLineParser parser = new DefaultParser();
    final CommandLine cmd = parser.parse(options, args);

    // Get CLI options
    final HostAndPort listenAddress = HostAndPort.fromString(cmd.getOptionValue("listenAddress"));
    final HostAndPort seedAddress = HostAndPort.fromString(cmd.getOptionValue("seedAddress"));

    // Bring up Rapid node
    try {
        final StandaloneAgent agent = new StandaloneAgent(listenAddress, seedAddress);
        agent.startCluster();
        for (int i = 0; i < MAX_TRIES; i++) {
            agent.printClusterMembership();
            Thread.sleep(SLEEP_INTERVAL_MS);
        }
    } catch (final IOException | InterruptedException e) {
        LOG.error("Exception thrown by StandaloneAgent {}", e);
        Thread.currentThread().interrupt();
    }
}
 
Example 5
Source File: Subscriber.java    From java-sdk with MIT License 5 votes vote down vote up
/**
 * This is the entry point for this example app, which subscribes to a topic.
 * @param args The port this app will listen on.
 * @throws Exception An Exception on startup.
 */
public static void main(String[] args) throws Exception {
  Options options = new Options();
  options.addRequiredOption("p", "port", true, "The port this app will listen on");

  CommandLineParser parser = new DefaultParser();
  CommandLine cmd = parser.parse(options, args);

  // If port string is not valid, it will throw an exception.
  int port = Integer.parseInt(cmd.getOptionValue("port"));

  // Start Dapr's callback endpoint.
  DaprApplication.start(port);
}
 
Example 6
Source File: InputBindingExample.java    From java-sdk with MIT License 5 votes vote down vote up
/**
 * The entry point of this app.
 * @param args The port this app will listen on.
 * @throws Exception The Exception.
 */
public static void main(String[] args) throws Exception {
  Options options = new Options();
  options.addRequiredOption("p", "port", true, "The port this app will listen on.");

  CommandLineParser parser = new DefaultParser();
  CommandLine cmd = parser.parse(options, args);

  // If port string is not valid, it will throw an exception.
  int port = Integer.parseInt(cmd.getOptionValue("port"));

  // Start Dapr's callback endpoint.
  DaprApplication.start(port);
}
 
Example 7
Source File: DemoService.java    From java-sdk with MIT License 5 votes vote down vote up
/**
 * Starts the service.
 * @param args Expects the port: -p PORT
 * @throws Exception If cannot start service.
 */
public static void main(String[] args) throws Exception {
  Options options = new Options();
  options.addRequiredOption("p", "port", true, "Port to listen to.");

  CommandLineParser parser = new DefaultParser();
  CommandLine cmd = parser.parse(options, args);

  // If port string is not valid, it will throw an exception.
  int port = Integer.parseInt(cmd.getOptionValue("port"));

  DaprApplication.start(port);
}
 
Example 8
Source File: HelloWorldService.java    From java-sdk with MIT License 5 votes vote down vote up
/**
 * This is the main method of this app.
 * @param args The port to listen on.
 * @throws Exception An Exception.
 */
public static void main(String[] args) throws Exception {
  Options options = new Options();
  options.addRequiredOption("p", "port", true, "Port to listen to.");

  CommandLineParser parser = new DefaultParser();
  CommandLine cmd = parser.parse(options, args);

  // If port string is not valid, it will throw an exception.
  int port = Integer.parseInt(cmd.getOptionValue("port"));

  final GrpcHelloWorldDaprService service = new GrpcHelloWorldDaprService();
  service.start(port);
  service.awaitTermination();
}
 
Example 9
Source File: BulkFetchAndUpdate.java    From atlas with Apache License 2.0 5 votes vote down vote up
private static CommandLine getCommandLine(String[] args) throws ParseException {
    Options options = new Options();
    options.addRequiredOption("s", "step", true, "Step to run.");
    options.addOption("u", "user", true, "User name.");
    options.addOption("p", "password", true, "Password name.");
    options.addOption("d", "dir", true, "Directory for reading/writing data.");
    options.addOption(OPTION_FROM, "fromDate", true, "Date, in YYYY-MM-DD format, from where to start reading.");

    return new DefaultParser().parse(options, args);
}