boolean includeRemote = isRemoteRequest(request);
if (pathInfo.startsWith("apps/delta")) {
getDeltaCount.getAndIncrement();
Applications apps = new Applications();
apps.setVersion(100L);
if (sentDelta.compareAndSet(false, true)) {
addDeltaApps(includeRemote, apps);
} else {
System.out.println("Eureka port: " + port + ". " + System.currentTimeMillis() +". Not including delta as it has already been sent.");
}
apps.setAppsHashCode(getDeltaAppsHashCode(includeRemote));
sendOkResponseWithContent((Request) request, response, apps);
handled = true;
} else if(pathInfo.equals("apps/")) {
getFullRegistryCount.getAndIncrement();
Applications apps = new Applications();
apps.setVersion(100L);
for (Application application : applicationMap.values()) {
apps.addApplication(application);
}
if (includeRemote) {
for (Application application : remoteRegionApps.values()) {
apps.addApplication(application);
}
}
if (sentDelta.get()) {
addDeltaApps(includeRemote, apps);
} else {
System.out.println("Eureka port: " + port + ". " + System.currentTimeMillis() +". Not including delta apps in /apps response, as delta has not been sent.");
}
apps.setAppsHashCode(apps.getReconcileHashCode());
sendOkResponseWithContent((Request) request, response, apps);
sentRegistry.set(true);
handled = true;
} else if (pathInfo.startsWith("vips/")) {
getSingleVipCount.getAndIncrement();
String vipAddress = pathInfo.substring("vips/".length());
Applications apps = new Applications();
apps.setVersion(-1l);
for (Application application : applicationMap.values()) {
Application retApp = new Application(application.getName());
for (InstanceInfo instance : application.getInstances()) {
if (vipAddress.equals(instance.getVIPAddress())) {
retApp.addInstance(instance);
}
}
if (retApp.getInstances().size() > 0) {
apps.addApplication(retApp);
}
}
apps.setAppsHashCode(apps.getReconcileHashCode());
sendOkResponseWithContent((Request) request, response, apps);
handled = true;
} else if (pathInfo.startsWith("apps")) { // assume this is the renewal heartbeat
heartbeatCount.getAndIncrement();
sendOkResponseWithContent((Request) request, response, new Applications());
} else {
System.out.println("Not handling request: " + pathInfo);
}
}