yfsn666 commented on code in PR #10837: URL: https://github.com/apache/inlong/pull/10837#discussion_r1725052438
########## inlong-sort-standalone/sort-standalone-source/src/main/java/org/apache/inlong/sort/standalone/sink/http/HttpCallback.java: ########## @@ -0,0 +1,87 @@ +/* + * 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.inlong.sort.standalone.sink.http; + +import org.apache.inlong.sort.standalone.channel.ProfileEvent; +import org.apache.inlong.sort.standalone.utils.InlongLoggerFactory; + +import org.apache.http.HttpResponse; +import org.apache.http.concurrent.FutureCallback; +import org.slf4j.Logger; + +public class HttpCallback implements FutureCallback<HttpResponse> { + + public static final Logger LOG = InlongLoggerFactory.getLogger(HttpCallback.class); + + private HttpSinkContext context; + private HttpRequest requestItem; + + public HttpCallback(HttpSinkContext context, HttpRequest requestItem) { + this.context = context; + this.requestItem = requestItem; + } + + @Override + public void completed(HttpResponse httpResponse) { + int statusCode = httpResponse.getStatusLine().getStatusCode(); + ProfileEvent event = requestItem.getEvent(); + long sendTime = requestItem.getSendTime(); + + // is fail + if (statusCode != 200) { + context.addSendResultMetric(event, context.getTaskName(), false, sendTime); + // if reach the max retry times, release the request + int remainRetryTimes = requestItem.getRemainRetryTimes(); + if (remainRetryTimes == 1) { + context.releaseDispatchQueue(requestItem); + return; + } + if (remainRetryTimes > 1) { + requestItem.setRemainRetryTimes(remainRetryTimes - 1); + } + context.backDispatchQueue(requestItem); + } else { + context.addSendResultMetric(event, context.getTaskName(), true, sendTime); + context.releaseDispatchQueue(requestItem); + event.ack(); + } + } + + @Override + public void failed(Exception e) { + LOG.error("Http request failed,errorMsg:" + e.getMessage(), e); Review Comment: fixed. ########## inlong-sort-standalone/sort-standalone-source/src/main/java/org/apache/inlong/sort/standalone/sink/http/HttpChannelWorker.java: ########## @@ -0,0 +1,102 @@ +/* + * 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.inlong.sort.standalone.sink.http; + +import org.apache.inlong.sort.standalone.channel.ProfileEvent; + +import org.apache.flume.Channel; +import org.apache.flume.Event; +import org.apache.flume.Transaction; +import org.apache.flume.lifecycle.LifecycleState; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class HttpChannelWorker extends Thread { + + public static final Logger LOG = LoggerFactory.getLogger(HttpChannelWorker.class); + + private final HttpSinkContext context; + private final int workerIndex; + + private LifecycleState status; + private IEvent2HttpRequestHandler handler; + + public HttpChannelWorker(HttpSinkContext context, int workerIndex) { + this.context = context; + this.workerIndex = workerIndex; + this.status = LifecycleState.IDLE; + this.handler = context.createHttpRequestHandler(); + } + + @Override + public void run() { + status = LifecycleState.START; + LOG.info("start to HttpChannelWorker:{},status:{},index:{}", context.getTaskName(), status, workerIndex); Review Comment: fixed. -- 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: commits-unsubscr...@inlong.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org