Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
39c1757a
Commit
39c1757a
authored
Jun 21, 2017
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.5.x'
parents
b41c5d6a
7a04708c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
13 deletions
+35
-13
HealthMvcEndpoint.java
...ramework/boot/actuate/endpoint/mvc/HealthMvcEndpoint.java
+35
-13
No files found.
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/HealthMvcEndpoint.java
View file @
39c1757a
...
...
@@ -59,9 +59,7 @@ public class HealthMvcEndpoint extends AbstractEndpointMvcAdapter<HealthEndpoint
private
Map
<
String
,
HttpStatus
>
statusMapping
=
new
HashMap
<>();
private
long
lastAccess
=
0
;
private
Health
cached
;
private
volatile
CachedHealth
cachedHealth
;
public
HealthMvcEndpoint
(
HealthEndpoint
delegate
)
{
this
(
delegate
,
true
);
...
...
@@ -164,22 +162,29 @@ public class HealthMvcEndpoint extends AbstractEndpointMvcAdapter<HealthEndpoint
}
private
Health
getHealth
(
HttpServletRequest
request
,
Principal
principal
)
{
long
accessTime
=
System
.
currentTimeMillis
();
if
(
isCacheStale
(
accessTime
))
{
this
.
lastAccess
=
accessTime
;
this
.
cached
=
getDelegate
().
invoke
();
}
Health
currentHealth
=
getCurrentHealth
();
if
(
exposeHealthDetails
(
request
,
principal
))
{
return
this
.
cached
;
return
this
.
cachedHealth
.
health
;
}
return
Health
.
status
(
currentHealth
.
getStatus
()).
build
();
}
private
Health
getCurrentHealth
()
{
long
accessTime
=
System
.
currentTimeMillis
();
CachedHealth
cachedHealth
=
this
.
cachedHealth
;
if
(
isStale
(
cachedHealth
,
accessTime
))
{
Health
health
=
getDelegate
().
invoke
();
this
.
cachedHealth
=
new
CachedHealth
(
health
,
accessTime
);
return
health
;
}
return
Health
.
status
(
this
.
cached
.
getStatus
()).
build
()
;
return
cachedHealth
.
health
;
}
private
boolean
is
CacheStale
(
long
accessTime
)
{
if
(
this
.
cached
==
null
)
{
private
boolean
is
Stale
(
CachedHealth
cachedHealth
,
long
accessTime
)
{
if
(
cachedHealth
==
null
)
{
return
true
;
}
return
(
accessTime
-
this
.
lastAccess
)
>=
getDelegate
().
getTimeToLive
();
return
(
accessTime
-
cachedHealth
.
creationTime
)
>=
getDelegate
().
getTimeToLive
();
}
protected
boolean
exposeHealthDetails
(
HttpServletRequest
request
,
...
...
@@ -214,4 +219,21 @@ public class HealthMvcEndpoint extends AbstractEndpointMvcAdapter<HealthEndpoint
null
)
&&
principal
instanceof
Authentication
;
}
/**
* A cached {@link Health} that encapsulates the {@code Health} itself and the time at
* which it was created.
*/
static
class
CachedHealth
{
private
final
Health
health
;
private
final
long
creationTime
;
CachedHealth
(
Health
health
,
long
creationTime
)
{
this
.
health
=
health
;
this
.
creationTime
=
creationTime
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment