Skip to content

Commit

Permalink
Fuse ServiceManager implementation (#116)
Browse files Browse the repository at this point in the history
* Fuse ServiceManagers

* Update ContextUtilTest.java

* Update ContextUtilTest.java

* Update SpiServiceManager.java
  • Loading branch information
SentryMan authored Dec 2, 2024
1 parent 7a6ec82 commit 4249441
Show file tree
Hide file tree
Showing 8 changed files with 228 additions and 385 deletions.
20 changes: 10 additions & 10 deletions avaje-jex/src/main/java/io/avaje/jex/core/BootstrapServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,13 @@ public static Jex.Server start(Jex jex) {
}

final SpiRoutes routes =
new RoutesBuilder(jex.routing(), config.ignoreTrailingSlashes())
.build();
new RoutesBuilder(jex.routing(), config.ignoreTrailingSlashes()).build();

return start(jex, routes);
}

static Jex.Server start(Jex jex, SpiRoutes routes) {
SpiServiceManager serviceManager = CoreServiceManager.create(jex);
try {
try {
final var config = jex.config();
final var socketAddress = createSocketAddress(config);
final var https = config.httpsConfig();
Expand All @@ -56,25 +54,27 @@ static Jex.Server start(Jex jex, SpiRoutes routes) {

final var scheme = config.scheme();
final var contextPath = config.contextPath();
final var manager = new CtxServiceManager(serviceManager, scheme, contextPath);
final var handler = new RoutingHandler(routes, manager, config.compression());
SpiServiceManager serviceManager = SpiServiceManager.create(jex);
final var handler = new RoutingHandler(routes, serviceManager, config.compression());

server.setExecutor(config.executor());
server.createContext(contextPath, handler);
server.start();

jex.lifecycle().status(AppLifecycle.Status.STARTED);
log.log(
INFO,
"started com.sun.net.httpserver.HttpServer on port {0}://{1}",
scheme, socketAddress);
INFO,
"started com.sun.net.httpserver.HttpServer on port {0}://{1}",
scheme,
socketAddress);
return new JdkJexServer(server, jex.lifecycle(), handler);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

private static InetSocketAddress createSocketAddress(JexConfig config) throws UnknownHostException {
private static InetSocketAddress createSocketAddress(JexConfig config)
throws UnknownHostException {
final var inetAddress = config.host() == null ? null : InetAddress.getByName(config.host());
return new InetSocketAddress(inetAddress, config.port());
}
Expand Down
2 changes: 1 addition & 1 deletion avaje-jex/src/main/java/io/avaje/jex/core/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ private Constants() {}
public static final String HOST = "Host";
public static final String USER_AGENT = "User-Agent";
public static final String ACCEPT_ENCODING = "Accept-Encoding";

public static final String TEXT_HTML = "text/html";
public static final String TEXT_PLAIN = "text/plain";
public static final String TEXT_HTML_UTF8 = "text/html;charset=utf-8";
Expand Down
208 changes: 0 additions & 208 deletions avaje-jex/src/main/java/io/avaje/jex/core/CoreServiceManager.java

This file was deleted.

91 changes: 0 additions & 91 deletions avaje-jex/src/main/java/io/avaje/jex/core/CtxServiceManager.java

This file was deleted.

6 changes: 3 additions & 3 deletions avaje-jex/src/main/java/io/avaje/jex/core/JdkContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ final class JdkContext implements Context {
private static final int SC_MOVED_TEMPORARILY = 302;
private static final String SET_COOKIE = "Set-Cookie";
private static final String COOKIE = "Cookie";
private final CtxServiceManager mgr;
private final SpiServiceManager mgr;
private final CompressionConfig compressionConfig;
private final String path;
private final Map<String, String> pathParams;
Expand All @@ -57,7 +57,7 @@ final class JdkContext implements Context {
private String characterEncoding;

JdkContext(
CtxServiceManager mgr,
SpiServiceManager mgr,
CompressionConfig compressionConfig,
HttpExchange exchange,
String path,
Expand All @@ -73,7 +73,7 @@ final class JdkContext implements Context {

/** Create when no route matched. */
JdkContext(
CtxServiceManager mgr,
SpiServiceManager mgr,
CompressionConfig compressionConfig,
HttpExchange exchange,
String path,
Expand Down
Loading

0 comments on commit 4249441

Please sign in to comment.