githublaohu commented on code in PR #937: URL: https://github.com/apache/incubator-eventmesh/pull/937#discussion_r920326682
########## eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/HandlerService.java: ########## @@ -0,0 +1,232 @@ +/* + * 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.core.protocol.http.processor; + +import org.apache.eventmesh.runtime.boot.HTTPTrace; +import org.apache.eventmesh.runtime.boot.HTTPTrace.TraceOperation; +import org.apache.eventmesh.runtime.metrics.http.HTTPMetricsServer; +import org.apache.eventmesh.runtime.util.HttpResponseUtils; +import org.apache.eventmesh.runtime.util.RemotingHelper; + +import java.util.Map; +import java.util.Map.Entry; +import java.util.Objects; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ThreadPoolExecutor; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import io.netty.channel.ChannelFutureListener; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.http.HttpRequest; +import io.netty.handler.codec.http.HttpResponse; + +import lombok.Setter; + + +public class HandlerService { + + private Logger httpServerLogger = LoggerFactory.getLogger(this.getClass()); + + private Logger httpLogger = LoggerFactory.getLogger("http"); + + private Map<String, ProcessorWrapper> httpProcessorMap = new ConcurrentHashMap<>(); + + @Setter + private HTTPMetricsServer metrics; + + @Setter + private HTTPTrace httpTrace; + + + public void init() { + httpServerLogger.info("HandlerService start "); + } + + public void register(HttpProcessor httpProcessor, ThreadPoolExecutor threadPoolExecutor) { + for (String path : httpProcessor.paths()) { + this.register(path, httpProcessor, threadPoolExecutor); + } + } + + public void register(String path, HttpProcessor httpProcessor, ThreadPoolExecutor threadPoolExecutor) { + + if (httpProcessorMap.containsKey(path)) { + throw new RuntimeException(String.format("HandlerService path %s repeat, repeat processor is %s ", + path, httpProcessor.getClass().getSimpleName())); + } + ProcessorWrapper processorWrapper = new ProcessorWrapper(); + processorWrapper.threadPoolExecutor = threadPoolExecutor; + processorWrapper.httpProcessor = httpProcessor; + if (httpProcessor instanceof AsynHttpProcessor) { + processorWrapper.asyn = (AsynHttpProcessor) httpProcessor; + } else { + processorWrapper.httpProcessor = httpProcessor; Review Comment: ok ########## eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/AsynHttpProcessor.java: ########## @@ -0,0 +1,35 @@ +/* + * 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.core.protocol.http.processor; + +import org.apache.eventmesh.runtime.core.protocol.http.processor.HandlerService.HandlerSpecific; + +import io.netty.handler.codec.http.HttpRequest; +import io.netty.handler.codec.http.HttpResponse; + +/** + * aysn http processor + */ +public interface AsynHttpProcessor extends HttpProcessor { Review Comment: ok -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
