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
71d0a474
Commit
71d0a474
authored
Dec 16, 2014
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleanup threads in DiscoveryClient.jerseyClient and ServoMetricCollector
parent
d4d1fe7f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
1 deletion
+34
-1
EurekaDiscoveryClientConfiguration.java
...ud/netflix/eureka/EurekaDiscoveryClientConfiguration.java
+22
-0
ServoMetricCollector.java
...ngframework/cloud/netflix/servo/ServoMetricCollector.java
+12
-1
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/eureka/EurekaDiscoveryClientConfiguration.java
View file @
71d0a474
...
...
@@ -19,6 +19,7 @@ import javax.annotation.PreDestroy;
import
com.netflix.appinfo.EurekaInstanceConfig
;
import
com.netflix.appinfo.HealthCheckHandler
;
import
com.netflix.discovery.shared.EurekaJerseyClient
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -45,7 +46,9 @@ import com.netflix.appinfo.ApplicationInfoManager;
import
com.netflix.appinfo.InstanceInfo.InstanceStatus
;
import
com.netflix.discovery.DiscoveryManager
;
import
com.netflix.discovery.EurekaClientConfig
;
import
org.springframework.util.ReflectionUtils
;
import
java.lang.reflect.Field
;
import
java.util.concurrent.atomic.AtomicBoolean
;
import
java.util.concurrent.atomic.AtomicInteger
;
...
...
@@ -79,10 +82,29 @@ public class EurekaDiscoveryClientConfiguration implements SmartLifecycle, Order
@PreDestroy
public
void
close
()
{
closeDiscoveryClientJersey
();
logger
.
info
(
"Removing application {} from eureka"
,
instanceConfig
.
getAppname
());
DiscoveryManager
.
getInstance
().
shutdownComponent
();
}
private
void
closeDiscoveryClientJersey
()
{
logger
.
info
(
"Closing DiscoveryClient.jerseyClient"
);
Field
jerseyClientField
=
ReflectionUtils
.
findField
(
com
.
netflix
.
discovery
.
DiscoveryClient
.
class
,
"discoveryJerseyClient"
,
EurekaJerseyClient
.
JerseyClient
.
class
);
if
(
jerseyClientField
!=
null
)
{
try
{
jerseyClientField
.
setAccessible
(
true
);
Object
obj
=
jerseyClientField
.
get
(
DiscoveryManager
.
getInstance
().
getDiscoveryClient
());
EurekaJerseyClient
.
JerseyClient
jerseyClient
=
(
EurekaJerseyClient
.
JerseyClient
)
obj
;
jerseyClient
.
destroyResources
();
}
catch
(
Exception
e
)
{
logger
.
error
(
"Error closing DiscoveryClient.jerseyClient"
,
e
);
}
}
}
@Override
public
void
start
()
{
//only set the port if the nonSecurePort is 0 and this.port != 0
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/servo/ServoMetricCollector.java
View file @
71d0a474
...
...
@@ -21,6 +21,8 @@ import java.util.Date;
import
java.util.List
;
import
java.util.concurrent.TimeUnit
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.DisposableBean
;
import
org.springframework.boot.actuate.metrics.Metric
;
import
org.springframework.boot.actuate.metrics.reader.MetricReader
;
import
org.springframework.boot.actuate.metrics.writer.MetricWriter
;
...
...
@@ -40,7 +42,8 @@ import com.netflix.servo.publish.PollScheduler;
* @author Dave Syer
* @author Christian Dupuis
*/
public
class
ServoMetricCollector
{
@Slf4j
public
class
ServoMetricCollector
implements
DisposableBean
{
public
ServoMetricCollector
(
MetricWriter
metrics
)
{
List
<
MetricObserver
>
observers
=
new
ArrayList
<
MetricObserver
>();
...
...
@@ -55,6 +58,14 @@ public class ServoMetricCollector {
PollScheduler
.
getInstance
().
addPoller
(
task
,
5
,
TimeUnit
.
SECONDS
);
}
@Override
public
void
destroy
()
throws
Exception
{
log
.
info
(
"Stopping Servo PollScheduler"
);
if
(
PollScheduler
.
getInstance
().
isStarted
())
{
PollScheduler
.
getInstance
().
stop
();
}
}
/**
* {@link MetricObserver} to convert Servo metrics into Spring Boot {@link Metric}
* instances.
...
...
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