Merge branch '1.5.x'

This commit is contained in:
Phillip Webb
2017-07-06 18:38:52 -07:00
24 changed files with 188 additions and 172 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -69,8 +69,12 @@ public class HealthEndpoint extends AbstractEndpoint<Health> {
return this.timeToLive;
}
public void setTimeToLive(long ttl) {
this.timeToLive = ttl;
/**
* Set the time to live for cached results.
* @param timeToLive the time to live in milliseconds
*/
public void setTimeToLive(long timeToLive) {
this.timeToLive = timeToLive;
}
/**

View File

@@ -171,20 +171,13 @@ public class HealthMvcEndpoint extends AbstractEndpointMvcAdapter<HealthEndpoint
private Health getCurrentHealth() {
long accessTime = System.currentTimeMillis();
CachedHealth cachedHealth = this.cachedHealth;
if (isStale(cachedHealth, accessTime)) {
CachedHealth cached = this.cachedHealth;
if (cached == null || cached.isStale(accessTime, getDelegate().getTimeToLive())) {
Health health = getDelegate().invoke();
this.cachedHealth = new CachedHealth(health, accessTime);
return health;
}
return cachedHealth.health;
}
private boolean isStale(CachedHealth cachedHealth, long accessTime) {
if (cachedHealth == null) {
return true;
}
return (accessTime - cachedHealth.creationTime) >= getDelegate().getTimeToLive();
return cached.getHealth();
}
protected boolean exposeHealthDetails(HttpServletRequest request,
@@ -234,6 +227,14 @@ public class HealthMvcEndpoint extends AbstractEndpointMvcAdapter<HealthEndpoint
this.creationTime = creationTime;
}
public boolean isStale(long accessTime, long timeToLive) {
return (accessTime - this.creationTime) >= timeToLive;
}
public Health getHealth() {
return this.health;
}
}
}