Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【fix】修复注册在未就绪的情况下查询服务名报错的问题 #661

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}
}

Expand All @@ -73,6 +77,10 @@ public void stop() {

@Override
public List<MicroServiceInstance> 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!");
Expand All @@ -83,6 +91,10 @@ public List<MicroServiceInstance> getServerList(String serviceId) {

@Override
public List<String> getServices() {
if (!isRegistered.get()) {
LOGGER.warning("Query instance must be at the stage that finish registry!");
return Collections.emptyList();
}
return RegisterManager.INSTANCE.getServices();
}

Expand Down