๐ HTTP ์๋ฒ
HTTP ์๋ฒ๋ Tomcat์ ํต์ฌ ๊ธฐ๋ฅ์ ์ฌํํ Sprout์ ์๋ฒ ๋๋ ์๋ฒ ๊ตฌํ์ฒด์ ๋๋ค. Blocking I/O (BIO)์ Non-blocking I/O (NIO)๋ฅผ ๋ชจ๋ ์ง์ํ๋ฉฐ, ํ๋ซํผ ์ค๋ ๋ ๋๋ ๊ฐ์ ์ค๋ ๋ ์ต์ ์ ์ ๊ณตํ๋ ์ ์ฐํ๊ณ ์ค์ ๊ฐ๋ฅํ ์๋ฒ ์ธํ๋ผ๋ฅผ ์ ๊ณตํฉ๋๋ค.
๊ฐ์โ
Sprout์ HTTP ์๋ฒ๋ ๋ค์์ ์ ๊ณตํฉ๋๋ค:
- NIO ๊ธฐ๋ฐ ์ด๋ฒคํธ ๋ฃจํ: Java NIO Selector๋ฅผ ์ฌ์ฉํ ๊ณ ์ฑ๋ฅ ๋ ผ๋ธ๋กํน I/O
- ํ์ด๋ธ๋ฆฌ๋ BIO/NIO ๋ชจ๋: ํ๋กํ ์ฝ ํธ๋ค๋ฌ๋ณ ์ ์ฐํ I/O ์ ๋ต ์ ํ
- ๊ฐ์ ์ค๋ ๋ ์ง์: Java 21์ ๊ฐ์ ์ค๋ ๋๋ฅผ ํ์ฉํ ํ๋์ ์ธ ๋์์ฑ ์ฒ๋ฆฌ
- ํ๋ซํผ ์ค๋ ๋ ํ: ํธํ์ฑ์ ์ํ ์ ํต์ ์ธ ์ค๋ ๋ ํ
- ํ๋กํ ์ฝ ๊ฐ์ง: HTTP/WebSocket ํ๋กํ ์ฝ ์๋ ์๋ณ
- ํ๋ฌ๊ทธ์ธํ ํธ๋ค๋ฌ ์ํคํ ์ฒ: ํ์ฅ ๊ฐ๋ฅํ ํ๋กํ ์ฝ ํธ๋ค๋ฌ ์์คํ
์๋ฒ ์ํคํ ์ฒโ
ํต์ฌ ์ปดํฌ๋ํธโ
HTTP ์๋ฒ๋ ๋ค์์ ์ฃผ์ ์ปดํฌ๋ํธ๋ก ๊ตฌ์ฑ๋ฉ๋๋ค:
HttpServer
: ๋ผ์ดํ์ฌ์ดํด ๊ด๋ฆฌ๋ฅผ ๊ตฌํํ๋ ๋ฉ์ธ ์๋ฒ ํ์ฌ๋ServerStrategy
: ํ๋ฌ๊ทธ์ธํ ์๋ฒ ์ ๋ต ์ธํฐํ์ด์ค (NIO ์ด๋ฒคํธ ๋ฃจํ)ConnectionManager
: ์ฐ๊ฒฐ ์๋ฝ ๋ฐ ํ๋กํ ์ฝ ๋ผ์ฐํProtocolDetector
: ์ด๊ธฐ ๋ฐ์ดํธ๋ก๋ถํฐ ํ๋กํ ์ฝ ์๋ณProtocolHandler
: ํ๋กํ ์ฝ๋ณ ์์ฒญ ์ฒ๋ฆฌRequestExecutorService
: ์ค๋ ๋ ๊ด๋ฆฌ ์ถ์ํ
์๋ฒ ์ด๊ธฐํ ํ๋ก์ธ์คโ
public class SproutApplication {
public static void run(Class<?> primarySource) throws Exception {
// 1. ์ ํ๋ฆฌ์ผ์ด์
์ปจํ
์คํธ ์์ฑ
ApplicationContext ctx = new SproutApplicationContext(packages);
ctx.refresh();
// 2. HttpServer ๋น ๊ฐ์ ธ์ค๊ธฐ
HttpServer server = ctx.getBean(HttpServer.class);
// 3. ์๋ฒ ์์
int port = server.start(8080);
System.out.println("Server started on port " + port);
}
}