Class NettyWebsocketTtyBootstrap

java.lang.Object
org.aesh.terminal.http.netty.NettyWebsocketTtyBootstrap

public class NettyWebsocketTtyBootstrap extends Object
Convenience class for quickly starting a Netty Tty server.
Author:
Julien Viet
  • Constructor Details

    • NettyWebsocketTtyBootstrap

      public NettyWebsocketTtyBootstrap()
      Creates a new bootstrap with default host (localhost) and port (8080).
  • Method Details

    • getHost

      public String getHost()
      Returns the host address the server will bind to.
      Returns:
      the host address
    • setHost

      public NettyWebsocketTtyBootstrap setHost(String host)
      Sets the host address for the server to bind to.
      Parameters:
      host - the host address
      Returns:
      this bootstrap instance for method chaining
    • getPort

      public int getPort()
      Returns the port the server will listen on.
      Returns:
      the port number
    • setPort

      public NettyWebsocketTtyBootstrap setPort(int port)
      Sets the port for the server to listen on.
      Parameters:
      port - the port number
      Returns:
      this bootstrap instance for method chaining
    • getResourcePath

      public String getResourcePath()
      Returns the classpath resource path for static files.
      Returns:
      the resource path
    • setResourcePath

      public NettyWebsocketTtyBootstrap setResourcePath(String resourcePath)
      Sets the classpath resource path for serving static files. The path should start with "/" and point to a classpath location. For example, "/com/example/myapp/web" would serve files from that package.
      Parameters:
      resourcePath - the classpath resource path
      Returns:
      this bootstrap instance for method chaining
    • isServeStaticFiles

      public boolean isServeStaticFiles()
      Returns whether static file serving is enabled.
      Returns:
      true if static files are served, false for WebSocket-only mode
    • setServeStaticFiles

      public NettyWebsocketTtyBootstrap setServeStaticFiles(boolean serveStaticFiles)
      Enables or disables static file serving. When disabled, only WebSocket connections at /ws are handled. HTTP requests to other paths will receive a 404 response.
      Parameters:
      serveStaticFiles - true to serve static files, false for WebSocket-only mode
      Returns:
      this bootstrap instance for method chaining
    • start

      public void start(Consumer<Connection> handler, Consumer<Throwable> doneHandler)
      Starts the server asynchronously with callback-based completion notification.
      Parameters:
      handler - the handler to invoke for each new connection
      doneHandler - the callback invoked when startup completes (with null on success, or the error)
    • start

      public CompletableFuture<Void> start(Consumer<Connection> handler) throws Exception
      Starts the server asynchronously and returns a CompletableFuture.
      Parameters:
      handler - the handler to invoke for each new connection
      Returns:
      a CompletableFuture that completes when the server has started
      Throws:
      Exception - if an error occurs during startup
    • stop

      public void stop(Consumer<Throwable> doneHandler)
      Stops the server asynchronously with callback-based completion notification.
      Parameters:
      doneHandler - the callback invoked when shutdown completes
    • stop

      Stops the server asynchronously and returns a CompletableFuture.
      Returns:
      a CompletableFuture that completes when the server has stopped
      Throws:
      InterruptedException - if the thread is interrupted while waiting