for (Cache c : caches) {
if (c instanceof SecureCacheImpl) {
c = (Cache) extractField(SecureCacheImpl.class, c, "delegate");
}
StateTransferManager stateTransferManager = extractComponent(c, StateTransferManager.class);
DefaultRebalancePolicy rebalancePolicy = (DefaultRebalancePolicy) TestingUtil.extractGlobalComponent(c.getCacheManager(), RebalancePolicy.class);
Address cacheAddress = c.getAdvancedCache().getRpcManager().getAddress();
while (true) {
CacheTopology cacheTopology = stateTransferManager.getCacheTopology();
boolean rebalanceInProgress = stateTransferManager.isStateTransferInProgress();
boolean chIsBalanced = !rebalanceInProgress && rebalancePolicy.isBalanced(cacheTopology.getCurrentCH());
boolean chContainsAllMembers = cacheTopology.getCurrentCH().getMembers().size() == caches.length;
if (chIsBalanced && chContainsAllMembers)
break;
if (System.nanoTime() > giveup) {