Package org.aesh.terminal.http.netty
Class NettyWebsocketTtyBootstrap
java.lang.Object
org.aesh.terminal.http.netty.NettyWebsocketTtyBootstrap
Convenience class for quickly starting a Netty Tty server.
- Author:
- Julien Viet
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new bootstrap with default host (localhost) and port (8080). -
Method Summary
Modifier and TypeMethodDescriptiongetHost()Returns the host address the server will bind to.intgetPort()Returns the port the server will listen on.Returns the classpath resource path for static files.booleanReturns whether static file serving is enabled.Sets the host address for the server to bind to.setPort(int port) Sets the port for the server to listen on.setResourcePath(String resourcePath) Sets the classpath resource path for serving static files.setServeStaticFiles(boolean serveStaticFiles) Enables or disables static file serving.start(Consumer<Connection> handler) Starts the server asynchronously and returns a CompletableFuture.voidstart(Consumer<Connection> handler, Consumer<Throwable> doneHandler) Starts the server asynchronously with callback-based completion notification.stop()Stops the server asynchronously and returns a CompletableFuture.voidStops the server asynchronously with callback-based completion notification.
-
Constructor Details
-
NettyWebsocketTtyBootstrap
public NettyWebsocketTtyBootstrap()Creates a new bootstrap with default host (localhost) and port (8080).
-
-
Method Details
-
getHost
Returns the host address the server will bind to.- Returns:
- the host address
-
setHost
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
Sets the port for the server to listen on.- Parameters:
port- the port number- Returns:
- this bootstrap instance for method chaining
-
getResourcePath
Returns the classpath resource path for static files.- Returns:
- the resource path
-
setResourcePath
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
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
Starts the server asynchronously with callback-based completion notification.- Parameters:
handler- the handler to invoke for each new connectiondoneHandler- the callback invoked when startup completes (with null on success, or the error)
-
start
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
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
-