public static void main(String[] args) throws IOException, InterruptedException {
    // Add final keyword to pass checkStyle.
    final String user = getStringOrDefaultFromArgs(args, 0, "world");
    final String host = getStringOrDefaultFromArgs(args, 1, "localhost");
    final int serverPort = getPortOrDefaultFromArgs(args, 2, 50051);
    final String cloudProjectId = getStringOrDefaultFromArgs(args, 3, null);
    final int zPagePort = getPortOrDefaultFromArgs(args, 4, 3001);

    // Registers all RPC views. For demonstration all views are registered. You may want to
    // start with registering basic views and register other views as needed for your application.
    RpcViews.registerAllViews();

    // Starts a HTTP server and registers all Zpages to it.
    ZPageHandlers.startHttpServerAndRegisterAll(zPagePort);
    logger.info("ZPages server starts at localhost:" + zPagePort);

    // Registers logging trace exporter.
    LoggingTraceExporter.register();

    // Registers Stackdriver exporters.
    if (cloudProjectId != null) {
      StackdriverTraceExporter.createAndRegister(
          StackdriverTraceConfiguration.builder().setProjectId(cloudProjectId).build());
      StackdriverStatsExporter.createAndRegister(
          StackdriverStatsConfiguration.builder()
              .setProjectId(cloudProjectId)
              .setExportInterval(Duration.create(60, 0))
              .build());
    }

    // Register Prometheus exporters and export metrics to a Prometheus HTTPServer.
    PrometheusStatsCollector.createAndRegister();

    HelloWorldClient client = new HelloWorldClient(host, serverPort);
    try {
      client.greet(user);
    } finally {
      client.shutdown();
    }

    logger.info("Client sleeping, ^C to exit. Meanwhile you can view stats and spans on zpages.");
    while (true) {
      try {
        Thread.sleep(10000);
      } catch (InterruptedException e) {
        logger.info("Exiting HelloWorldClient...");
      }
    }
  }
public static void main ( String [ ] args ) throws IOException , InterruptedException { final String user = getStringOrDefaultFromArgs ( args , 0 , "world" ) ; final String host = getStringOrDefaultFromArgs ( args , 1 , "localhost" ) ; final int serverPort = getPortOrDefaultFromArgs ( args , 2 , 50051 ) ; final String cloudProjectId = getStringOrDefaultFromArgs ( args , 3 , null ) ; final int zPagePort = getPortOrDefaultFromArgs ( args , 4 , 3001 ) ; RpcViews . registerAllViews ( ) ; ZPageHandlers . startHttpServerAndRegisterAll ( zPagePort ) ; logger . info ( "ZPages server starts at localhost:" + zPagePort ) ; LoggingTraceExporter . register ( ) ; if ( cloudProjectId != null ) { StackdriverTraceExporter . createAndRegister ( StackdriverTraceConfiguration . builder ( ) . setProjectId ( cloudProjectId ) . build ( ) ) ; StackdriverStatsExporter . createAndRegister ( StackdriverStatsConfiguration . builder ( ) . setProjectId ( cloudProjectId ) . setExportInterval ( Duration . create ( 60 , 0 ) ) . build ( ) ) ; } PrometheusStatsCollector . createAndRegister ( ) ; HelloWorldClient client = new HelloWorldClient ( host , serverPort ) ; try { client . greet ( user ) ; } finally { client . shutdown ( ) ; } logger . info ( "Client sleeping, ^C to exit. Meanwhile you can view stats and spans on zpages." ) ; while ( true ) { try { Thread . sleep ( 10000 ) ; } catch ( InterruptedException e ) { logger . info ( "Exiting HelloWorldClient..." ) ; } } }
Greet server. If provided, the first element of {@code args} is the name to use in the
greeting.