instanceInfoList = new ArrayList<InstanceInfo>(instances);
}
if (indexByRemoteRegions || filterUpInstances) {
Iterator<InstanceInfo> it = instanceInfoList.iterator();
while (it.hasNext()) {
InstanceInfo instanceInfo = it.next();
if (filterUpInstances && !InstanceStatus.UP.equals(instanceInfo.getStatus())) {
it.remove();
} else if (indexByRemoteRegions && null != instanceRegionChecker && null != clientConfig
&& null != remoteRegionsRegistry) {
String instanceRegion = instanceRegionChecker.getInstanceRegion(instanceInfo);
if (!instanceRegionChecker.isLocalRegion(instanceRegion)) {
Applications appsForRemoteRegion = remoteRegionsRegistry.get(instanceRegion);
if (null == appsForRemoteRegion) {
appsForRemoteRegion = new Applications();
remoteRegionsRegistry.put(instanceRegion, appsForRemoteRegion);
}
Application remoteApp =
appsForRemoteRegion.getRegisteredApplications(instanceInfo.getAppName());
if (null == remoteApp) {
remoteApp = new Application(instanceInfo.getAppName());
appsForRemoteRegion.addApplication(remoteApp);
}
remoteApp.addInstance(instanceInfo);
this.removeInstance(instanceInfo, false);