Commit 790ac76a by Spencer Gibb

Change type of loadBalancerClient back LoadBalancerClient.

parent 1d1ad75a
......@@ -67,7 +67,7 @@ public class RibbonAutoConfiguration {
@Bean
@ConditionalOnMissingBean(LoadBalancerClient.class)
public RibbonLoadBalancerClient loadBalancerClient() {
public LoadBalancerClient loadBalancerClient() {
return new RibbonLoadBalancerClient(springClientFactory());
}
......@@ -80,7 +80,7 @@ public class RibbonAutoConfiguration {
private SpringClientFactory springClientFactory;
@Autowired
private RibbonLoadBalancerClient loadBalancerClient;
private LoadBalancerClient loadBalancerClient;
@Bean
public RestTemplateCustomizer restTemplateCustomizer() {
......
......@@ -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 RibbonLoadBalancerClient loadBalancer;
private LoadBalancerClient loadBalancer;
public RibbonClientHttpRequestFactory(SpringClientFactory clientFactory, RibbonLoadBalancerClient 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);
}
......
......@@ -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;
......
......@@ -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 */);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment