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
790ac76a
Commit
790ac76a
authored
Mar 04, 2016
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change type of loadBalancerClient back LoadBalancerClient.
parent
1d1ad75a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
18 deletions
+27
-18
RibbonAutoConfiguration.java
...amework/cloud/netflix/ribbon/RibbonAutoConfiguration.java
+2
-2
RibbonClientHttpRequestFactory.java
.../cloud/netflix/ribbon/RibbonClientHttpRequestFactory.java
+13
-4
RibbonLoadBalancerClient.java
...mework/cloud/netflix/ribbon/RibbonLoadBalancerClient.java
+0
-4
RibbonStatsRecorder.java
...ngframework/cloud/netflix/ribbon/RibbonStatsRecorder.java
+12
-8
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonAutoConfiguration.java
View file @
790ac76a
...
...
@@ -67,7 +67,7 @@ public class RibbonAutoConfiguration {
@Bean
@ConditionalOnMissingBean
(
LoadBalancerClient
.
class
)
public
Ribbon
LoadBalancerClient
loadBalancerClient
()
{
public
LoadBalancerClient
loadBalancerClient
()
{
return
new
RibbonLoadBalancerClient
(
springClientFactory
());
}
...
...
@@ -80,7 +80,7 @@ public class RibbonAutoConfiguration {
private
SpringClientFactory
springClientFactory
;
@Autowired
private
Ribbon
LoadBalancerClient
loadBalancerClient
;
private
LoadBalancerClient
loadBalancerClient
;
@Bean
public
RestTemplateCustomizer
restTemplateCustomizer
()
{
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonClientHttpRequestFactory.java
View file @
790ac76a
...
...
@@ -19,6 +19,8 @@ package org.springframework.cloud.netflix.ribbon;
import
java.io.IOException
;
import
java.net.URI
;
import
org.springframework.cloud.client.ServiceInstance
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancerClient
;
import
org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.RibbonServer
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.http.client.ClientHttpRequest
;
...
...
@@ -26,6 +28,7 @@ import org.springframework.http.client.ClientHttpRequestFactory;
import
com.netflix.client.config.IClientConfig
;
import
com.netflix.client.http.HttpRequest
;
import
com.netflix.loadbalancer.Server
;
import
com.netflix.niws.client.http.RestClient
;
/**
...
...
@@ -35,9 +38,9 @@ public class RibbonClientHttpRequestFactory implements ClientHttpRequestFactory
private
final
SpringClientFactory
clientFactory
;
private
Ribbon
LoadBalancerClient
loadBalancer
;
private
LoadBalancerClient
loadBalancer
;
public
RibbonClientHttpRequestFactory
(
SpringClientFactory
clientFactory
,
Ribbon
LoadBalancerClient
loadBalancer
)
{
public
RibbonClientHttpRequestFactory
(
SpringClientFactory
clientFactory
,
LoadBalancerClient
loadBalancer
)
{
this
.
clientFactory
=
clientFactory
;
this
.
loadBalancer
=
loadBalancer
;
}
...
...
@@ -50,7 +53,7 @@ public class RibbonClientHttpRequestFactory implements ClientHttpRequestFactory
if
(
serviceId
==
null
)
{
throw
new
IOException
(
"Invalid hostname in the URI ["
+
originalUri
.
toASCIIString
()
+
"]"
);
}
RibbonServer
instance
=
loadBalancer
.
chooseRibbonServer
(
serviceId
);
ServiceInstance
instance
=
loadBalancer
.
choose
(
serviceId
);
if
(
instance
==
null
)
{
throw
new
IllegalStateException
(
"No instances available for "
+
serviceId
);
}
...
...
@@ -60,7 +63,13 @@ public class RibbonClientHttpRequestFactory implements ClientHttpRequestFactory
RestClient
client
=
this
.
clientFactory
.
getClient
(
instance
.
getServiceId
(),
RestClient
.
class
);
HttpRequest
.
Verb
verb
=
HttpRequest
.
Verb
.
valueOf
(
httpMethod
.
name
());
RibbonLoadBalancerContext
context
=
this
.
clientFactory
.
getLoadBalancerContext
(
serviceId
);
RibbonStatsRecorder
statsRecorder
=
new
RibbonStatsRecorder
(
context
,
instance
.
getServer
());
Server
server
=
null
;
if
(
instance
instanceof
RibbonServer
)
{
server
=
((
RibbonServer
)
instance
).
getServer
();
}
RibbonStatsRecorder
statsRecorder
=
new
RibbonStatsRecorder
(
context
,
server
);
//@formatter:on
return
new
RibbonHttpRequest
(
uri
,
verb
,
client
,
clientConfig
,
statsRecorder
);
}
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonLoadBalancerClient.java
View file @
790ac76a
...
...
@@ -62,10 +62,6 @@ public class RibbonLoadBalancerClient implements LoadBalancerClient {
@Override
public
ServiceInstance
choose
(
String
serviceId
)
{
return
this
.
chooseRibbonServer
(
serviceId
);
}
RibbonServer
chooseRibbonServer
(
String
serviceId
)
{
Server
server
=
getServer
(
serviceId
);
if
(
server
==
null
)
{
return
null
;
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonStatsRecorder.java
View file @
790ac76a
...
...
@@ -12,14 +12,16 @@ import com.netflix.servo.monitor.Stopwatch;
public
class
RibbonStatsRecorder
{
private
RibbonLoadBalancerContext
context
;
private
final
ServerStats
serverStats
;
private
final
Stopwatch
tracer
;
private
ServerStats
serverStats
;
private
Stopwatch
tracer
;
public
RibbonStatsRecorder
(
RibbonLoadBalancerContext
context
,
Server
server
)
{
this
.
context
=
context
;
serverStats
=
context
.
getServerStats
(
server
);
context
.
noteOpenConnection
(
serverStats
);
tracer
=
context
.
getExecuteTracer
().
start
();
if
(
server
!=
null
)
{
serverStats
=
context
.
getServerStats
(
server
);
context
.
noteOpenConnection
(
serverStats
);
tracer
=
context
.
getExecuteTracer
().
start
();
}
}
public
void
recordStats
(
Object
entity
)
{
...
...
@@ -31,8 +33,10 @@ public class RibbonStatsRecorder {
}
protected
void
recordStats
(
Object
entity
,
Throwable
exception
)
{
this
.
tracer
.
stop
();
long
duration
=
this
.
tracer
.
getDuration
(
TimeUnit
.
MILLISECONDS
);
this
.
context
.
noteRequestCompletion
(
serverStats
,
entity
,
exception
,
duration
,
null
/* errorHandler */
);
if
(
this
.
tracer
!=
null
&&
this
.
serverStats
!=
null
)
{
this
.
tracer
.
stop
();
long
duration
=
this
.
tracer
.
getDuration
(
TimeUnit
.
MILLISECONDS
);
this
.
context
.
noteRequestCompletion
(
serverStats
,
entity
,
exception
,
duration
,
null
/* errorHandler */
);
}
}
}
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