[ Status ] optimize code

This commit is contained in:
zeaslity
2023-06-15 17:17:55 +08:00
parent 54569cc41b
commit 1aa4c23dfc
5 changed files with 36 additions and 37 deletions

View File

@@ -1,7 +1,6 @@
package io.wdd.rpc.status;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.wdd.rpc.message.OctopusMessage;
import io.wdd.rpc.message.OctopusMessageType;
import lombok.AllArgsConstructor;
@@ -9,9 +8,10 @@ import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import static io.wdd.common.utils.OctopusObjectMapperConfig.OctopusObjectMapper;
@Data
@AllArgsConstructor
@NoArgsConstructor
@@ -26,9 +26,6 @@ public class OctopusStatusMessage {
public static final String METRIC_STATUS_MESSAGE_TYPE = "METRIC";
public static final String APP_STATUS_MESSAGE_TYPE = "APP";
@Resource
ObjectMapper objectMapper;
/**
* which kind of status should be return
* metric => short time message
@@ -41,7 +38,7 @@ public class OctopusStatusMessage {
int metricRepeatPinch;
public OctopusMessage ConstructAgentStatusMessage(String statusType, String agentTopicName, LocalDateTime currentTime) {
public static OctopusMessage ConstructAgentStatusMessage(String statusType, String agentTopicName, LocalDateTime currentTime) {
OctopusStatusMessage statusMessage = OctopusStatusMessage
.builder()
@@ -50,7 +47,7 @@ public class OctopusStatusMessage {
String ops;
try {
ops = objectMapper.writeValueAsString(statusMessage);
ops = OctopusObjectMapper.writeValueAsString(statusMessage);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}

View File

@@ -6,7 +6,6 @@ import io.wdd.rpc.message.OctopusMessageType;
import io.wdd.rpc.message.handler.async.AsyncWaitOctopusMessageResultService;
import io.wdd.rpc.message.handler.async.OctopusMessageAsyncReplayContend;
import io.wdd.rpc.message.sender.OMessageToAgentSender;
import io.wdd.rpc.status.OctopusStatusMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@@ -19,6 +18,7 @@ import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import static io.wdd.rpc.init.AgentStatusCacheService.ALL_AGENT_TOPIC_NAME_LIST;
import static io.wdd.rpc.status.OctopusStatusMessage.ConstructAgentStatusMessage;
import static io.wdd.rpc.status.OctopusStatusMessage.HEALTHY_STATUS_MESSAGE_TYPE;
@Slf4j
@@ -30,9 +30,6 @@ public class AsyncStatusServiceImpl implements AsyncStatusService {
@Resource
OMessageToAgentSender oMessageToAgentSender;
@Resource
OctopusStatusMessage octopusStatusMessage;
@Resource
AsyncWaitOctopusMessageResultService asyncWaitOctopusMessageResultService;
@@ -105,7 +102,7 @@ public class AsyncStatusServiceImpl implements AsyncStatusService {
List<OctopusMessage> octopusStatusMessageList = ALL_AGENT_TOPIC_NAME_LIST
.stream()
.map(
agentTopicName -> octopusStatusMessage.ConstructAgentStatusMessage(
agentTopicName -> ConstructAgentStatusMessage(
HEALTHY_STATUS_MESSAGE_TYPE,
agentTopicName,
currentTime