Skip to content

Commit

Permalink
Migrate from standard socket to Netty for improved performance
Browse files Browse the repository at this point in the history
  • Loading branch information
mustafabinguldev committed Feb 23, 2025
1 parent a106dea commit a064adb
Show file tree
Hide file tree
Showing 17 changed files with 420 additions and 543 deletions.
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@
</dependency>


<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.72.Final</version> <!-- Versiyon numarasını ihtiyacınıza göre güncelleyebilirsiniz -->
</dependency>





</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import lombok.Getter;
import org.yaml.snakeyaml.Yaml;
import tech.bingulhan.webserver.app.ui.ApplicationUI;
import tech.bingulhan.webserver.server.HttpServer;
import tech.bingulhan.webserver.server.HttpNettyServer;

import java.io.File;
import java.io.FileInputStream;
Expand All @@ -30,7 +30,7 @@ public class AureliusApplication {

private static AureliusApplication instance;

private HttpServer server;
private HttpNettyServer server;

public static synchronized AureliusApplication getInstance() {
return instance;
Expand Down Expand Up @@ -118,10 +118,11 @@ public Map<String, Object> readYaml(String filePath) throws IOException {
}

public void start(String[] args) {

server = new HttpServer(this,port, args);
server= new HttpNettyServer(this, args);
server.start();
}




}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void start(Stage stage) throws Exception {
Scene scene = new Scene(root, 600, 400);

stage.setOnCloseRequest(event -> AureliusApplication.getInstance().stop());
stage.setTitle("Aurelius 0.4.6 - Server Status");
stage.setTitle("Aurelius 0.5 - Server Status");
stage.setScene(scene);
stage.setResizable(false);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package tech.bingulhan.webserver.response;

public interface NettyResponseHandler {


void handleResponse(NettyResponseService service, RequestStructure structure);

static void handle(NettyResponseService service, RequestStructure structure) {
String[] paths = structure.getRoot().split("/");
if (paths.length>1) {
for (NettyResponseType type: NettyResponseType.values()) {
if (type.path.equals(paths[1])) {
type.handler.handleResponse(service, structure);
return;
}
}
}

NettyResponseType.PAGE.handler.handleResponse(service,structure);


}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package tech.bingulhan.webserver.response;

import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.DefaultHttpRequest;
import lombok.Getter;
import tech.bingulhan.webserver.app.AureliusApplication;

@Getter
public class NettyResponseService {

private DefaultHttpRequest request;

private ChannelHandlerContext ctx;

private AureliusApplication application;

public NettyResponseService(AureliusApplication application, DefaultHttpRequest request, ChannelHandlerContext ctx) {
this.application = application;
this.request = request;
this.ctx = ctx;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package tech.bingulhan.webserver.response;

import tech.bingulhan.webserver.response.impl.media.NettyResponseMediaHandler;
import tech.bingulhan.webserver.response.impl.mvc.NettyResponseMvcHandler;

public enum NettyResponseType {

PAGE("", new NettyResponseMvcHandler()),
MEDIA("public", new NettyResponseMediaHandler());
;
public String path;

public NettyResponseHandler handler;
NettyResponseType(String path, NettyResponseHandler handler) {
this.path = path;
this.handler = handler;
}

}

This file was deleted.

110 changes: 0 additions & 110 deletions src/main/java/tech/bingulhan/webserver/response/ResponseService.java

This file was deleted.

19 changes: 0 additions & 19 deletions src/main/java/tech/bingulhan/webserver/response/ResponseType.java

This file was deleted.

This file was deleted.

Loading

0 comments on commit a064adb

Please sign in to comment.