From df4558837ddd452bce08d2a7bbc2ed8fb94e60a7 Mon Sep 17 00:00:00 2001 From: justforstudy <2167005981@qq.com> Date: Tue, 23 Aug 2022 15:36:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B3=A8=E5=86=8C=E5=9C=A8?= =?UTF-8?q?=E6=9C=AA=E5=B0=B1=E7=BB=AA=E7=9A=84=E6=83=85=E5=86=B5=E4=B8=8B?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=9C=8D=E5=8A=A1=E5=90=8D=E6=8A=A5=E9=94=99?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/RegisterCenterServiceImpl.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/sermant-plugins/sermant-service-registry/spring-cloud-registry-service/src/main/java/com/huawei/registry/service/impl/RegisterCenterServiceImpl.java b/sermant-plugins/sermant-service-registry/spring-cloud-registry-service/src/main/java/com/huawei/registry/service/impl/RegisterCenterServiceImpl.java index ffc1780aae..cefbf38f8d 100644 --- a/sermant-plugins/sermant-service-registry/spring-cloud-registry-service/src/main/java/com/huawei/registry/service/impl/RegisterCenterServiceImpl.java +++ b/sermant-plugins/sermant-service-registry/spring-cloud-registry-service/src/main/java/com/huawei/registry/service/impl/RegisterCenterServiceImpl.java @@ -41,6 +41,8 @@ public class RegisterCenterServiceImpl implements RegisterCenterService { private final AtomicBoolean isStopped = new AtomicBoolean(); + private final AtomicBoolean isRegistered = new AtomicBoolean(); + private RegisterConfig registerConfig; @Override @@ -52,10 +54,12 @@ public void start() { @Override public void register(FixedResult result) { - RegisterManager.INSTANCE.register(); - if (!getRegisterConfig().isOpenMigration()) { - // 阻止原注册中心注册 - result.setResult(null); + if (isRegistered.compareAndSet(false, true)) { + RegisterManager.INSTANCE.register(); + if (!getRegisterConfig().isOpenMigration()) { + // 阻止原注册中心注册 + result.setResult(null); + } } } @@ -73,6 +77,10 @@ public void stop() { @Override public List getServerList(String serviceId) { + if (!isRegistered.get()) { + LOGGER.warning("Query instance must be at the stage that finish registry!"); + return Collections.emptyList(); + } if (serviceId == null) { // 无法执行替换 LOGGER.warning("Can not acquire the name of service, the process to replace instance won't be finished!"); @@ -83,6 +91,10 @@ public List getServerList(String serviceId) { @Override public List getServices() { + if (!isRegistered.get()) { + LOGGER.warning("Query instance must be at the stage that finish registry!"); + return Collections.emptyList(); + } return RegisterManager.INSTANCE.getServices(); }