forked from yegor256/takes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFront.java
More file actions
56 lines (52 loc) · 1.98 KB
/
Front.java
File metadata and controls
56 lines (52 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* SPDX-FileCopyrightText: Copyright (c) 2014-2026 Yegor Bugayenko
* SPDX-License-Identifier: MIT
*/
package org.takes.http;
import java.io.IOException;
/**
* HTTP front-end.
*
* <p>A front-end is responsible for accepting incoming client connections
* and managing the overall server lifecycle. It typically binds to a network
* port, listens for incoming TCP connections, and passes each connection
* to a {@link Back} implementation for processing.
*
* <p>The front-end runs in a continuous loop, accepting connections until
* the provided {@link Exit} condition indicates that the server should
* shut down gracefully. This design allows for controlled server shutdown
* and proper resource cleanup.
*
* <p>Key responsibilities:
* <ul>
* <li>Bind to network interface and port</li>
* <li>Accept incoming TCP connections</li>
* <li>Dispatch connections to back-end processors</li>
* <li>Monitor exit conditions for graceful shutdown</li>
* <li>Clean up network resources on termination</li>
* </ul>
*
* <p>All implementations of this interface must be thread-safe.
*
* @since 0.1
*/
@FunctionalInterface
public interface Front {
/**
* Start the front-end and dispatch all incoming connections.
*
* <p>This method blocks and runs the main server loop. It continuously
* accepts incoming client connections and processes them until the
* exit condition is met. The method should handle the complete server
* lifecycle, including binding to the network port, accepting connections,
* and performing cleanup when shutting down.
*
* <p>Implementations should check the exit condition periodically
* (typically between accepting connections) and shut down gracefully
* when {@link Exit#ready()} returns {@code true}.
*
* @param exit Condition that determines when the server should stop
* @throws IOException If network operations fail or server cannot start
*/
void start(Exit exit) throws IOException;
}