Skip to content

Commit

Permalink
fix checkstyle
Browse files Browse the repository at this point in the history
  • Loading branch information
lrhkobe committed Jul 12, 2023
1 parent c5be10b commit 9471624
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,35 +142,35 @@ public void recordHTTPDiscard() {
}

public void snapshotHTTPTPS() {
try{
try {
lock.lock();
Integer tps = httpRequestPerSecond.intValue();
httpRequestTPSSnapshots.add(tps);
httpRequestPerSecond.set(0);
if (httpRequestTPSSnapshots.size() > STATIC_PERIOD / 1000) {
httpRequestTPSSnapshots.removeFirst();
}
}finally {
} finally {
lock.unlock();
}
}

public float maxHTTPTPS() {
try{
try {
lock.lock();
float tps = Collections.max(httpRequestTPSSnapshots);
return tps;
}finally {
} finally {
lock.unlock();
}
}

public float avgHTTPTPS() {
try{
try {
lock.lock();
float tps = avg(httpRequestTPSSnapshots);
return tps;
}finally {
} finally {
lock.unlock();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public static CloudEvent buildEvent(HttpEventWrapper httpEventWrapper) throws Pr
String subject = sysHeaderMap.getOrDefault(HttpProtocolConstant.CONSTANTS_KEY_SUBJECT,
HttpProtocolConstant.CONSTANTS_DEFAULT_SUBJECT).toString();

String dataContentType = requestHeaderMap.getOrDefault(HttpProtocolConstant.DATA_CONTENT_TYPE, HttpProtocolConstant.APPLICATION_JSON).toString();
String dataContentType = requestHeaderMap.getOrDefault(HttpProtocolConstant.DATA_CONTENT_TYPE,
HttpProtocolConstant.APPLICATION_JSON).toString();
// with attributes
builder.withId(id)
.withType(type)
Expand All @@ -81,8 +82,8 @@ public static CloudEvent buildEvent(HttpEventWrapper httpEventWrapper) throws Pr
byte[] requestBody = httpEventWrapper.getBody();

if (StringUtils.equals(dataContentType, HttpProtocolConstant.APPLICATION_JSON)) {
Map<String, Object> requestBodyMap = JsonUtils.parseTypeReferenceObject(new String(requestBody), new TypeReference<HashMap<String, Object>>() {
});
Map<String, Object> requestBodyMap = JsonUtils.parseTypeReferenceObject(new String(requestBody),
new TypeReference<HashMap<String, Object>>() {});

String requestURI = httpEventWrapper.getRequestURI();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,11 @@ public synchronized void init() throws Exception {
if (currentTopicConfig == null) {
try {
sendMessageBack(event, uniqueId, bizSeqNo);
log.warn("no ConsumerGroupTopicConf found, sendMessageBack success, consumerGroup:{}, topic:{}, bizSeqNo={}, uniqueId={}", consumerGroupConf.getConsumerGroup(), topic, bizSeqNo, uniqueId);
log.warn("no ConsumerGroupTopicConf found, sendMessageBack success, consumerGroup:{}, topic:{}, bizSeqNo={}, uniqueId={}",
consumerGroupConf.getConsumerGroup(), topic, bizSeqNo, uniqueId);
} catch (Exception ex) {
log.warn("sendMessageBack fail, consumerGroup:{}, topic:{}, bizSeqNo={}, uniqueId={}", consumerGroupConf.getConsumerGroup(), topic, bizSeqNo, uniqueId, ex);
log.warn("sendMessageBack fail, consumerGroup:{}, topic:{}, bizSeqNo={}, uniqueId={}",
consumerGroupConf.getConsumerGroup(), topic, bizSeqNo, uniqueId, ex);
}
eventMeshAsyncConsumeContext.commit(EventMeshAction.CommitMessage);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,13 @@
import java.util.Map;
import java.util.Objects;

import io.cloudevents.CloudEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.cloudevents.CloudEvent;

import lombok.extern.slf4j.Slf4j;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Slf4j
public class HandleMsgContext {

Expand Down Expand Up @@ -211,7 +210,8 @@ public EventMeshHTTPServer getEventMeshHTTPServer() {
public void finish() {
if (Objects.nonNull(eventMeshConsumer) && Objects.nonNull(context) && Objects.nonNull(event)) {
MESSAGE_LOGGER.info("messageAcked|group={}|topic={}|bizSeq={}|uniqId={}|msgRandomNo={}|queueId={}|queueOffset={}",
consumerGroup, topic, bizSeqNo, uniqueId, msgRandomNo, event.getExtension(Constants.PROPERTY_MESSAGE_QUEUE_ID), event.getExtension(Constants.PROPERTY_MESSAGE_QUEUE_OFFSET));
consumerGroup, topic, bizSeqNo, uniqueId, msgRandomNo, event.getExtension(Constants.PROPERTY_MESSAGE_QUEUE_ID),
event.getExtension(Constants.PROPERTY_MESSAGE_QUEUE_OFFSET));
eventMeshConsumer.updateOffset(topic, subscriptionItem.getMode(), Collections.singletonList(event), context);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.apache.eventmesh.runtime.core.protocol.http.async.AsyncContext;
import org.apache.eventmesh.runtime.core.protocol.http.processor.inf.AbstractEventProcessor;
import org.apache.eventmesh.runtime.util.RemotingHelper;
import org.apache.eventmesh.runtime.util.WebhookUtil;

import org.apache.commons.lang3.StringUtils;
import org.apache.http.impl.client.CloseableHttpClient;
Expand Down Expand Up @@ -117,7 +116,7 @@ public void handler(HandlerService.HandlerSpecific handlerSpecific, HttpRequest
return;
}

// String url = requestBodyMap.get(EventMeshConstants.URL).toString();
//String url = requestBodyMap.get(EventMeshConstants.URL).toString();
String topic = JsonUtils.toJSONString(requestBodyMap.get(EventMeshConstants.MANAGE_TOPIC));

// SubscriptionItem
Expand Down Expand Up @@ -145,32 +144,32 @@ public void handler(HandlerService.HandlerSpecific handlerSpecific, HttpRequest
}

// validate URL
// try {
// if (!IPUtils.isValidDomainOrIp(url, eventMeshHttpConfiguration.getEventMeshIpv4BlackList(),
// eventMeshHttpConfiguration.getEventMeshIpv6BlackList())) {
// httpLogger.error("subscriber url {} is not valid", url);
// handlerSpecific.sendErrorResponse(EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR, responseHeaderMap,
// responseBodyMap, null);
// return;
// }
// } catch (Exception e) {
// httpLogger.error("subscriber url {} is not valid, error {}", url, e.getMessage());
// handlerSpecific.sendErrorResponse(EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR, responseHeaderMap,
// responseBodyMap, null);
// return;
// }
//
// CloseableHttpClient closeableHttpClient = eventMeshHTTPServer.getHttpClientPool().getClient();
// // obtain webhook delivery agreement for Abuse Protection
// boolean isWebhookAllowed = WebhookUtil.obtainDeliveryAgreement(closeableHttpClient,
// url, eventMeshHttpConfiguration.getEventMeshWebhookOrigin());
//
// if (!isWebhookAllowed) {
// httpLogger.error("subscriber url {} is not allowed by the target system", url);
// handlerSpecific.sendErrorResponse(EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR, responseHeaderMap,
// responseBodyMap, null);
// return;
// }
// try {
// if (!IPUtils.isValidDomainOrIp(url, eventMeshHttpConfiguration.getEventMeshIpv4BlackList(),
// eventMeshHttpConfiguration.getEventMeshIpv6BlackList())) {
// httpLogger.error("subscriber url {} is not valid", url);
// handlerSpecific.sendErrorResponse(EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR, responseHeaderMap,
// responseBodyMap, null);
// return;
// }
// } catch (Exception e) {
// httpLogger.error("subscriber url {} is not valid, error {}", url, e.getMessage());
// handlerSpecific.sendErrorResponse(EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR, responseHeaderMap,
// responseBodyMap, null);
// return;
// }
//
// CloseableHttpClient closeableHttpClient = eventMeshHTTPServer.getHttpClientPool().getClient();
// // obtain webhook delivery agreement for Abuse Protection
// boolean isWebhookAllowed = WebhookUtil.obtainDeliveryAgreement(closeableHttpClient,
// url, eventMeshHttpConfiguration.getEventMeshWebhookOrigin());
//
// if (!isWebhookAllowed) {
// httpLogger.error("subscriber url {} is not allowed by the target system", url);
// handlerSpecific.sendErrorResponse(EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR, responseHeaderMap,
// responseBodyMap, null);
// return;
// }

long startTime = System.currentTimeMillis();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ public void tryHTTPRequest() {
}

} catch (Exception ex) {
LOGGER.warn("cloudevent to HttpEventWrapper occur except, group:{}, topic:{}, bizSeqNo={}, uniqueId={}", this.handleMsgContext.getConsumerGroup(),
LOGGER.warn("cloudevent to HttpEventWrapper occur except, group:{}, topic:{}, bizSeqNo={}, uniqueId={}",
this.handleMsgContext.getConsumerGroup(),
this.handleMsgContext.getTopic(), this.handleMsgContext.getBizSeqNo(), this.handleMsgContext.getUniqueId(), ex);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static boolean obtainDeliveryAgreement(final CloseableHttpClient httpClie
try (CloseableHttpResponse response = httpClient.execute(builder)) {
String allowedOrigin = null;

if(response.getLastHeader(ALLOWED_ORIGIN_HEADER) != null){
if (response.getLastHeader(ALLOWED_ORIGIN_HEADER) != null) {
allowedOrigin = response.getLastHeader(ALLOWED_ORIGIN_HEADER).getValue();
}
return StringUtils.isEmpty(allowedOrigin)
Expand Down

0 comments on commit 9471624

Please sign in to comment.