Interface HttpServer
- All Known Implementing Classes:
ServerInstance
public interface HttpServer
Interface for an HTTP server.
This interface defines the methods required to start and stop an HTTP server, as well as to retrieve the port on which the server is running.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionintRetrieves the port on which the server is running.booleanChecks if the server is currently running.static HttpServernewInstance(int port) Creates a new instance of the HTTP server with the specified port and default backlog.booleanStarts the HTTP server with the specified router.booleanstop()Stops the HTTP server.
-
Field Details
-
DEFAULT_BACKLOG
static final int DEFAULT_BACKLOG- See Also:
-
-
Method Details
-
start
Starts the HTTP server with the specified router.- Parameters:
router- The router to handle incoming requests.- Returns:
- true if the server started successfully, false otherwise.
- Throws:
InterruptedException- If an error occurs while starting the server.
-
stop
Stops the HTTP server.- Returns:
- true if the server stopped successfully, false otherwise.
- Throws:
InterruptedException- If an error occurs while stopping the server.
-
getInstancePort
int getInstancePort()Retrieves the port on which the server is running.- Returns:
- The port number.
-
isRunning
boolean isRunning()Checks if the server is currently running.- Returns:
- true if the server is running, false otherwise.
-
newInstance
Creates a new instance of the HTTP server with the specified port and default backlog.- Parameters:
port- The port on which the server will listen for incoming connections.- Returns:
- A new instance of the HTTP server.
-