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
e7fd7a53
Commit
e7fd7a53
authored
Aug 24, 2015
by
Johannes Stelzer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Execute registration on startup asynchronously to not block startup
parent
0bd7eee3
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
26 deletions
+37
-26
RegistrationApplicationListener.java
.../boot/admin/services/RegistrationApplicationListener.java
+17
-6
RegistrationApplicationListenerTest.java
...t/admin/services/RegistrationApplicationListenerTest.java
+20
-20
No files found.
spring-boot-admin-starter-client/src/main/java/de/codecentric/boot/admin/services/RegistrationApplicationListener.java
View file @
e7fd7a53
...
@@ -9,27 +9,39 @@ import org.springframework.context.event.ContextClosedEvent;
...
@@ -9,27 +9,39 @@ import org.springframework.context.event.ContextClosedEvent;
import
org.springframework.context.event.ContextRefreshedEvent
;
import
org.springframework.context.event.ContextRefreshedEvent
;
import
org.springframework.core.Ordered
;
import
org.springframework.core.Ordered
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.core.task.SimpleAsyncTaskExecutor
;
import
org.springframework.core.task.TaskExecutor
;
import
de.codecentric.boot.admin.config.AdminProperties
;
import
de.codecentric.boot.admin.config.AdminProperties
;
@Order
(
Ordered
.
LOWEST_PRECEDENCE
)
@Order
(
Ordered
.
LOWEST_PRECEDENCE
)
public
class
RegistrationApplicationListener
implements
public
class
RegistrationApplicationListener
implements
ApplicationListener
<
ApplicationEvent
>
{
ApplicationListener
<
ApplicationEvent
>
{
private
final
AdminProperties
admin
;
private
final
AdminProperties
admin
;
private
final
ApplicationRegistrator
registrator
;
private
final
ApplicationRegistrator
registrator
;
private
final
TaskExecutor
executor
;
public
RegistrationApplicationListener
(
AdminProperties
admin
,
public
RegistrationApplicationListener
(
AdminProperties
admin
,
ApplicationRegistrator
registrator
)
{
ApplicationRegistrator
registrator
,
TaskExecutor
executor
)
{
this
.
admin
=
admin
;
this
.
admin
=
admin
;
this
.
registrator
=
registrator
;
this
.
registrator
=
registrator
;
this
.
executor
=
executor
;
}
public
RegistrationApplicationListener
(
AdminProperties
admin
,
ApplicationRegistrator
registrator
)
{
this
(
admin
,
registrator
,
new
SimpleAsyncTaskExecutor
());
}
}
@Override
public
void
onApplicationEvent
(
ApplicationEvent
event
)
{
public
void
onApplicationEvent
(
ApplicationEvent
event
)
{
if
(
startedDeployedWar
(
event
)
||
startedEmbeddedServer
(
event
))
{
if
(
startedDeployedWar
(
event
)
||
startedEmbeddedServer
(
event
))
{
executor
.
execute
(
new
Runnable
()
{
@Override
public
void
run
()
{
registrator
.
register
();
registrator
.
register
();
}
}
else
if
(
admin
.
isAutoDeregistration
()
});
&&
event
instanceof
ContextClosedEvent
)
{
}
else
if
(
admin
.
isAutoDeregistration
()
&&
event
instanceof
ContextClosedEvent
)
{
registrator
.
deregister
();
registrator
.
deregister
();
}
}
}
}
...
@@ -50,4 +62,3 @@ ApplicationListener<ApplicationEvent> {
...
@@ -50,4 +62,3 @@ ApplicationListener<ApplicationEvent> {
return
false
;
return
false
;
}
}
}
}
spring-boot-admin-starter-client/src/test/java/de/codecentric/boot/admin/services/RegistrationApplicationListenerTest.java
View file @
e7fd7a53
...
@@ -12,6 +12,7 @@ import org.springframework.boot.context.embedded.EmbeddedServletContainerInitial
...
@@ -12,6 +12,7 @@ import org.springframework.boot.context.embedded.EmbeddedServletContainerInitial
import
org.springframework.boot.context.embedded.EmbeddedWebApplicationContext
;
import
org.springframework.boot.context.embedded.EmbeddedWebApplicationContext
;
import
org.springframework.context.event.ContextClosedEvent
;
import
org.springframework.context.event.ContextClosedEvent
;
import
org.springframework.context.event.ContextRefreshedEvent
;
import
org.springframework.context.event.ContextRefreshedEvent
;
import
org.springframework.core.task.SyncTaskExecutor
;
import
de.codecentric.boot.admin.config.AdminProperties
;
import
de.codecentric.boot.admin.config.AdminProperties
;
...
@@ -27,12 +28,11 @@ public class RegistrationApplicationListenerTest {
...
@@ -27,12 +28,11 @@ public class RegistrationApplicationListenerTest {
@Test
@Test
public
void
test_register_embedded
()
{
public
void
test_register_embedded
()
{
ApplicationRegistrator
registrator
=
mock
(
ApplicationRegistrator
.
class
);
ApplicationRegistrator
registrator
=
mock
(
ApplicationRegistrator
.
class
);
RegistrationApplicationListener
listener
=
new
RegistrationApplicationListener
(
RegistrationApplicationListener
listener
=
new
RegistrationApplicationListener
(
admin
,
admin
,
registrator
);
registrator
,
new
SyncTaskExecutor
()
);
listener
.
onApplicationEvent
(
new
EmbeddedServletContainerInitializedEvent
(
listener
.
onApplicationEvent
(
new
EmbeddedServletContainerInitializedEvent
(
mock
(
EmbeddedWebApplicationContext
.
class
),
mock
(
EmbeddedWebApplicationContext
.
class
),
mock
(
EmbeddedServletContainer
.
class
)));
mock
(
EmbeddedServletContainer
.
class
)));
verify
(
registrator
).
register
();
verify
(
registrator
).
register
();
}
}
...
@@ -40,11 +40,11 @@ public class RegistrationApplicationListenerTest {
...
@@ -40,11 +40,11 @@ public class RegistrationApplicationListenerTest {
@Test
@Test
public
void
test_register_war
()
{
public
void
test_register_war
()
{
ApplicationRegistrator
registrator
=
mock
(
ApplicationRegistrator
.
class
);
ApplicationRegistrator
registrator
=
mock
(
ApplicationRegistrator
.
class
);
RegistrationApplicationListener
listener
=
new
RegistrationApplicationListener
(
RegistrationApplicationListener
listener
=
new
RegistrationApplicationListener
(
admin
,
admin
,
registrator
);
registrator
,
new
SyncTaskExecutor
()
);
listener
.
onApplicationEvent
(
new
ContextRefreshedEvent
(
listener
.
onApplicationEvent
(
mock
(
EmbeddedWebApplicationContext
.
class
)));
new
ContextRefreshedEvent
(
mock
(
EmbeddedWebApplicationContext
.
class
)));
verify
(
registrator
).
register
();
verify
(
registrator
).
register
();
}
}
...
@@ -52,12 +52,12 @@ public class RegistrationApplicationListenerTest {
...
@@ -52,12 +52,12 @@ public class RegistrationApplicationListenerTest {
@Test
@Test
public
void
test_no_register_war
()
{
public
void
test_no_register_war
()
{
ApplicationRegistrator
registrator
=
mock
(
ApplicationRegistrator
.
class
);
ApplicationRegistrator
registrator
=
mock
(
ApplicationRegistrator
.
class
);
RegistrationApplicationListener
listener
=
new
RegistrationApplicationListener
(
RegistrationApplicationListener
listener
=
new
RegistrationApplicationListener
(
admin
,
admin
,
registrator
);
registrator
,
new
SyncTaskExecutor
()
);
EmbeddedWebApplicationContext
context
=
mock
(
EmbeddedWebApplicationContext
.
class
);
EmbeddedWebApplicationContext
context
=
mock
(
EmbeddedWebApplicationContext
.
class
);
when
(
context
.
getEmbeddedServletContainer
())
.
thenReturn
(
when
(
context
.
getEmbeddedServletContainer
())
mock
(
EmbeddedServletContainer
.
class
));
.
thenReturn
(
mock
(
EmbeddedServletContainer
.
class
));
listener
.
onApplicationEvent
(
new
ContextRefreshedEvent
(
context
));
listener
.
onApplicationEvent
(
new
ContextRefreshedEvent
(
context
));
verify
(
registrator
,
never
()).
register
();
verify
(
registrator
,
never
()).
register
();
...
@@ -66,11 +66,11 @@ public class RegistrationApplicationListenerTest {
...
@@ -66,11 +66,11 @@ public class RegistrationApplicationListenerTest {
@Test
@Test
public
void
test_no_deregister
()
{
public
void
test_no_deregister
()
{
ApplicationRegistrator
registrator
=
mock
(
ApplicationRegistrator
.
class
);
ApplicationRegistrator
registrator
=
mock
(
ApplicationRegistrator
.
class
);
RegistrationApplicationListener
listener
=
new
RegistrationApplicationListener
(
RegistrationApplicationListener
listener
=
new
RegistrationApplicationListener
(
admin
,
admin
,
registrator
);
registrator
,
new
SyncTaskExecutor
()
);
listener
.
onApplicationEvent
(
new
ContextClosedEvent
(
listener
.
onApplicationEvent
(
mock
(
EmbeddedWebApplicationContext
.
class
)));
new
ContextClosedEvent
(
mock
(
EmbeddedWebApplicationContext
.
class
)));
verify
(
registrator
,
never
()).
deregister
();
verify
(
registrator
,
never
()).
deregister
();
}
}
...
@@ -78,13 +78,13 @@ public class RegistrationApplicationListenerTest {
...
@@ -78,13 +78,13 @@ public class RegistrationApplicationListenerTest {
@Test
@Test
public
void
test_deregister
()
{
public
void
test_deregister
()
{
ApplicationRegistrator
registrator
=
mock
(
ApplicationRegistrator
.
class
);
ApplicationRegistrator
registrator
=
mock
(
ApplicationRegistrator
.
class
);
RegistrationApplicationListener
listener
=
new
RegistrationApplicationListener
(
RegistrationApplicationListener
listener
=
new
RegistrationApplicationListener
(
admin
,
admin
,
registrator
);
registrator
);
admin
.
setAutoDeregistration
(
true
);
admin
.
setAutoDeregistration
(
true
);
listener
.
onApplicationEvent
(
new
ContextClosedEvent
(
listener
.
onApplicationEvent
(
mock
(
EmbeddedWebApplicationContext
.
class
)));
new
ContextClosedEvent
(
mock
(
EmbeddedWebApplicationContext
.
class
)));
verify
(
registrator
).
deregister
();
verify
(
registrator
).
deregister
();
}
}
...
...
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