Skip to content

Instantly share code, notes, and snippets.

@addozhang
Last active August 8, 2019 07:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save addozhang/9b584470558beb862abeb93e74c1a9b4 to your computer and use it in GitHub Desktop.
Save addozhang/9b584470558beb862abeb93e74c1a9b4 to your computer and use it in GitHub Desktop.
Btrace script for reproducing eureka instance registering starting status
import com.sun.btrace.annotations.BTrace;
import com.sun.btrace.annotations.Kind;
import com.sun.btrace.annotations.Location;
import com.sun.btrace.annotations.OnMethod;
import java.util.concurrent.atomic.AtomicBoolean;
import static com.sun.btrace.BTraceUtils.currentThread;
import static com.sun.btrace.BTraceUtils.println;
/**
* @author Addo.Zhang
* @date 2019-07-31
*/
@BTrace(unsafe = true)
public class EurekaRequest {
public static final AtomicBoolean heartbeatThreadRegistrationStarted = new AtomicBoolean(false);
public static final AtomicBoolean replicatorThreadRegistrationCompleted = new AtomicBoolean(false);
public static final AtomicBoolean statusUP = new AtomicBoolean(false);
@OnMethod(clazz = "org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry", location = @Location(value = Kind.LINE, line = 45))
public static void waitHeartbeatExecution() {
println(currentThread() + " is waiting heartbeatThreadRegistrationStarted thread executing first");
while (!heartbeatThreadRegistrationStarted.get()) ;
}
@OnMethod(clazz = "org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry", location = @Location(value = Kind.LINE, line = 46))
public static void markStatusUp() {
statusUP.set(true);
println("Heartbeat thread executed and " + currentThread() + " continues procedure to change status to [UP]");
}
@OnMethod(clazz = "com.netflix.discovery.converters.EurekaJacksonCodec$InstanceInfoSerializer", location = @Location(value = Kind.LINE, line = 369))
public static void continueRegistrationExecution() {
doExecution();
}
private static void doExecution() {
println(currentThread() + " started to proceed registration");
if (Thread.currentThread().getName().contains("HeartbeatExecutor")) {
heartbeatThreadRegistrationStarted.set(true);
while (!statusUP.get() || !replicatorThreadRegistrationCompleted.get()) {
}
try {
Thread.sleep(500); //interval for replicator registration request completed.
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
} else if (Thread.currentThread().getName().contains("InstanceInfoReplicator")) {
replicatorThreadRegistrationCompleted.set(true);
}
println(currentThread() + " thread registration completed");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment