Skip to content

Commit e83f4d8

Browse files
author
arnett, stu
committed
v2.0.3
1 parent ea256e8 commit e83f4d8

15 files changed

+83
-11
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ description = 'Smart REST Client - JAX-RS (Jersey) REST client that provides cli
2929
ext.githubProjectName = 'smart-client-java'
3030

3131
buildscript {
32-
ext.commonBuildVersion = '1.3.2'
32+
ext.commonBuildVersion = '1.3.3'
3333
ext.commonBuildDir = "https://raw.githubusercontent.com/emcvipr/ecs-common-build/v$commonBuildVersion"
3434
apply from: "$commonBuildDir/ecs-publish.buildscript.gradle", to: buildscript
3535
}
@@ -39,7 +39,7 @@ apply from: "$commonBuildDir/ecs-publish.gradle"
3939
dependencies {
4040
compile 'com.sun.jersey:jersey-client:1.19',
4141
'com.sun.jersey.contribs:jersey-apache-client4:1.19',
42-
'org.apache.httpcomponents:httpclient:4.5',
42+
'org.apache.httpcomponents:httpclient:4.2.6',
4343
'log4j:log4j:1.2.17'
4444
testCompile 'junit:junit:4.12'
4545
}

src/main/java/com/emc/rest/smart/HostListProvider.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,13 @@ public interface HostListProvider {
3737
* (<code>host.setHealthy(false)</code> is called).
3838
*/
3939
void runHealthCheck(Host host);
40+
41+
/**
42+
* Destroy this provider. Any system resources associated with the provider
43+
* will be cleaned up.
44+
* <p/>
45+
* The provider must not be reused after this method is called otherwise
46+
* undefined behavior will occur.
47+
*/
48+
void destroy();
4049
}

src/main/java/com/emc/rest/smart/LoadBalancer.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,16 @@ public LoadBalancer(List<Host> initialHosts) {
4242
* Returns the host with the lowest response index.
4343
*/
4444
public Host getTopHost(Map<String, Object> requestProperties) {
45-
Host topHost = null;
45+
Host topHost = null, topHealthyHost = null;
4646

47-
long lowestIndex = Long.MAX_VALUE;
47+
long lowestIndex = Long.MAX_VALUE, lowestHealthyIndex = Long.MAX_VALUE;
4848

4949
synchronized (hosts) {
5050
for (Host host : hosts) {
5151

5252
// apply any veto rules
5353
if (shouldVeto(host, requestProperties)) continue;
5454

55-
// if the host is unhealthy/down, ignore it
56-
if (!host.isHealthy()) continue;
57-
5855
// get response index for a host
5956
long hostIndex = host.getResponseIndex();
6057

@@ -63,8 +60,17 @@ public Host getTopHost(Map<String, Object> requestProperties) {
6360
topHost = host;
6461
lowestIndex = hostIndex;
6562
}
63+
64+
// also keep track of the top *healthy* host
65+
if (host.isHealthy() && hostIndex < lowestHealthyIndex) {
66+
topHealthyHost = host;
67+
lowestHealthyIndex = hostIndex;
68+
}
6669
}
6770

71+
// if there are no healthy hosts, we still need a host to contact
72+
if (topHealthyHost != null) topHost = topHealthyHost;
73+
6874
// move the top host to the end of the host list as an extra tie-breaker
6975
hosts.remove(topHost);
7076
hosts.add(topHost);

0 commit comments

Comments
 (0)