Called when the client wishes to know on which node the next invocation must be performed.
101102103104105106107108109110111
{ target = (InvokerLocator) ((AopLoadBalancePolicy) lb).chooseTarget(family.get(), invocation); } else { target = (InvokerLocator) lb.chooseTarget(family.get()); } } Throwable lastException = null; boolean failoverAuthorized = true;
218219220221222223224225226227228
if (!definitivlyRemoveNodeOnFailure) { family.get().resetView(); } target = (InvokerLocator) lb.chooseTarget(family.get()); if (target == null) { if (lastException != null) { throw new RuntimeException("cluster invocation failed, last exception was: ", lastException);
7172737475767778798081
FamilyClusterInfo fci = ClusteringTargetsRepository.initTarget(FAMILY_BASE + testCount, Arrays.asList(TARGETS)); LoadBalancePolicy lbp = getLoadBalancePolicy(); int expectedCursor = -1; for (int i = 0; i < 100; i++) { Object target = lbp.chooseTarget(fci); if (expectedCursor < 0) { expectedCursor = fci.getCursor(); } else
949596979899100101102103104
testCount++; List<String> targets = new ArrayList<String>(Arrays.asList(TARGETS)); FamilyClusterInfo fci = ClusteringTargetsRepository.initTarget(FAMILY_BASE + testCount, targets); LoadBalancePolicy lbp = getLoadBalancePolicy(); String target = (String) lbp.chooseTarget(fci); int cursor = fci.getCursor(); assertEquals(target, fci.getTargets().get(cursor)); while (targets.size() > 1) {
106107108109110111112113114115116
targets.remove(target); assertEquals(targets, fci.getTargets()); int expectedCursor = ++cursor % targets.size(); target = (String) lbp.chooseTarget(fci); cursor = fci.getCursor(); assertEquals(expectedCursor, cursor); assertEquals(target, fci.getTargets().get(cursor)); } }
120121122123124125126127128129130
testCount++; List<String> targets = Arrays.asList(TARGETS); FamilyClusterInfo fci = ClusteringTargetsRepository.initTarget(FAMILY_BASE + testCount, targets); LoadBalancePolicy lbp = getLoadBalancePolicy(); String target = (String) lbp.chooseTarget(fci); int cursor = fci.getCursor(); assertEquals(target, fci.getTargets().get(cursor)); targets = Arrays.asList(new String[]{"W", "X", "Y", "Z"}); fci.updateClusterInfo(targets, 1);
129130131132133134135136137138139
targets = Arrays.asList(new String[]{"W", "X", "Y", "Z"}); fci.updateClusterInfo(targets, 1); int expectedCursor = ++cursor % targets.size(); target = (String) lbp.chooseTarget(fci); cursor = fci.getCursor(); assertEquals(expectedCursor, cursor); assertEquals(target, targets.get(cursor)); }
7576777879808182838485
Set<Object> selected = new HashSet<Object>(); LoadBalancePolicy lbp = getLoadBalancePolicy(); for (int i = 0; i < 10000; i++) { selected.add(lbp.chooseTarget(fci)); if (selected.size() == TARGETS.length) break; } assertEquals(TARGETS.length, selected.size());
90919293949596979899100
testCount++; List<String> targets = new ArrayList<String>(Arrays.asList(TARGETS)); FamilyClusterInfo fci = ClusteringTargetsRepository.initTarget(FAMILY_BASE + testCount, targets); LoadBalancePolicy lbp = getLoadBalancePolicy(); String target = (String) lbp.chooseTarget(fci); assertTrue(targets.contains(target)); while (targets.size() > 1) { fci.removeDeadTarget(target);
99100101102103104105106107108109
{ fci.removeDeadTarget(target); targets.remove(target); assertEquals(targets, fci.getTargets()); target = (String) lbp.chooseTarget(fci); assertTrue(targets.contains(target)); } } public void testTopologyChange()