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. * Registry configuration.
*
* @author chen.ma
* @date 2021/8/12 21:48
*/ */
@Configuration @Configuration
@AllArgsConstructor @AllArgsConstructor

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

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

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

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

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

Loading…
Cancel
Save