You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@eventmesh.apache.org by "pandaapo (via GitHub)" <gi...@apache.org> on 2024/03/21 11:01:08 UTC
Re: [PR] [ISSUE #4750] Replace sun.net.httpserver.HttpServer to use netty server (eventmesh)
pandaapo commented on code in PR #4739:
URL: https://github.com/apache/eventmesh/pull/4739#discussion_r1533663698
##########
eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshAdminServer.java:
##########
@@ -0,0 +1,299 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.eventmesh.runtime.boot;
+
+import org.apache.eventmesh.runtime.admin.handler.AdminHandlerManager;
+import org.apache.eventmesh.runtime.util.HttpResponseUtils;
+import org.apache.eventmesh.runtime.util.Utils;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.InetSocketAddress;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Optional;
+import java.util.Set;
+
+import io.netty.bootstrap.ServerBootstrap;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import io.netty.channel.ChannelFutureListener;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelInitializer;
+import io.netty.channel.ChannelOption;
+import io.netty.channel.ChannelPipeline;
+import io.netty.channel.SimpleChannelInboundHandler;
+import io.netty.channel.epoll.EpollServerSocketChannel;
+import io.netty.channel.socket.SocketChannel;
+import io.netty.channel.socket.nio.NioServerSocketChannel;
+import io.netty.handler.codec.http.DefaultFullHttpResponse;
+import io.netty.handler.codec.http.FullHttpRequest;
+import io.netty.handler.codec.http.HttpObjectAggregator;
+import io.netty.handler.codec.http.HttpRequest;
+import io.netty.handler.codec.http.HttpRequestDecoder;
+import io.netty.handler.codec.http.HttpResponseEncoder;
+import io.netty.handler.codec.http.HttpResponseStatus;
+import io.netty.handler.codec.http.HttpVersion;
+
+import com.sun.net.httpserver.Headers;
+import com.sun.net.httpserver.HttpContext;
+import com.sun.net.httpserver.HttpExchange;
+import com.sun.net.httpserver.HttpHandler;
+import com.sun.net.httpserver.HttpPrincipal;
+
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+public class EventMeshAdminServer extends AbstractHTTPServer {
+
+ private HttpConnectionHandler httpConnectionHandler = new HttpConnectionHandler();
+
+ private AdminHandlerManager adminHandlerManager;
+
+ public EventMeshAdminServer(EventMeshServer eventMeshServer) {
+ super(eventMeshServer.getEventMeshTCPServer().getEventMeshTCPConfiguration().getEventMeshServerAdminPort(), false,
+ eventMeshServer.getEventMeshHTTPServer().getEventMeshHttpConfiguration());
+ adminHandlerManager = new AdminHandlerManager(eventMeshServer);
+ }
+
+
+ @Override
+ public void init() throws Exception {
+ super.init("eventMesh-admin-http");
+ adminHandlerManager.registerHttpHandler();
+ }
+
+ @Override
+ public void start() throws Exception {
+ final Thread thread = new Thread(() -> {
+ final ServerBootstrap bootstrap = new ServerBootstrap();
+ try {
+ bootstrap.group(this.getBossGroup(), this.getIoGroup())
+ .channel(useEpoll() ? EpollServerSocketChannel.class : NioServerSocketChannel.class)
+ .childHandler(new AdminServerInitializer())
+ .childOption(ChannelOption.SO_KEEPALIVE, Boolean.TRUE);
+
+ log.info("AdminHttpServer[port={}] started.", this.getPort());
+
+ bootstrap.bind(this.getPort())
+ .channel()
+ .closeFuture()
+ .sync();
+ } catch (Exception e) {
+ log.error("AdminHttpServer start error!", e);
+ try {
+ shutdown();
+ } catch (Exception ex) {
+ log.error("AdminHttpServer shutdown error!", ex);
+ }
+ System.exit(-1);
Review Comment:
Is it appropriate for the admin server to exit when it starts a failed process? Older versions of admin server didn't have such strong constraints. Please keep an eye on the community, I'm not sure if it's appropriate or not.
admin server启动失败进程就退出是否合适?旧版的admin server没有这么强的约束。请社区留意,我不知道合适与否。
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: issues-help@eventmesh.apache.org