armybuilder/src/main/java/net/mekstrike/armybuilder/ArmyBuilderService.java
/**
   * Server mode: starts listening on given port.
   *
   * @param port Port to listen on.
   * @throws IOException Errors while trying to start service.
   */
Server mode: starts listening on given port.
@param port Port to listen on.
@throws IOException Errors while trying to start service.
Server mode : starts listening on given port . @param port Port to listen on . @throws IOException Errors while trying to start service .
public void start(int port) throws IOException {
    this.server = ServerBuilder.forPort(port).addService(this).build().start();
    System.out.printf("Server: started listening on port %d\n", port);
    client = new DaprClientBuilder().build();
    Runtime.getRuntime().addShutdownHook(new Thread() {
      @Override
      public void run() {
        try {
          System.out.println("Server: shutting down gracefully ...");
          ArmyBuilderService.this.server.shutdown();
          client.close();
        } catch (Exception e) {
          e.printStackTrace();
        }
        System.out.println("Server: Bye.");
      }
    });
  }
public void start ( int port ) throws IOException { this . server = ServerBuilder . forPort ( port ) . addService ( this ) . build ( ) . start ( ) ; System . out . printf ( "Server: started listening on port %d\n" , port ) ; client = new DaprClientBuilder ( ) . build ( ) ; Runtime . getRuntime ( ) . addShutdownHook ( new Thread ( ) { @ Override public void run ( ) { try { System . out . println ( "Server: shutting down gracefully ..." ) ; ArmyBuilderService . this . server . shutdown ( ) ; client . close ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } System . out . println ( "Server: Bye." ) ; } } ) ; }
Server mode: starts listening on given port.
Server mode : starts listening on given port .
// Now we handle ctrl+c (or any other JVM shutdown)