Class ExternalProblem.Builder

java.lang.Object
org.moeaframework.problem.ExternalProblem.Builder
Enclosing class:
ExternalProblem

public static class ExternalProblem.Builder extends Object
Builder for defining the process or connection to the external problem.
  • Constructor Details

    • Builder

      public Builder()
      Constructs a new builder.
  • Method Details

    • withCommand

      public ExternalProblem.Builder withCommand(String... command)
      Configures this builder to start a process using the given command and optional arguments.
      Parameters:
      command - the command and arguments
      Returns:
      a reference to this builder for chaining together calls
    • withWorkingDirectory

      public ExternalProblem.Builder withWorkingDirectory(File directory)
      Sets the working directory where the process is started.
      Parameters:
      directory - the working directory
      Returns:
      a reference to this builder for chaining together calls
    • withWorkingDirectory

      public ExternalProblem.Builder withWorkingDirectory(Path path)
      Sets the working directory where the process is started.
      Parameters:
      path - the working directory
      Returns:
      a reference to this builder for chaining together calls
    • withSocket

      public ExternalProblem.Builder withSocket(int port)
      Configures this builder to communicate with a local process using the given port.
      Parameters:
      port - the port
      Returns:
      a reference to this builder for chaining together calls
    • withSocket

      public ExternalProblem.Builder withSocket(InetAddress address, int port)
      Configures this builder to communicate with the specified address and port.
      Parameters:
      address - the address
      port - the port
      Returns:
      a reference to this builder for chaining together calls
    • withSocket

      public ExternalProblem.Builder withSocket(String hostname, int port)
      Configures this builder to communicate with the specified hostname and port.
      Parameters:
      hostname - the host name
      port - the port
      Returns:
      a reference to this builder for chaining together calls
    • withIOStreams

      public ExternalProblem.Builder withIOStreams(InputStream inputStream, OutputStream outputStream)
      Configures this builder to communicate using the given input and output streams. This is primarily intended for internal use.
      Parameters:
      inputStream - the input stream
      outputStream - the output stream
      Returns:
      a reference to this builder for chaining together calls
    • withDebugging

      public ExternalProblem.Builder withDebugging()
      Enables writing debugging info to standard output.
      Returns:
      a reference to this builder for chaining together calls
    • withDebugging

      public ExternalProblem.Builder withDebugging(OutputStream debug)
      Enables writing debugging info to the given output stream. The given stream is not closed when the problem is closed.
      Parameters:
      debug - the output stream
      Returns:
      a reference to this builder for chaining together calls
    • redirectErrorTo

      public ExternalProblem.Builder redirectErrorTo(OutputStream errorStream)
      Redirects the process' standard error to the given stream. The given stream is not closed when the problem is closed.
      Parameters:
      errorStream - the stream where error messages are written
      Returns:
      a reference to this builder for chaining together calls
    • withRetries

      public ExternalProblem.Builder withRetries(int retryAttempts, Duration retryDelay)
      Sets the retry options when trying to connect to the external process with sockets.
      Parameters:
      retryAttempts - the number of retry attempts (a value <= 0 will fail after the first attempt)
      retryDelay - the fixed delay between retries
      Returns:
      a reference to this builder for chaining together calls
    • withShutdownTimeout

      public ExternalProblem.Builder withShutdownTimeout(Duration shutdownTimeout)
      Overrides the timeout given to allow the process to cleanly terminate before sending a kill signal.
      Parameters:
      shutdownTimeout - the shutdown timeout
      Returns:
      a reference to this builder for chaining together calls
    • copy

      protected ExternalProblem.Builder copy()
      Creates a copy of this builder. Note that streams are shared between the two instances.
      Returns:
      the copy
    • build

      protected ExternalProblem.Instance build()
      Returns the constructed instance.
      Returns:
      the external problem instance