Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add MtRequestProcessor #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
package io.github.protocol.mtconnect.server;

import io.github.shoothzj.http.facade.core.HttpMethod;
import io.github.shoothzj.http.facade.server.HttpServer;
import io.github.shoothzj.http.facade.server.HttpServerFactory;

import java.util.HashMap;
import java.util.concurrent.CompletableFuture;

public class MtConnectServer {
private final MtConnectServerConfiguration config;

private final HttpServer httpServer;

private final MtRequestProcessor mtRequestProcessor;

public MtConnectServer(MtConnectServerConfiguration configuration) {
this.config = configuration;
this.httpServer = HttpServerFactory.createHttpServer(config.httpConfig());
this.mtRequestProcessor = new MtRequestProcessor(configuration, new HashMap<>());
}

public CompletableFuture<Void> start() {
mtRequestProcessor.getHandlerMap().entrySet().forEach(entry -> {
httpServer.addRoute(entry.getKey(), HttpMethod.GET, entry.getValue());
});
return httpServer.start();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.github.protocol.mtconnect.server;

import io.github.shoothzj.http.facade.server.RequestHandler;

public interface MtHandler extends RequestHandler {
Copy link
Member

@shoothzj shoothzj Sep 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure this's a good idea. Normally, we would make MtHandler has multi protocol specified method.
It looks same to RequestHandler

If I want to add a http path, what sould I do?

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.github.protocol.mtconnect.server;

import io.github.shoothzj.http.facade.core.HttpRequest;
import io.github.shoothzj.http.facade.core.HttpResponse;

import java.util.concurrent.CompletableFuture;

public class MtHandlerImpl implements MtHandler {
@Override
public CompletableFuture<HttpResponse> handle(HttpRequest request) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.github.protocol.mtconnect.server;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

import java.util.Map;

@AllArgsConstructor
@Getter
@Setter
public class MtRequestProcessor {
private MtConnectServerConfiguration serverCfg;

private Map<String,MtHandler> handlerMap;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package io.github.protocol.mtconnect.server;

class MtConnectServerTest {
}