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
be6f2634
Unverified
Commit
be6f2634
authored
Sep 23, 2016
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow OkHttpClient to be customized.
Moved common functionality to AbstractLoadBalancingClient
parent
9eed2490
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
38 deletions
+58
-38
RibbonLoadBalancingHttpClient.java
.../netflix/ribbon/apache/RibbonLoadBalancingHttpClient.java
+5
-24
OkHttpLoadBalancingClient.java
...loud/netflix/ribbon/okhttp/OkHttpLoadBalancingClient.java
+12
-13
AbstractLoadBalancingClient.java
...d/netflix/ribbon/support/AbstractLoadBalancingClient.java
+41
-1
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/ribbon/apache/RibbonLoadBalancingHttpClient.java
View file @
be6f2634
...
...
@@ -23,13 +23,11 @@ import org.apache.http.client.HttpClient;
import
org.apache.http.client.config.RequestConfig
;
import
org.apache.http.client.methods.HttpUriRequest
;
import
org.apache.http.impl.client.HttpClientBuilder
;
import
org.springframework.cloud.netflix.ribbon.DefaultServerIntrospector
;
import
org.springframework.cloud.netflix.ribbon.ServerIntrospector
;
import
org.springframework.cloud.netflix.ribbon.support.AbstractLoadBalancingClient
;
import
org.springframework.web.util.UriComponentsBuilder
;
import
com.netflix.client.config.CommonClientConfigKey
;
import
com.netflix.client.config.DefaultClientConfigImpl
;
import
com.netflix.client.config.IClientConfig
;
import
com.netflix.loadbalancer.ILoadBalancer
;
import
com.netflix.loadbalancer.Server
;
...
...
@@ -42,40 +40,27 @@ import static org.springframework.cloud.netflix.ribbon.RibbonUtils.updateToHttps
//TODO: rename (ie new class that extends this in Dalston) to ApacheHttpLoadBalancingClient
public
class
RibbonLoadBalancingHttpClient
extends
AbstractLoadBalancingClient
<
RibbonApacheHttpRequest
,
RibbonApacheHttpResponse
>
{
private
final
HttpClient
delegate
;
private
final
IClientConfig
config
;
private
final
ServerIntrospector
serverIntrospector
;
AbstractLoadBalancingClient
<
RibbonApacheHttpRequest
,
RibbonApacheHttpResponse
,
HttpClient
>
{
@Deprecated
public
RibbonLoadBalancingHttpClient
()
{
this
(
new
DefaultClientConfigImpl
(),
new
DefaultServerIntrospector
()
);
super
(
);
}
@Deprecated
public
RibbonLoadBalancingHttpClient
(
final
ILoadBalancer
lb
)
{
super
(
lb
);
this
.
config
=
new
DefaultClientConfigImpl
();
this
.
delegate
=
createHttpClient
(
this
.
config
);
this
.
serverIntrospector
=
new
DefaultServerIntrospector
();
initWithNiwsConfig
(
config
);
}
public
RibbonLoadBalancingHttpClient
(
IClientConfig
config
,
ServerIntrospector
serverIntrospector
)
{
this
.
delegate
=
createHttpClient
(
config
);
this
.
config
=
config
;
this
.
serverIntrospector
=
serverIntrospector
;
initWithNiwsConfig
(
config
);
super
(
config
,
serverIntrospector
);
}
public
RibbonLoadBalancingHttpClient
(
HttpClient
delegate
,
IClientConfig
config
,
ServerIntrospector
serverIntrospector
)
{
this
.
delegate
=
delegate
;
this
.
config
=
config
;
this
.
serverIntrospector
=
serverIntrospector
;
initWithNiwsConfig
(
config
);
super
(
delegate
,
config
,
serverIntrospector
);
}
protected
HttpClient
create
HttpClient
(
IClientConfig
config
)
{
protected
HttpClient
create
Delegate
(
IClientConfig
config
)
{
return
HttpClientBuilder
.
create
()
// already defaults to 0 in builder, so resetting to 0 won't hurt
.
setMaxConnTotal
(
config
.
getPropertyAsInteger
(
CommonClientConfigKey
.
MaxTotalConnections
,
0
))
...
...
@@ -86,10 +71,6 @@ public class RibbonLoadBalancingHttpClient
.
build
();
}
protected
HttpClient
getDelegate
()
{
return
this
.
delegate
;
}
@Override
public
RibbonApacheHttpResponse
execute
(
RibbonApacheHttpRequest
request
,
final
IClientConfig
configOverride
)
throws
Exception
{
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/ribbon/okhttp/OkHttpLoadBalancingClient.java
View file @
be6f2634
...
...
@@ -19,13 +19,11 @@ package org.springframework.cloud.netflix.ribbon.okhttp;
import
java.net.URI
;
import
java.util.concurrent.TimeUnit
;
import
org.springframework.cloud.netflix.ribbon.DefaultServerIntrospector
;
import
org.springframework.cloud.netflix.ribbon.ServerIntrospector
;
import
org.springframework.cloud.netflix.ribbon.support.AbstractLoadBalancingClient
;
import
org.springframework.web.util.UriComponentsBuilder
;
import
com.netflix.client.config.CommonClientConfigKey
;
import
com.netflix.client.config.DefaultClientConfigImpl
;
import
com.netflix.client.config.IClientConfig
;
import
com.netflix.loadbalancer.ILoadBalancer
;
import
com.netflix.loadbalancer.Server
;
...
...
@@ -40,30 +38,31 @@ import static org.springframework.cloud.netflix.ribbon.RibbonUtils.updateToHttps
* @author Spencer Gibb
*/
public
class
OkHttpLoadBalancingClient
extends
AbstractLoadBalancingClient
<
OkHttpRibbonRequest
,
OkHttpRibbonResponse
>
{
private
final
OkHttpClient
delegate
=
new
OkHttpClient
();
private
final
IClientConfig
config
;
private
final
ServerIntrospector
serverIntrospector
;
extends
AbstractLoadBalancingClient
<
OkHttpRibbonRequest
,
OkHttpRibbonResponse
,
OkHttpClient
>
{
@Deprecated
public
OkHttpLoadBalancingClient
()
{
super
();
config
=
new
DefaultClientConfigImpl
();
serverIntrospector
=
new
DefaultServerIntrospector
();
}
@Deprecated
public
OkHttpLoadBalancingClient
(
final
ILoadBalancer
lb
)
{
super
(
lb
);
config
=
new
DefaultClientConfigImpl
();
serverIntrospector
=
new
DefaultServerIntrospector
();
}
public
OkHttpLoadBalancingClient
(
IClientConfig
config
,
ServerIntrospector
serverIntrospector
)
{
this
.
config
=
config
;
this
.
serverIntrospector
=
serverIntrospector
;
initWithNiwsConfig
(
config
);
super
(
config
,
serverIntrospector
);
}
public
OkHttpLoadBalancingClient
(
OkHttpClient
delegate
,
IClientConfig
config
,
ServerIntrospector
serverIntrospector
)
{
super
(
delegate
,
config
,
serverIntrospector
);
}
@Override
protected
OkHttpClient
createDelegate
(
IClientConfig
config
)
{
return
new
OkHttpClient
();
}
@Override
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/ribbon/support/AbstractLoadBalancingClient.java
View file @
be6f2634
...
...
@@ -17,6 +17,9 @@
package
org
.
springframework
.
cloud
.
netflix
.
ribbon
.
support
;
import
org.springframework.cloud.netflix.ribbon.DefaultServerIntrospector
;
import
org.springframework.cloud.netflix.ribbon.ServerIntrospector
;
import
com.netflix.client.AbstractLoadBalancerAwareClient
;
import
com.netflix.client.IResponse
;
import
com.netflix.client.RequestSpecificRetryHandler
;
...
...
@@ -29,7 +32,7 @@ import com.netflix.loadbalancer.ILoadBalancer;
/**
* @author Spencer Gibb
*/
public
abstract
class
AbstractLoadBalancingClient
<
S
extends
ContextAwareRequest
,
T
extends
IResponse
>
extends
public
abstract
class
AbstractLoadBalancingClient
<
S
extends
ContextAwareRequest
,
T
extends
IResponse
,
D
>
extends
AbstractLoadBalancerAwareClient
<
S
,
T
>
{
protected
int
connectTimeout
;
...
...
@@ -42,16 +45,47 @@ public abstract class AbstractLoadBalancingClient<S extends ContextAwareRequest,
protected
boolean
okToRetryOnAllOperations
;
protected
final
D
delegate
;
protected
final
IClientConfig
config
;
protected
final
ServerIntrospector
serverIntrospector
;
@Deprecated
public
AbstractLoadBalancingClient
()
{
super
(
null
);
this
.
config
=
new
DefaultClientConfigImpl
();
this
.
delegate
=
createDelegate
(
this
.
config
);
this
.
serverIntrospector
=
new
DefaultServerIntrospector
();
this
.
setRetryHandler
(
RetryHandler
.
DEFAULT
);
initWithNiwsConfig
(
config
);
}
@Deprecated
public
AbstractLoadBalancingClient
(
final
ILoadBalancer
lb
)
{
super
(
lb
);
this
.
config
=
new
DefaultClientConfigImpl
();
this
.
delegate
=
createDelegate
(
config
);
this
.
serverIntrospector
=
new
DefaultServerIntrospector
();
this
.
setRetryHandler
(
RetryHandler
.
DEFAULT
);
initWithNiwsConfig
(
config
);
}
protected
AbstractLoadBalancingClient
(
IClientConfig
config
,
ServerIntrospector
serverIntrospector
)
{
super
(
null
);
this
.
delegate
=
createDelegate
(
config
);
this
.
config
=
config
;
this
.
serverIntrospector
=
serverIntrospector
;
this
.
setRetryHandler
(
RetryHandler
.
DEFAULT
);
initWithNiwsConfig
(
config
);
}
protected
AbstractLoadBalancingClient
(
D
delegate
,
IClientConfig
config
,
ServerIntrospector
serverIntrospector
)
{
super
(
null
);
this
.
delegate
=
delegate
;
this
.
config
=
config
;
this
.
serverIntrospector
=
serverIntrospector
;
this
.
setRetryHandler
(
RetryHandler
.
DEFAULT
);
initWithNiwsConfig
(
config
);
}
@Override
public
void
initWithNiwsConfig
(
IClientConfig
clientConfig
)
{
...
...
@@ -72,6 +106,12 @@ public abstract class AbstractLoadBalancingClient<S extends ContextAwareRequest,
DefaultClientConfigImpl
.
DEFAULT_OK_TO_RETRY_ON_ALL_OPERATIONS
);
}
protected
abstract
D
createDelegate
(
IClientConfig
config
);
public
D
getDelegate
()
{
return
this
.
delegate
;
}
@Override
public
RequestSpecificRetryHandler
getRequestSpecificRetryHandler
(
final
S
request
,
final
IClientConfig
requestConfig
)
{
...
...
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