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

Change the order in which events are issued #4274

Merged
merged 4 commits into from
Apr 9, 2024
Merged
Changes from 1 commit
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
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2022 the original author or authors.
* Copyright 2013-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -39,6 +39,7 @@

/**
* @author Spencer Gibb
* @author Wonchul Heo
*/
public class InstanceRegistry extends PeerAwareInstanceRegistryImpl implements ApplicationContextAware {

Expand Down Expand Up @@ -78,43 +79,39 @@ public void openForTraffic(ApplicationInfoManager applicationInfoManager, int co

@Override
public void register(InstanceInfo info, int leaseDuration, boolean isReplication) {
handleRegistration(info, leaseDuration, isReplication);
super.register(info, leaseDuration, isReplication);
handleRegistration(info, leaseDuration, isReplication);
}

@Override
public void register(final InstanceInfo info, final boolean isReplication) {
handleRegistration(info, resolveInstanceLeaseDuration(info), isReplication);
super.register(info, isReplication);
handleRegistration(info, resolveInstanceLeaseDuration(info), isReplication);
}

@Override
public boolean cancel(String appName, String serverId, boolean isReplication) {
final boolean cancelled = super.cancel(appName, serverId, isReplication);
handleCancelation(appName, serverId, isReplication);
heowc marked this conversation as resolved.
Show resolved Hide resolved
return super.cancel(appName, serverId, isReplication);
return cancelled;
}

@Override
public boolean renew(final String appName, final String serverId, boolean isReplication) {
log("renew " + appName + " serverId " + serverId + ", isReplication {}" + isReplication);
Application application = getApplication(appName);
if (application != null) {
InstanceInfo instanceInfo = application.getByInstanceId(serverId);
if (instanceInfo != null) {
publishEvent(new EurekaInstanceRenewedEvent(this, appName, serverId, instanceInfo, isReplication));
}
}
return super.renew(appName, serverId, isReplication);
final boolean renewed = super.renew(appName, serverId, isReplication);
handleRenewal(appName, serverId, isReplication);
return renewed;
}

@Override
protected boolean internalCancel(String appName, String id, boolean isReplication) {
final boolean cancelled = super.internalCancel(appName, id, isReplication);
handleCancelation(appName, id, isReplication);
return super.internalCancel(appName, id, isReplication);
return cancelled;
}

private void handleCancelation(String appName, String id, boolean isReplication) {
log("cancel " + appName + ", serverId " + id + ", isReplication " + isReplication);
log("cancelled " + appName + ", serverId " + id + ", isReplication " + isReplication);
publishEvent(new EurekaInstanceCanceledEvent(this, appName, id, isReplication));
}

Expand All @@ -124,6 +121,17 @@ private void handleRegistration(InstanceInfo info, int leaseDuration, boolean is
publishEvent(new EurekaInstanceRegisteredEvent(this, info, leaseDuration, isReplication));
}

private void handleRenewal(final String appName, final String serverId, boolean isReplication) {
log("renew " + appName + " serverId " + serverId + ", isReplication {}" + isReplication);
heowc marked this conversation as resolved.
Show resolved Hide resolved
final Application application = getApplication(appName);
if (application != null) {
final InstanceInfo instanceInfo = application.getByInstanceId(serverId);
if (instanceInfo != null) {
publishEvent(new EurekaInstanceRenewedEvent(this, appName, serverId, instanceInfo, isReplication));
}
}
}

private void log(String message) {
if (log.isDebugEnabled()) {
log.debug(message);
Expand Down