hippo4j-discovery code naming and log optimization

pull/481/head
chen.ma 2 years ago
parent d4b0b468cf
commit 6ccecf1d59

@ -25,9 +25,6 @@ import javax.annotation.PostConstruct;
/**
* Registry configuration.
*
* @author chen.ma
* @date 2021/8/12 21:48
*/
@Configuration
@AllArgsConstructor

@ -33,9 +33,6 @@ import static cn.hippo4j.common.constant.Constants.BASE_PATH;
/**
* Application controller.
*
* @author chen.ma
* @date 2021/8/8 22:24
*/
@Slf4j
@RestController

@ -43,13 +43,7 @@ import static cn.hippo4j.common.constant.Constants.SCHEDULED_THREAD_CORE_NUM;
/**
* Base instance registry.
*
* <p>
* Reference from Eureka.
* Service registration, service offline, service renewal.
* </p>
*
* @author chen.ma
* @date 2021/8/8 22:46
* <p> Reference from Eureka. Service registration, service offline, service renewal.
*/
@Slf4j
@Service
@ -65,7 +59,6 @@ public class BaseInstanceRegistry implements InstanceRegistry<InstanceInfo> {
if (CollectionUtils.isEmpty(appNameLeaseMap)) {
return Lists.newArrayList();
}
List<Lease<InstanceInfo>> appNameLeaseList = Lists.newArrayList();
appNameLeaseMap.values().forEach(each -> appNameLeaseList.add(each));
return appNameLeaseList;
@ -81,27 +74,22 @@ public class BaseInstanceRegistry implements InstanceRegistry<InstanceInfo> {
registerMap = registerNewMap;
}
}
Lease<InstanceInfo> existingLease = registerMap.get(registrant.getInstanceId());
if (existingLease != null && (existingLease.getHolder() != null)) {
Long existingLastDirtyTimestamp = existingLease.getHolder().getLastDirtyTimestamp();
Long registrationLastDirtyTimestamp = registrant.getLastDirtyTimestamp();
if (existingLastDirtyTimestamp > registrationLastDirtyTimestamp) {
registrant = existingLease.getHolder();
}
}
Lease<InstanceInfo> lease = new Lease(registrant);
if (existingLease != null) {
lease.setServiceUpTimestamp(existingLease.getServiceUpTimestamp());
}
registerMap.put(registrant.getInstanceId(), lease);
if (InstanceStatus.UP.equals(registrant.getStatus())) {
lease.serviceUp();
}
registrant.setActionType(InstanceInfo.ActionType.ADDED);
registrant.setLastUpdatedTimestamp();
}

@ -26,9 +26,6 @@ import org.springframework.stereotype.Component;
/**
* Client close hook remove node.
*
* @author chen.ma
* @date 2022/1/6 22:24
*/
@Slf4j
@Component
@ -38,13 +35,11 @@ public class ClientCloseHookRemoveNode implements ClientCloseHookExecute {
private final InstanceRegistry instanceRegistry;
@Override
public void closeHook(ClientCloseHookReq req) {
log.info(
"Remove Node, Execute client hook function. Req :: {}",
JSONUtil.toJSONString(req));
public void closeHook(ClientCloseHookReq requestParam) {
log.info("Remove Node, Execute client hook function. Request: {}", JSONUtil.toJSONString(requestParam));
try {
InstanceInfo instanceInfo = new InstanceInfo();
instanceInfo.setAppName(req.getAppName()).setInstanceId(req.getInstanceId());
instanceInfo.setAppName(requestParam.getAppName()).setInstanceId(requestParam.getInstanceId());
instanceRegistry.remove(instanceInfo);
} catch (Exception ex) {
log.error("Failed to delete node hook.", ex);

@ -23,9 +23,6 @@ import java.util.List;
/**
* Instance registry.
*
* @author chen.ma
* @date 2021/8/8 22:31
*/
public interface InstanceRegistry<T> {

@ -19,9 +19,6 @@ package cn.hippo4j.discovery.core;
/**
* Lease.
*
* @author chen.ma
* @date 2021/8/8 22:49
*/
public class Lease<T> {

Loading…
Cancel
Save