diff --git a/src/main/java/org/springframework/cloud/client/CommonsClientAutoConfiguration.java b/src/main/java/org/springframework/cloud/client/CommonsClientAutoConfiguration.java index a061c6d9..54f39296 100644 --- a/src/main/java/org/springframework/cloud/client/CommonsClientAutoConfiguration.java +++ b/src/main/java/org/springframework/cloud/client/CommonsClientAutoConfiguration.java @@ -1,5 +1,7 @@ package org.springframework.cloud.client; +import java.util.List; + import org.springframework.boot.actuate.health.HealthAggregator; import org.springframework.boot.actuate.health.HealthIndicator; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; @@ -13,8 +15,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.annotation.Order; -import java.util.List; - /** * @author Spencer Gibb */ @@ -28,12 +28,14 @@ public class CommonsClientAutoConfiguration { @ConditionalOnExpression("${spring.cloud.discovery.enabled:true}") protected static class HealthConfiguration { @Bean - public DiscoveryClientHealthIndicator instancesHealthIndicator(DiscoveryClient discoveryClient) { + public DiscoveryClientHealthIndicator instancesHealthIndicator( + DiscoveryClient discoveryClient) { return new DiscoveryClientHealthIndicator(discoveryClient); } @Bean - public DiscoveryCompositeHealthIndicator discoveryHealthIndicator(HealthAggregator aggregator, List indicators) { + public DiscoveryCompositeHealthIndicator discoveryHealthIndicator( + HealthAggregator aggregator, List indicators) { return new DiscoveryCompositeHealthIndicator(aggregator, indicators); } } diff --git a/src/main/java/org/springframework/cloud/client/DefaultServiceInstance.java b/src/main/java/org/springframework/cloud/client/DefaultServiceInstance.java index 32cf1a79..860e8f34 100644 --- a/src/main/java/org/springframework/cloud/client/DefaultServiceInstance.java +++ b/src/main/java/org/springframework/cloud/client/DefaultServiceInstance.java @@ -7,7 +7,7 @@ import lombok.Data; */ @Data public class DefaultServiceInstance implements ServiceInstance { - private final String serviceId; - private final String host; - private final int port; + private final String serviceId; + private final String host; + private final int port; } diff --git a/src/main/java/org/springframework/cloud/client/ServiceInstance.java b/src/main/java/org/springframework/cloud/client/ServiceInstance.java index 2480f2a3..4be95769 100644 --- a/src/main/java/org/springframework/cloud/client/ServiceInstance.java +++ b/src/main/java/org/springframework/cloud/client/ServiceInstance.java @@ -1,12 +1,12 @@ package org.springframework.cloud.client; - /** - * @author Spencer Gibb - * TODO: name? Server? HostAndPort? Instance? + * @author Spencer Gibb TODO: name? Server? HostAndPort? Instance? */ public interface ServiceInstance { - public String getServiceId(); - public String getHost(); - public int getPort(); + public String getServiceId(); + + public String getHost(); + + public int getPort(); } diff --git a/src/main/java/org/springframework/cloud/client/SingleImplementationImportSelector.java b/src/main/java/org/springframework/cloud/client/SingleImplementationImportSelector.java index 407cfc07..6d814704 100644 --- a/src/main/java/org/springframework/cloud/client/SingleImplementationImportSelector.java +++ b/src/main/java/org/springframework/cloud/client/SingleImplementationImportSelector.java @@ -33,7 +33,7 @@ public abstract class SingleImplementationImportSelector implements @SuppressWarnings("unchecked") protected SingleImplementationImportSelector() { - annotationClass = (Class) GenericTypeResolver.resolveTypeArgument( + this.annotationClass = (Class) GenericTypeResolver.resolveTypeArgument( this.getClass(), SingleImplementationImportSelector.class); } @@ -43,14 +43,14 @@ public abstract class SingleImplementationImportSelector implements return new String[0]; } AnnotationAttributes attributes = AnnotationAttributes.fromMap(metadata - .getAnnotationAttributes(annotationClass.getName(), true)); + .getAnnotationAttributes(this.annotationClass.getName(), true)); Assert.notNull(attributes, "No " + getSimpleName() + " attributes found. Is " + metadata.getClassName() + " annotated with @" + getSimpleName() + "?"); // Find all possible auto configuration classes, filtering duplicates List factories = new ArrayList<>(new LinkedHashSet<>( - SpringFactoriesLoader.loadFactoryNames(annotationClass, + SpringFactoriesLoader.loadFactoryNames(this.annotationClass, this.beanClassLoader))); if (factories.size() > 1) { @@ -69,15 +69,15 @@ public abstract class SingleImplementationImportSelector implements protected abstract boolean isEnabled(); protected String getSimpleName() { - return annotationClass.getSimpleName(); + return this.annotationClass.getSimpleName(); } - + protected Class getAnnotationClass() { - return annotationClass; + return this.annotationClass; } protected Environment getEnvironment() { - return environment; + return this.environment; } @Override diff --git a/src/main/java/org/springframework/cloud/client/circuitbreaker/EnableCircuitBreaker.java b/src/main/java/org/springframework/cloud/client/circuitbreaker/EnableCircuitBreaker.java index a4a66e3a..3e18c39c 100644 --- a/src/main/java/org/springframework/cloud/client/circuitbreaker/EnableCircuitBreaker.java +++ b/src/main/java/org/springframework/cloud/client/circuitbreaker/EnableCircuitBreaker.java @@ -1,8 +1,13 @@ package org.springframework.cloud.client.circuitbreaker; -import org.springframework.context.annotation.Import; +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; -import java.lang.annotation.*; +import org.springframework.context.annotation.Import; /** * @author Spencer Gibb diff --git a/src/main/java/org/springframework/cloud/client/circuitbreaker/EnableCircuitBreakerImportSelector.java b/src/main/java/org/springframework/cloud/client/circuitbreaker/EnableCircuitBreakerImportSelector.java index 55c9312e..fb5604b3 100644 --- a/src/main/java/org/springframework/cloud/client/circuitbreaker/EnableCircuitBreakerImportSelector.java +++ b/src/main/java/org/springframework/cloud/client/circuitbreaker/EnableCircuitBreakerImportSelector.java @@ -9,10 +9,12 @@ import org.springframework.core.annotation.Order; * @author Spencer Gibb */ @Order(Ordered.LOWEST_PRECEDENCE - 100) -public class EnableCircuitBreakerImportSelector extends SingleImplementationImportSelector { +public class EnableCircuitBreakerImportSelector extends + SingleImplementationImportSelector { @Override protected boolean isEnabled() { - return new RelaxedPropertyResolver(getEnvironment()).getProperty("spring.cloud.circuit.breaker.enabled", Boolean.class, Boolean.TRUE); + return new RelaxedPropertyResolver(getEnvironment()).getProperty( + "spring.cloud.circuit.breaker.enabled", Boolean.class, Boolean.TRUE); } } diff --git a/src/main/java/org/springframework/cloud/client/discovery/AbstractDiscoveryLifecycle.java b/src/main/java/org/springframework/cloud/client/discovery/AbstractDiscoveryLifecycle.java index 2397ca7f..25e05ac6 100644 --- a/src/main/java/org/springframework/cloud/client/discovery/AbstractDiscoveryLifecycle.java +++ b/src/main/java/org/springframework/cloud/client/discovery/AbstractDiscoveryLifecycle.java @@ -1,109 +1,117 @@ package org.springframework.cloud.client.discovery; +import javax.annotation.PreDestroy; + import org.springframework.beans.BeansException; import org.springframework.boot.actuate.autoconfigure.ManagementServerProperties; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.core.env.Environment; -import javax.annotation.PreDestroy; - /** * @author Spencer Gibb */ -public abstract class AbstractDiscoveryLifecycle implements DiscoveryLifecycle, ApplicationContextAware { +public abstract class AbstractDiscoveryLifecycle implements DiscoveryLifecycle, + ApplicationContextAware { - protected boolean autoStartup = true; - protected boolean running; - protected int order = 0; - protected ApplicationContext context; - protected Environment environment; + protected boolean autoStartup = true; + protected boolean running; + protected int order = 0; + protected ApplicationContext context; + protected Environment environment; - @Override - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { - this.context = applicationContext; - environment = context.getEnvironment(); - } + @Override + public void setApplicationContext(ApplicationContext applicationContext) + throws BeansException { + this.context = applicationContext; + this.environment = this.context.getEnvironment(); + } - @Override - public boolean isAutoStartup() { - return autoStartup; - } + @Override + public boolean isAutoStartup() { + return this.autoStartup; + } - @Override - public void stop(Runnable callback) { - stop(); - callback.run(); - } + @Override + public void stop(Runnable callback) { + stop(); + callback.run(); + } - @Override - public void start() { - if (!isEnabled()) return; + @Override + public void start() { + if (!isEnabled()) { + return; + } - register(); - if (ManagementServerPortUtils.isDifferent(context)) { - registerManagement(); - } - context.publishEvent(new InstanceRegisteredEvent<>(this, getConfiguration())); - running = true; - } + register(); + if (ManagementServerPortUtils.isDifferent(this.context)) { + registerManagement(); + } + this.context + .publishEvent(new InstanceRegisteredEvent<>(this, getConfiguration())); + this.running = true; + } - protected abstract Object getConfiguration(); + protected abstract Object getConfiguration(); - protected abstract void register(); + protected abstract void register(); - protected void registerManagement() {} + protected void registerManagement() { + } - protected abstract void deregister(); + protected abstract void deregister(); - protected void deregisterManagement() {} + protected void deregisterManagement() { + } - protected abstract boolean isEnabled(); + protected abstract boolean isEnabled(); - protected String getManagementServiceId() { - return context.getId() + ":management"; //TODO: configurable management suffix - } + protected String getManagementServiceId() { + return this.context.getId() + ":management"; // TODO: configurable management + // suffix + } - protected String getManagementServiceName() { - return getAppName() + ":management"; //TODO: configurable management suffix - } + protected String getManagementServiceName() { + return getAppName() + ":management"; // TODO: configurable management suffix + } - protected Integer getManagementPort() { - return context.getBean(ManagementServerProperties.class).getPort(); - } + protected Integer getManagementPort() { + return this.context.getBean(ManagementServerProperties.class).getPort(); + } - protected String getAppName() { - return environment.getProperty("spring.application.name"); - } + protected String getAppName() { + return this.environment.getProperty("spring.application.name"); + } - @Override - public void stop() { - if (isEnabled()) { - deregister(); - if (getManagementPort() != null) { - deregisterManagement(); - } - } - running = false; - } + @Override + public void stop() { + if (isEnabled()) { + deregister(); + if (getManagementPort() != null) { + deregisterManagement(); + } + } + this.running = false; + } - @PreDestroy - public void destroy() { - stop(); - } + @PreDestroy + public void destroy() { + stop(); + } - @Override - public boolean isRunning() { - return running; - } + @Override + public boolean isRunning() { + return this.running; + } - @Override - public int getOrder() { - return order; - } + @Override + public int getOrder() { + return this.order; + } - @Override - public int getPhase() { - return 0; - } + @Override + public int getPhase() { + return 0; + } } diff --git a/src/main/java/org/springframework/cloud/client/discovery/DiscoveryClient.java b/src/main/java/org/springframework/cloud/client/discovery/DiscoveryClient.java index 2d4d0803..16a49694 100644 --- a/src/main/java/org/springframework/cloud/client/discovery/DiscoveryClient.java +++ b/src/main/java/org/springframework/cloud/client/discovery/DiscoveryClient.java @@ -1,32 +1,32 @@ package org.springframework.cloud.client.discovery; -import org.springframework.cloud.client.ServiceInstance; - import java.util.List; +import org.springframework.cloud.client.ServiceInstance; + /** * @author Spencer Gibb */ -//TODO: merge with LoadBalancerClient? +// TODO: merge with LoadBalancerClient? public interface DiscoveryClient { public String description(); - /** - * @return ServiceInstance with information used to register the local service - */ - public ServiceInstance getLocalServiceInstance(); + /** + * @return ServiceInstance with information used to register the local service + */ + public ServiceInstance getLocalServiceInstance(); - /** - * Get all ServiceInstance's associated with a particular serviceId - * @param serviceId the serviceId to query - * @return a List of ServiceInstance - */ - public List getInstances(String serviceId); + /** + * Get all ServiceInstance's associated with a particular serviceId + * @param serviceId the serviceId to query + * @return a List of ServiceInstance + */ + public List getInstances(String serviceId); - public List getAllInstances(); + public List getAllInstances(); - /** - * @return all known service id's - */ - public List getServices(); + /** + * @return all known service id's + */ + public List getServices(); } diff --git a/src/main/java/org/springframework/cloud/client/discovery/DiscoveryClientHealthIndicator.java b/src/main/java/org/springframework/cloud/client/discovery/DiscoveryClientHealthIndicator.java index 80c72954..578ff262 100644 --- a/src/main/java/org/springframework/cloud/client/discovery/DiscoveryClientHealthIndicator.java +++ b/src/main/java/org/springframework/cloud/client/discovery/DiscoveryClientHealthIndicator.java @@ -24,16 +24,17 @@ public class DiscoveryClientHealthIndicator implements DiscoveryHealthIndicator, @Override public Health health() { Health.Builder builder = new Health.Builder(); - try { - List services = discoveryClient.getServices(); - builder.status(new Status("UP", discoveryClient.description())) + try { + List services = this.discoveryClient.getServices(); + builder.status(new Status("UP", this.discoveryClient.description())) .withDetail("services", services); - } catch (Exception e) { - log.error("Error", e); - builder.down(e); - } + } + catch (Exception e) { + log.error("Error", e); + builder.down(e); + } return builder.build(); - } + } @Override public String getName() { @@ -42,7 +43,7 @@ public class DiscoveryClientHealthIndicator implements DiscoveryHealthIndicator, @Override public int getOrder() { - return order; + return this.order; } public void setOrder(int order) { diff --git a/src/main/java/org/springframework/cloud/client/discovery/DiscoveryCompositeHealthIndicator.java b/src/main/java/org/springframework/cloud/client/discovery/DiscoveryCompositeHealthIndicator.java index 91d86f4e..9c18e1e1 100644 --- a/src/main/java/org/springframework/cloud/client/discovery/DiscoveryCompositeHealthIndicator.java +++ b/src/main/java/org/springframework/cloud/client/discovery/DiscoveryCompositeHealthIndicator.java @@ -14,7 +14,8 @@ import org.springframework.boot.actuate.health.HealthIndicator; public class DiscoveryCompositeHealthIndicator extends CompositeHealthIndicator { @Autowired - public DiscoveryCompositeHealthIndicator(HealthAggregator healthAggregator, List indicators) { + public DiscoveryCompositeHealthIndicator(HealthAggregator healthAggregator, + List indicators) { super(healthAggregator); for (DiscoveryHealthIndicator indicator : indicators) { addHealthIndicator(indicator.getName(), new Holder(indicator)); @@ -30,7 +31,7 @@ public class DiscoveryCompositeHealthIndicator extends CompositeHealthIndicator @Override public Health health() { - return delegate.health(); + return this.delegate.health(); } } } diff --git a/src/main/java/org/springframework/cloud/client/discovery/DiscoveryHeartbeatEvent.java b/src/main/java/org/springframework/cloud/client/discovery/DiscoveryHeartbeatEvent.java index 32f93cc6..8a8cd03a 100644 --- a/src/main/java/org/springframework/cloud/client/discovery/DiscoveryHeartbeatEvent.java +++ b/src/main/java/org/springframework/cloud/client/discovery/DiscoveryHeartbeatEvent.java @@ -16,6 +16,6 @@ public class DiscoveryHeartbeatEvent extends ApplicationEvent { } public Object getValue() { - return value; + return this.value; } } diff --git a/src/main/java/org/springframework/cloud/client/discovery/EnableDiscoveryClient.java b/src/main/java/org/springframework/cloud/client/discovery/EnableDiscoveryClient.java index 4b6ab16a..fb4f2763 100644 --- a/src/main/java/org/springframework/cloud/client/discovery/EnableDiscoveryClient.java +++ b/src/main/java/org/springframework/cloud/client/discovery/EnableDiscoveryClient.java @@ -4,7 +4,12 @@ package org.springframework.cloud.client.discovery; * @author Spencer Gibb */ -import java.lang.annotation.*; +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; import org.springframework.context.annotation.Import; diff --git a/src/main/java/org/springframework/cloud/client/discovery/InstanceRegisteredEvent.java b/src/main/java/org/springframework/cloud/client/discovery/InstanceRegisteredEvent.java index c459b68e..774b0b59 100644 --- a/src/main/java/org/springframework/cloud/client/discovery/InstanceRegisteredEvent.java +++ b/src/main/java/org/springframework/cloud/client/discovery/InstanceRegisteredEvent.java @@ -3,23 +3,24 @@ package org.springframework.cloud.client.discovery; import org.springframework.context.ApplicationEvent; /** - * Event to be published after the local service instance registers itself with a discovery service + * Event to be published after the local service instance registers itself with a + * discovery service * @author Spencer Gibb */ @SuppressWarnings("serial") public class InstanceRegisteredEvent extends ApplicationEvent { - private T config; + private T config; - /** - * @param source the component that published the event (never {@code null}) - * @param config the configuration of the instance - */ - public InstanceRegisteredEvent(Object source, T config) { - super(source); - this.config = config; - } + /** + * @param source the component that published the event (never {@code null}) + * @param config the configuration of the instance + */ + public InstanceRegisteredEvent(Object source, T config) { + super(source); + this.config = config; + } - public T getConfig() { - return config; - } + public T getConfig() { + return this.config; + } } diff --git a/src/main/java/org/springframework/cloud/client/discovery/ManagementServerPortUtils.java b/src/main/java/org/springframework/cloud/client/discovery/ManagementServerPortUtils.java index 5861dde7..9d5c9148 100644 --- a/src/main/java/org/springframework/cloud/client/discovery/ManagementServerPortUtils.java +++ b/src/main/java/org/springframework/cloud/client/discovery/ManagementServerPortUtils.java @@ -11,58 +11,58 @@ import org.springframework.web.context.WebApplicationContext; */ public class ManagementServerPortUtils { - //TODO: copied from EndpointWebMvcAutoConfiguration.ManagementServerPort - public static enum ManagementServerPort { + // TODO: copied from EndpointWebMvcAutoConfiguration.ManagementServerPort + public static enum ManagementServerPort { - DISABLE, SAME, DIFFERENT; + DISABLE, SAME, DIFFERENT; - public static ManagementServerPort get(BeanFactory beanFactory) { + public static ManagementServerPort get(BeanFactory beanFactory) { - ServerProperties serverProperties; - try { - serverProperties = beanFactory.getBean(ServerProperties.class); - } - catch (NoSuchBeanDefinitionException ex) { - serverProperties = new ServerProperties(); - } + ServerProperties serverProperties; + try { + serverProperties = beanFactory.getBean(ServerProperties.class); + } + catch (NoSuchBeanDefinitionException ex) { + serverProperties = new ServerProperties(); + } - ManagementServerProperties managementServerProperties; - try { - managementServerProperties = beanFactory - .getBean(ManagementServerProperties.class); - } - catch (NoSuchBeanDefinitionException ex) { - managementServerProperties = new ManagementServerProperties(); - } + ManagementServerProperties managementServerProperties; + try { + managementServerProperties = beanFactory + .getBean(ManagementServerProperties.class); + } + catch (NoSuchBeanDefinitionException ex) { + managementServerProperties = new ManagementServerProperties(); + } - Integer port = managementServerProperties.getPort(); - if (port != null && port < 0) { - return DISABLE; - } - if (!(beanFactory instanceof WebApplicationContext)) { - // Current context is not a webapp - return DIFFERENT; - } - return ((port == null) - || (serverProperties.getPort() == null && port.equals(8080)) - || (port != 0 && port.equals(serverProperties.getPort())) ? SAME - : DIFFERENT); - } - }; + Integer port = managementServerProperties.getPort(); + if (port != null && port < 0) { + return DISABLE; + } + if (!(beanFactory instanceof WebApplicationContext)) { + // Current context is not a webapp + return DIFFERENT; + } + return ((port == null) + || (serverProperties.getPort() == null && port.equals(8080)) + || (port != 0 && port.equals(serverProperties.getPort())) ? SAME + : DIFFERENT); + } + }; - public static ManagementServerPort get(BeanFactory beanFactory) { - return ManagementServerPort.get(beanFactory); - } + public static ManagementServerPort get(BeanFactory beanFactory) { + return ManagementServerPort.get(beanFactory); + } - public static boolean isDifferent(BeanFactory beanFactory) { - return get(beanFactory) == ManagementServerPort.DIFFERENT; - } + public static boolean isDifferent(BeanFactory beanFactory) { + return get(beanFactory) == ManagementServerPort.DIFFERENT; + } - public static boolean isDisabled(BeanFactory beanFactory) { - return get(beanFactory) == ManagementServerPort.DISABLE; - } + public static boolean isDisabled(BeanFactory beanFactory) { + return get(beanFactory) == ManagementServerPort.DISABLE; + } - public static boolean isSame(BeanFactory beanFactory) { - return get(beanFactory) == ManagementServerPort.SAME; - } + public static boolean isSame(BeanFactory beanFactory) { + return get(beanFactory) == ManagementServerPort.SAME; + } } diff --git a/src/main/java/org/springframework/cloud/client/discovery/NoopDiscoveryClient.java b/src/main/java/org/springframework/cloud/client/discovery/NoopDiscoveryClient.java index 6bcf8a2a..0d14f52d 100644 --- a/src/main/java/org/springframework/cloud/client/discovery/NoopDiscoveryClient.java +++ b/src/main/java/org/springframework/cloud/client/discovery/NoopDiscoveryClient.java @@ -27,7 +27,7 @@ import org.springframework.cloud.client.ServiceInstance; public class NoopDiscoveryClient implements DiscoveryClient { private final ServiceInstance instance; - + public NoopDiscoveryClient(ServiceInstance instance) { this.instance = instance; } @@ -39,7 +39,7 @@ public class NoopDiscoveryClient implements DiscoveryClient { @Override public ServiceInstance getLocalServiceInstance() { - return instance; + return this.instance; } @Override diff --git a/src/main/java/org/springframework/cloud/client/discovery/NoopDiscoveryClientConfiguration.java b/src/main/java/org/springframework/cloud/client/discovery/NoopDiscoveryClientConfiguration.java index 88786c6b..7b15b80c 100644 --- a/src/main/java/org/springframework/cloud/client/discovery/NoopDiscoveryClientConfiguration.java +++ b/src/main/java/org/springframework/cloud/client/discovery/NoopDiscoveryClientConfiguration.java @@ -45,7 +45,8 @@ import org.springframework.core.env.Environment; @EnableConfigurationProperties @ConditionalOnMissingClass(name = "com.netflix.discovery.EurekaClientConfig") @ConditionalOnExpression("!${eureka.client.enabled:false}") -public class NoopDiscoveryClientConfiguration implements ApplicationListener { +public class NoopDiscoveryClientConfiguration implements + ApplicationListener { private static final Logger logger = LoggerFactory .getLogger(NoopDiscoveryClientConfiguration.class); @@ -71,29 +72,30 @@ public class NoopDiscoveryClientConfiguration implements ApplicationListener(this, environment)); + this.context.publishEvent(new InstanceRegisteredEvent(this, + this.environment)); } @Bean public DiscoveryClient discoveryClient() { - return new NoopDiscoveryClient(serviceInstance); + return new NoopDiscoveryClient(this.serviceInstance); } } diff --git a/src/main/java/org/springframework/cloud/client/loadbalancer/LoadBalancerClient.java b/src/main/java/org/springframework/cloud/client/loadbalancer/LoadBalancerClient.java index 19ed6fc0..b43aa034 100644 --- a/src/main/java/org/springframework/cloud/client/loadbalancer/LoadBalancerClient.java +++ b/src/main/java/org/springframework/cloud/client/loadbalancer/LoadBalancerClient.java @@ -1,28 +1,31 @@ package org.springframework.cloud.client.loadbalancer; -import org.springframework.cloud.client.ServiceInstance; - import java.net.URI; +import org.springframework.cloud.client.ServiceInstance; + /** * @author Spencer Gibb */ public interface LoadBalancerClient { - /** - * Choose a ServiceInstance from the LoadBalancer for the specified service - * @param serviceId the service id to look up the LoadBalancer - * @return a ServiceInstance that matches the serviceId - */ - public ServiceInstance choose(String serviceId); + /** + * Choose a ServiceInstance from the LoadBalancer for the specified service + * @param serviceId the service id to look up the LoadBalancer + * @return a ServiceInstance that matches the serviceId + */ + public ServiceInstance choose(String serviceId); - /** - * execute request using a ServiceInstance from the LoadBalancer for the specified service - * @param serviceId the service id to look up the LoadBalancer - * @param request allows implementations to execute pre and post actions such as incrementing metrics - * @return the result of the LoadBalancerRequest callback on the selected ServiceInstance - */ - public T execute(String serviceId, LoadBalancerRequest request); + /** + * execute request using a ServiceInstance from the LoadBalancer for the specified + * service + * @param serviceId the service id to look up the LoadBalancer + * @param request allows implementations to execute pre and post actions such as + * incrementing metrics + * @return the result of the LoadBalancerRequest callback on the selected + * ServiceInstance + */ + public T execute(String serviceId, LoadBalancerRequest request); - public URI reconstructURI(ServiceInstance instance, URI original); + public URI reconstructURI(ServiceInstance instance, URI original); } diff --git a/src/main/java/org/springframework/cloud/client/loadbalancer/LoadBalancerRequest.java b/src/main/java/org/springframework/cloud/client/loadbalancer/LoadBalancerRequest.java index 7c6cbc60..bb82f31d 100644 --- a/src/main/java/org/springframework/cloud/client/loadbalancer/LoadBalancerRequest.java +++ b/src/main/java/org/springframework/cloud/client/loadbalancer/LoadBalancerRequest.java @@ -6,5 +6,5 @@ import org.springframework.cloud.client.ServiceInstance; * @author Spencer Gibb */ public interface LoadBalancerRequest { - public T apply(ServiceInstance instance) throws Exception; + public T apply(ServiceInstance instance) throws Exception; } diff --git a/src/test/java/org/springframework/cloud/client/SingleImplementationImportSelectorTests.java b/src/test/java/org/springframework/cloud/client/SingleImplementationImportSelectorTests.java index cd88ffbd..6d6b5214 100644 --- a/src/test/java/org/springframework/cloud/client/SingleImplementationImportSelectorTests.java +++ b/src/test/java/org/springframework/cloud/client/SingleImplementationImportSelectorTests.java @@ -2,25 +2,29 @@ package org.springframework.cloud.client; import org.junit.Test; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; /** * @author Spencer Gibb */ public class SingleImplementationImportSelectorTests { - @Test - public void testFindAnnotation() { - MyAnnotationImportSelector selector = new MyAnnotationImportSelector(); - assertEquals("annotationClass was wrong", MyAnnotation.class, selector.getAnnotationClass()); - } + @Test + public void testFindAnnotation() { + MyAnnotationImportSelector selector = new MyAnnotationImportSelector(); + assertEquals("annotationClass was wrong", MyAnnotation.class, + selector.getAnnotationClass()); + } - public static @interface MyAnnotation {} - public static class MyAnnotationImportSelector extends SingleImplementationImportSelector { - @Override - protected boolean isEnabled() { - return true; - } + public static @interface MyAnnotation { + } - } + public static class MyAnnotationImportSelector extends + SingleImplementationImportSelector { + @Override + protected boolean isEnabled() { + return true; + } + + } } diff --git a/src/test/java/org/springframework/cloud/client/discovery/DiscoveryCompositeHealthIndicatorTests.java b/src/test/java/org/springframework/cloud/client/discovery/DiscoveryCompositeHealthIndicatorTests.java index 58a04ee7..98ecf7ff 100644 --- a/src/test/java/org/springframework/cloud/client/discovery/DiscoveryCompositeHealthIndicatorTests.java +++ b/src/test/java/org/springframework/cloud/client/discovery/DiscoveryCompositeHealthIndicatorTests.java @@ -1,6 +1,5 @@ package org.springframework.cloud.client.discovery; -import com.google.common.collect.Lists; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -14,14 +13,19 @@ import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import static org.mockito.Mockito.*; -import static org.junit.Assert.*; +import com.google.common.collect.Lists; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; /** * @author Spencer Gibb */ @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = {DiscoveryCompositeHealthIndicatorTests.Config.class, CommonsClientAutoConfiguration.class}) +@ContextConfiguration(classes = { DiscoveryCompositeHealthIndicatorTests.Config.class, + CommonsClientAutoConfiguration.class }) public class DiscoveryCompositeHealthIndicatorTests { @Autowired @@ -60,12 +64,13 @@ public class DiscoveryCompositeHealthIndicatorTests { @Test public void testHealthIndicator() { - assertNotNull("healthIndicator was null", healthIndicator); - Health health = healthIndicator.health(); + assertNotNull("healthIndicator was null", this.healthIndicator); + Health health = this.healthIndicator.health(); assertNotNull("health was null", health); Status status = health.getStatus(); assertNotNull("status was null", status); assertEquals("status code was wrong", "UP", status.getCode()); - assertEquals("status desciption was wrong", "TestDiscoveryClient", status.getDescription()); + assertEquals("status desciption was wrong", "TestDiscoveryClient", + status.getDescription()); } }