Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
spring-cloud-netflix
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-cloud-netflix
Commits
88f79507
Commit
88f79507
authored
Jul 27, 2014
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix race condition in server
parent
98d0da97
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
73 additions
and
8 deletions
+73
-8
EurekaClientAutoConfiguration.java
...latform/netflix/eureka/EurekaClientAutoConfiguration.java
+42
-7
EurekaServerAutoConfiguration.java
...latform/netflix/eureka/EurekaServerAutoConfiguration.java
+9
-1
EurekaClientConfigBeanTests.java
.../platform/netflix/eureka/EurekaClientConfigBeanTests.java
+22
-0
No files found.
spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/eureka/EurekaClientAutoConfiguration.java
View file @
88f79507
...
...
@@ -15,7 +15,6 @@
*/
package
org
.
springframework
.
platform
.
netflix
.
eureka
;
import
javax.annotation.PostConstruct
;
import
javax.annotation.PreDestroy
;
import
org.slf4j.Logger
;
...
...
@@ -25,8 +24,10 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnExpression
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.context.ApplicationListener
;
import
org.springframework.context.SmartLifecycle
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.event.ContextRefreshedEvent
;
import
org.springframework.core.Ordered
;
import
com.netflix.appinfo.ApplicationInfoManager
;
import
com.netflix.appinfo.InstanceInfo.InstanceStatus
;
...
...
@@ -43,10 +44,14 @@ import com.netflix.discovery.EurekaClientConfig;
@ConditionalOnClass
(
EurekaClientConfig
.
class
)
@ConditionalOnExpression
(
"${eureka.client.enabled:true}"
)
public
class
EurekaClientAutoConfiguration
implements
ApplicationListener
<
ContextRefreshedEvent
>
{
ApplicationListener
<
ContextRefreshedEvent
>
,
SmartLifecycle
,
Ordered
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
EurekaClientAutoConfiguration
.
class
);
private
boolean
running
;
private
int
order
=
0
;
@Autowired
private
EurekaClientConfigBean
clientConfig
;
...
...
@@ -59,15 +64,45 @@ public class EurekaClientAutoConfiguration implements
ApplicationInfoManager
.
getInstance
().
setInstanceStatus
(
InstanceStatus
.
UP
);
}
@PostConstruct
public
void
init
()
{
DiscoveryManager
.
getInstance
().
initComponent
(
instanceConfig
,
clientConfig
);
}
@PreDestroy
public
void
close
()
{
logger
.
info
(
"Removing application {} from eureka"
,
instanceConfig
.
getAppname
());
DiscoveryManager
.
getInstance
().
shutdownComponent
();
}
@Override
public
void
start
()
{
DiscoveryManager
.
getInstance
().
initComponent
(
instanceConfig
,
clientConfig
);
}
@Override
public
void
stop
()
{
running
=
false
;
}
@Override
public
boolean
isRunning
()
{
return
running
;
}
@Override
public
int
getPhase
()
{
return
0
;
}
@Override
public
boolean
isAutoStartup
()
{
return
true
;
}
@Override
public
void
stop
(
Runnable
callback
)
{
callback
.
run
();
}
@Override
public
int
getOrder
()
{
return
order
;
}
}
spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/eureka/EurekaServerAutoConfiguration.java
View file @
88f79507
...
...
@@ -25,6 +25,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.SmartLifecycle
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.core.Ordered
;
import
org.springframework.web.context.ServletContextAware
;
import
com.netflix.blitz4j.LoggingConfiguration
;
...
...
@@ -42,7 +43,7 @@ import com.netflix.eureka.PeerAwareInstanceRegistry;
@ConditionalOnClass
(
EurekaServerConfig
.
class
)
@ConditionalOnExpression
(
"${eureka.server.enabled:true}"
)
public
class
EurekaServerAutoConfiguration
implements
ServletContextAware
,
SmartLifecycle
{
SmartLifecycle
,
Ordered
{
@Autowired
private
EurekaServerConfig
eurekaServerConfig
;
...
...
@@ -54,6 +55,8 @@ public class EurekaServerAutoConfiguration implements ServletContextAware,
private
boolean
running
;
private
int
order
=
0
;
@Override
public
void
setServletContext
(
ServletContext
servletContext
)
{
this
.
servletContext
=
servletContext
;
...
...
@@ -105,4 +108,9 @@ public class EurekaServerAutoConfiguration implements ServletContextAware,
callback
.
run
();
}
@Override
public
int
getOrder
()
{
return
order
;
}
}
spring-platform-netflix-core/src/test/java/org/springframework/platform/netflix/eureka/EurekaClientConfigBeanTests.java
View file @
88f79507
...
...
@@ -17,6 +17,8 @@ package org.springframework.platform.netflix.eureka;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
java.util.Collections
;
import
org.junit.After
;
import
org.junit.Test
;
import
org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration
;
...
...
@@ -24,6 +26,8 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
import
org.springframework.boot.test.EnvironmentTestUtils
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.core.env.CompositePropertySource
;
import
org.springframework.core.env.MapPropertySource
;
/**
* @author Dave Syer
...
...
@@ -67,6 +71,24 @@ public class EurekaClientConfigBeanTests {
}
@Test
public
void
serviceUrlWithCompositePropertySource
()
{
CompositePropertySource
source
=
new
CompositePropertySource
(
"composite"
);
context
.
getEnvironment
().
getPropertySources
().
addFirst
(
source
);
source
.
addPropertySource
(
new
MapPropertySource
(
"config"
,
Collections
.<
String
,
Object
>
singletonMap
(
"eureka.client.serviceUrl.defaultZone"
,
"http://example.com"
)));
context
.
register
(
PropertyPlaceholderAutoConfiguration
.
class
,
TestConfiguration
.
class
);
context
.
refresh
();
assertEquals
(
"{defaultZone=http://example.com}"
,
context
.
getBean
(
EurekaClientConfigBean
.
class
).
getServiceUrl
().
toString
());
assertEquals
(
"[http://example.com]"
,
context
.
getBean
(
EurekaClientConfigBean
.
class
)
.
getEurekaServerServiceUrls
(
"defaultZone"
).
toString
());
}
@Test
public
void
serviceUrlWithDefault
()
{
EnvironmentTestUtils
.
addEnvironment
(
context
,
"eureka.client.serviceUrl.defaultZone:"
,
...
...
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