Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
spring-boot-admin
Project
Overview
Details
Activity
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
openSource
spring-boot-admin
Commits
c15b3bbc
Commit
c15b3bbc
authored
Dec 24, 2016
by
Johannes Edmeier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change status update to be executed async
parent
fef76a64
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
10 deletions
+29
-10
AdminServerCoreConfiguration.java
...ntric/boot/admin/config/AdminServerCoreConfiguration.java
+2
-3
StatusUpdateApplicationListener.java
.../boot/admin/registry/StatusUpdateApplicationListener.java
+9
-4
StatusUpdateApplicationListenerTest.java
...t/admin/registry/StatusUpdateApplicationListenerTest.java
+18
-3
No files found.
spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/config/AdminServerCoreConfiguration.java
View file @
c15b3bbc
...
...
@@ -23,7 +23,6 @@ import org.springframework.context.annotation.Bean;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
;
import
org.springframework.scheduling.TaskScheduler
;
import
org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler
;
import
org.springframework.web.client.DefaultResponseErrorHandler
;
...
...
@@ -89,7 +88,7 @@ public class AdminServerCoreConfiguration {
@Bean
@Qualifier
(
"updateTaskScheduler"
)
public
TaskScheduler
updateTaskScheduler
()
{
public
T
hreadPoolT
askScheduler
updateTaskScheduler
()
{
ThreadPoolTaskScheduler
taskScheduler
=
new
ThreadPoolTaskScheduler
();
taskScheduler
.
setPoolSize
(
1
);
taskScheduler
.
setRemoveOnCancelPolicy
(
true
);
...
...
@@ -101,7 +100,7 @@ public class AdminServerCoreConfiguration {
@ConditionalOnMissingBean
public
StatusUpdateApplicationListener
statusUpdateApplicationListener
(
StatusUpdater
statusUpdater
,
@Qualifier
(
"updateTaskScheduler"
)
TaskScheduler
taskScheduler
)
{
@Qualifier
(
"updateTaskScheduler"
)
T
hreadPoolT
askScheduler
taskScheduler
)
{
StatusUpdateApplicationListener
listener
=
new
StatusUpdateApplicationListener
(
statusUpdater
,
taskScheduler
);
listener
.
setUpdatePeriod
(
adminServerProperties
.
getMonitor
().
getPeriod
());
...
...
spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/registry/StatusUpdateApplicationListener.java
View file @
c15b3bbc
...
...
@@ -7,20 +7,20 @@ import org.slf4j.LoggerFactory;
import
org.springframework.boot.context.event.ApplicationReadyEvent
;
import
org.springframework.context.event.ContextClosedEvent
;
import
org.springframework.context.event.EventListener
;
import
org.springframework.scheduling.TaskScheduler
;
import
org.springframework.scheduling.
concurrent.ThreadPool
TaskScheduler
;
import
org.springframework.web.context.WebApplicationContext
;
import
de.codecentric.boot.admin.event.ClientApplicationRegisteredEvent
;
public
class
StatusUpdateApplicationListener
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
StatusUpdateApplicationListener
.
class
);
private
final
TaskScheduler
taskScheduler
;
private
final
T
hreadPoolT
askScheduler
taskScheduler
;
private
final
StatusUpdater
statusUpdater
;
private
long
updatePeriod
=
10_000L
;
private
ScheduledFuture
<?>
scheduledTask
;
public
StatusUpdateApplicationListener
(
StatusUpdater
statusUpdater
,
TaskScheduler
taskScheduler
)
{
T
hreadPoolT
askScheduler
taskScheduler
)
{
this
.
statusUpdater
=
statusUpdater
;
this
.
taskScheduler
=
taskScheduler
;
}
...
...
@@ -40,9 +40,14 @@ public class StatusUpdateApplicationListener {
}
@EventListener
public
void
onClientApplicationRegistered
(
ClientApplicationRegisteredEvent
event
)
{
public
void
onClientApplicationRegistered
(
final
ClientApplicationRegisteredEvent
event
)
{
taskScheduler
.
submit
(
new
Runnable
()
{
@Override
public
void
run
()
{
statusUpdater
.
updateStatus
(
event
.
getApplication
());
}
});
}
public
void
startStatusUpdate
()
{
if
(
scheduledTask
!=
null
&&
!
scheduledTask
.
isDone
())
{
...
...
spring-boot-admin-server/src/test/java/de/codecentric/boot/admin/registry/StatusUpdateApplicationListenerTest.java
View file @
c15b3bbc
package
de
.
codecentric
.
boot
.
admin
.
registry
;
import
static
org
.
mockito
.
Matchers
.
any
;
import
static
org
.
mockito
.
Matchers
.
eq
;
import
static
org
.
mockito
.
Matchers
.
isA
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
java.util.concurrent.Future
;
import
java.util.concurrent.ScheduledFuture
;
import
org.junit.Test
;
import
org.mockito.invocation.InvocationOnMock
;
import
org.mockito.stubbing.Answer
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.context.embedded.EmbeddedWebApplicationContext
;
import
org.springframework.boot.context.event.ApplicationReadyEvent
;
import
org.springframework.context.event.ContextClosedEvent
;
import
org.springframework.scheduling.TaskScheduler
;
import
org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler
;
import
org.springframework.util.concurrent.SettableListenableFuture
;
import
org.springframework.web.context.ConfigurableWebApplicationContext
;
import
de.codecentric.boot.admin.event.ClientApplicationRegisteredEvent
;
...
...
@@ -25,7 +30,7 @@ public class StatusUpdateApplicationListenerTest {
@Test
public
void
test_start_stop
()
throws
Exception
{
StatusUpdater
statusUpdater
=
mock
(
StatusUpdater
.
class
);
T
askScheduler
scheduler
=
mock
(
TaskScheduler
.
class
);
T
hreadPoolTaskScheduler
scheduler
=
mock
(
ThreadPool
TaskScheduler
.
class
);
StatusUpdateApplicationListener
listener
=
new
StatusUpdateApplicationListener
(
statusUpdater
,
scheduler
);
...
...
@@ -44,7 +49,17 @@ public class StatusUpdateApplicationListenerTest {
@Test
public
void
test_newApplication
()
throws
Exception
{
StatusUpdater
statusUpdater
=
mock
(
StatusUpdater
.
class
);
TaskScheduler
scheduler
=
mock
(
TaskScheduler
.
class
);
ThreadPoolTaskScheduler
scheduler
=
mock
(
ThreadPoolTaskScheduler
.
class
);
when
(
scheduler
.
submit
(
any
(
Runnable
.
class
))).
then
(
new
Answer
<
Future
<?>>()
{
@Override
public
Future
<?>
answer
(
InvocationOnMock
invocation
)
throws
Throwable
{
invocation
.
getArgumentAt
(
0
,
Runnable
.
class
).
run
();
SettableListenableFuture
<?>
future
=
new
SettableListenableFuture
<
Void
>();
future
.
set
(
null
);
return
future
;
}
});
StatusUpdateApplicationListener
listener
=
new
StatusUpdateApplicationListener
(
statusUpdater
,
scheduler
);
...
...
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