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
7a9362d1
Commit
7a9362d1
authored
May 18, 2015
by
Johannes Stelzer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use ApplicationEventPublisher-interface rather than ApplicationContext to publish events
parent
b4b298d7
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
18 deletions
+21
-18
ApplicationRegistry.java
.../codecentric/boot/admin/registry/ApplicationRegistry.java
+13
-11
RegistryControllerTest.java
...centric/boot/admin/controller/RegistryControllerTest.java
+2
-2
ApplicationDiscoveryListenerTest.java
...oot/admin/discovery/ApplicationDiscoveryListenerTest.java
+4
-3
ApplicationRegistryTest.java
...ecentric/boot/admin/registry/ApplicationRegistryTest.java
+2
-2
No files found.
spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/registry/ApplicationRegistry.java
View file @
7a9362d1
...
...
@@ -22,8 +22,8 @@ import java.util.Collection;
import
org.apache.commons.lang3.Validate
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.context.Application
Context
;
import
org.springframework.context.Application
Context
Aware
;
import
org.springframework.context.Application
EventPublisher
;
import
org.springframework.context.Application
EventPublisher
Aware
;
import
org.springframework.util.Assert
;
import
org.springframework.util.StringUtils
;
...
...
@@ -36,14 +36,15 @@ import de.codecentric.boot.admin.registry.store.ApplicationStore;
* Registry for all applications that should be managed/administrated by the Spring Boot Admin application.
* Backed by an ApplicationStore for persistence and an ApplicationIdGenerator for id generation.
*/
public
class
ApplicationRegistry
implements
Application
Context
Aware
{
public
class
ApplicationRegistry
implements
Application
EventPublisher
Aware
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
ApplicationRegistry
.
class
);
private
final
ApplicationStore
store
;
private
final
ApplicationIdGenerator
generator
;
private
Application
Context
context
;
private
Application
EventPublisher
publisher
;
public
ApplicationRegistry
(
ApplicationStore
store
,
ApplicationIdGenerator
generator
)
{
public
ApplicationRegistry
(
ApplicationStore
store
,
ApplicationIdGenerator
generator
)
{
this
.
store
=
store
;
this
.
generator
=
generator
;
}
...
...
@@ -75,10 +76,10 @@ public class ApplicationRegistry implements ApplicationContextAware {
if
(
oldApp
==
null
)
{
LOGGER
.
info
(
"New Application {} registered "
,
newApp
);
context
.
publishEvent
(
new
ClientApplicationRegisteredEvent
(
this
,
newApp
));
publisher
.
publishEvent
(
new
ClientApplicationRegisteredEvent
(
this
,
newApp
));
}
else
{
if
((
newApp
.
getId
().
equals
(
oldApp
.
getId
())
&&
app
.
get
Name
().
equals
(
oldApp
.
get
Name
())))
{
if
((
newApp
.
getId
().
equals
(
oldApp
.
getId
())
&&
app
.
get
HealthUrl
().
equals
(
oldApp
.
get
HealthUrl
())))
{
LOGGER
.
debug
(
"Application {} refreshed"
,
newApp
);
}
else
{
LOGGER
.
warn
(
"Application {} replaced by Application {}"
,
newApp
,
oldApp
);
...
...
@@ -141,13 +142,14 @@ public class ApplicationRegistry implements ApplicationContextAware {
Application
app
=
store
.
delete
(
id
);
if
(
app
!=
null
)
{
LOGGER
.
info
(
"Application {} unregistered "
,
app
);
context
.
publishEvent
(
new
ClientApplicationUnregisteredEvent
(
this
,
app
));
publisher
.
publishEvent
(
new
ClientApplicationUnregisteredEvent
(
this
,
app
));
}
return
app
;
}
@Override
public
void
setApplicationContext
(
ApplicationContext
applicationContext
)
{
this
.
context
=
applicationContext
;
public
void
setApplicationEventPublisher
(
ApplicationEventPublisher
applicationEventPublisher
)
{
publisher
=
applicationEventPublisher
;
}
}
spring-boot-admin-server/src/test/java/de/codecentric/boot/admin/controller/RegistryControllerTest.java
View file @
7a9362d1
...
...
@@ -24,7 +24,7 @@ import java.util.Collection;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.mockito.Mockito
;
import
org.springframework.context.Application
Context
;
import
org.springframework.context.Application
EventPublisher
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
...
...
@@ -42,7 +42,7 @@ public class RegistryControllerTest {
public
void
setup
()
{
registry
=
new
ApplicationRegistry
(
new
SimpleApplicationStore
(),
new
HashingApplicationUrlIdGenerator
());
registry
.
setApplication
Context
(
Mockito
.
mock
(
ApplicationContext
.
class
));
registry
.
setApplication
EventPublisher
(
Mockito
.
mock
(
ApplicationEventPublisher
.
class
));
controller
=
new
RegistryController
(
registry
);
}
...
...
spring-boot-admin-server/src/test/java/de/codecentric/boot/admin/discovery/ApplicationDiscoveryListenerTest.java
View file @
7a9362d1
...
...
@@ -29,7 +29,7 @@ import org.springframework.cloud.client.discovery.DiscoveryClient;
import
org.springframework.cloud.client.discovery.event.HeartbeatEvent
;
import
org.springframework.cloud.client.discovery.event.InstanceRegisteredEvent
;
import
org.springframework.cloud.client.discovery.event.ParentHeartbeatEvent
;
import
org.springframework.context.Application
Context
;
import
org.springframework.context.Application
EventPublisher
;
import
de.codecentric.boot.admin.model.Application
;
import
de.codecentric.boot.admin.registry.ApplicationRegistry
;
...
...
@@ -44,8 +44,9 @@ public class ApplicationDiscoveryListenerTest {
@Before
public
void
setup
()
{
registry
=
new
ApplicationRegistry
(
new
SimpleApplicationStore
(),
new
HashingApplicationUrlIdGenerator
());
registry
.
setApplicationContext
(
mock
(
ApplicationContext
.
class
));
registry
=
new
ApplicationRegistry
(
new
SimpleApplicationStore
(),
new
HashingApplicationUrlIdGenerator
());
registry
.
setApplicationEventPublisher
(
mock
(
ApplicationEventPublisher
.
class
));
discovery
=
mock
(
DiscoveryClient
.
class
);
listener
=
new
ApplicationDiscoveryListener
(
discovery
,
registry
);
}
...
...
spring-boot-admin-server/src/test/java/de/codecentric/boot/admin/registry/ApplicationRegistryTest.java
View file @
7a9362d1
...
...
@@ -24,7 +24,7 @@ import java.util.Collection;
import
org.junit.Test
;
import
org.mockito.Mockito
;
import
org.springframework.context.Application
Context
;
import
org.springframework.context.Application
EventPublisher
;
import
de.codecentric.boot.admin.model.Application
;
import
de.codecentric.boot.admin.registry.store.SimpleApplicationStore
;
...
...
@@ -35,7 +35,7 @@ public class ApplicationRegistryTest {
new
HashingApplicationUrlIdGenerator
());
public
ApplicationRegistryTest
()
{
registry
.
setApplication
Context
(
Mockito
.
mock
(
ApplicationContext
.
class
));
registry
.
setApplication
EventPublisher
(
Mockito
.
mock
(
ApplicationEventPublisher
.
class
));
}
@Test
(
expected
=
IllegalArgumentException
.
class
)
...
...
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