Browse Source

Polish

pull/5/head
Phillip Webb 10 years ago
parent
commit
5168937f93
  1. 5
      src/main/java/org/springframework/cloud/client/CommonsClientAutoConfiguration.java
  2. 6
      src/main/java/org/springframework/cloud/client/DefaultServiceInstance.java
  3. 5
      src/main/java/org/springframework/cloud/client/ServiceInstance.java
  4. 10
      src/main/java/org/springframework/cloud/client/SingleImplementationImportSelector.java
  5. 1
      src/main/java/org/springframework/cloud/client/circuitbreaker/EnableCircuitBreaker.java
  6. 1
      src/main/java/org/springframework/cloud/client/circuitbreaker/EnableCircuitBreakerImportSelector.java
  7. 12
      src/main/java/org/springframework/cloud/client/discovery/AbstractDiscoveryLifecycle.java
  8. 5
      src/main/java/org/springframework/cloud/client/discovery/DiscoveryClient.java
  9. 2
      src/main/java/org/springframework/cloud/client/discovery/DiscoveryClientHealthIndicator.java
  10. 1
      src/main/java/org/springframework/cloud/client/discovery/DiscoveryCompositeHealthIndicator.java
  11. 4
      src/main/java/org/springframework/cloud/client/discovery/DiscoveryHealthIndicator.java
  12. 1
      src/main/java/org/springframework/cloud/client/discovery/DiscoveryHeartbeatEvent.java
  13. 8
      src/main/java/org/springframework/cloud/client/discovery/EnableDiscoveryClient.java
  14. 1
      src/main/java/org/springframework/cloud/client/discovery/EnableDiscoveryClientImportSelector.java
  15. 6
      src/main/java/org/springframework/cloud/client/discovery/InstanceRegisteredEvent.java
  16. 32
      src/main/java/org/springframework/cloud/client/discovery/ManagementServerPortUtils.java
  17. 1
      src/main/java/org/springframework/cloud/client/discovery/NoopDiscoveryClient.java
  18. 1
      src/main/java/org/springframework/cloud/client/discovery/NoopDiscoveryClientConfiguration.java
  19. 2
      src/main/java/org/springframework/cloud/client/loadbalancer/LoadBalancerRequest.java
  20. 1
      src/test/java/org/springframework/cloud/client/SingleImplementationImportSelectorTests.java
  21. 1
      src/test/java/org/springframework/cloud/client/discovery/DiscoveryCompositeHealthIndicatorTests.java

5
src/main/java/org/springframework/cloud/client/CommonsClientAutoConfiguration.java

@ -20,6 +20,7 @@ import java.util.List; @@ -20,6 +20,7 @@ import java.util.List;
import org.springframework.boot.actuate.health.HealthAggregator;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
@ -32,6 +33,8 @@ import org.springframework.context.annotation.Configuration; @@ -32,6 +33,8 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
/**
* {@link EnableAutoConfiguration Auto-configuration} for Spring Cloud Commons Client.
*
* @author Spencer Gibb
*/
@Configuration
@ -43,6 +46,7 @@ public class CommonsClientAutoConfiguration { @@ -43,6 +46,7 @@ public class CommonsClientAutoConfiguration {
@ConditionalOnBean(DiscoveryClient.class)
@ConditionalOnExpression("${spring.cloud.discovery.enabled:true}")
protected static class HealthConfiguration {
@Bean
public DiscoveryClientHealthIndicator instancesHealthIndicator(
DiscoveryClient discoveryClient) {
@ -54,5 +58,6 @@ public class CommonsClientAutoConfiguration { @@ -54,5 +58,6 @@ public class CommonsClientAutoConfiguration {
HealthAggregator aggregator, List<DiscoveryHealthIndicator> indicators) {
return new DiscoveryCompositeHealthIndicator(aggregator, indicators);
}
}
}

6
src/main/java/org/springframework/cloud/client/DefaultServiceInstance.java

@ -19,11 +19,17 @@ package org.springframework.cloud.client; @@ -19,11 +19,17 @@ package org.springframework.cloud.client;
import lombok.Data;
/**
* Default implementation of {@link ServiceInstance}.
*
* @author Spencer Gibb
*/
@Data
public class DefaultServiceInstance implements ServiceInstance {
private final String serviceId;
private final String host;
private final int port;
}

5
src/main/java/org/springframework/cloud/client/ServiceInstance.java

@ -17,9 +17,12 @@ @@ -17,9 +17,12 @@
package org.springframework.cloud.client;
/**
* @author Spencer Gibb TODO: name? Server? HostAndPort? Instance?
* @author Spencer Gibb
*/
public interface ServiceInstance {
// TODO: name? Server? HostAndPort? Instance?
public String getServiceId();
public String getHost();

10
src/main/java/org/springframework/cloud/client/SingleImplementationImportSelector.java

@ -35,6 +35,7 @@ import org.springframework.util.Assert; @@ -35,6 +35,7 @@ import org.springframework.util.Assert;
/**
* Selects a single configuration to load defined by the generic type T.
*
* @author Spencer Gibb
* @author Dave Syer
*/
@ -45,6 +46,7 @@ public abstract class SingleImplementationImportSelector<T> implements @@ -45,6 +46,7 @@ public abstract class SingleImplementationImportSelector<T> implements
private ClassLoader beanClassLoader;
private Class<T> annotationClass;
private Environment environment;
@SuppressWarnings("unchecked")
@ -72,14 +74,13 @@ public abstract class SingleImplementationImportSelector<T> implements @@ -72,14 +74,13 @@ public abstract class SingleImplementationImportSelector<T> implements
if (factories.size() > 1) {
String factory = factories.get(0);
// there should only every be one DiscoveryClient
log.warn(
"More than one implementation of @{}. Using {} out of available {}",
getSimpleName(), factory, factories);
log.warn("More than one implementation "
+ "of @{}. Using {} out of available {}", getSimpleName(), factory,
factories);
factories = Collections.singletonList(factory);
}
return factories.toArray(new String[factories.size()]);
}
protected abstract boolean isEnabled();
@ -105,4 +106,5 @@ public abstract class SingleImplementationImportSelector<T> implements @@ -105,4 +106,5 @@ public abstract class SingleImplementationImportSelector<T> implements
public void setBeanClassLoader(ClassLoader classLoader) {
this.beanClassLoader = classLoader;
}
}

1
src/main/java/org/springframework/cloud/client/circuitbreaker/EnableCircuitBreaker.java

@ -34,4 +34,5 @@ import org.springframework.context.annotation.Import; @@ -34,4 +34,5 @@ import org.springframework.context.annotation.Import;
@Inherited
@Import(EnableCircuitBreakerImportSelector.class)
public @interface EnableCircuitBreaker {
}

1
src/main/java/org/springframework/cloud/client/circuitbreaker/EnableCircuitBreakerImportSelector.java

@ -33,4 +33,5 @@ public class EnableCircuitBreakerImportSelector extends @@ -33,4 +33,5 @@ public class EnableCircuitBreakerImportSelector extends
return new RelaxedPropertyResolver(getEnvironment()).getProperty(
"spring.cloud.circuit.breaker.enabled", Boolean.class, Boolean.TRUE);
}
}

12
src/main/java/org/springframework/cloud/client/discovery/AbstractDiscoveryLifecycle.java

@ -31,9 +31,13 @@ public abstract class AbstractDiscoveryLifecycle implements DiscoveryLifecycle, @@ -31,9 +31,13 @@ public abstract class AbstractDiscoveryLifecycle implements DiscoveryLifecycle,
ApplicationContextAware {
protected boolean autoStartup = true;
protected boolean running;
protected int order = 0;
protected ApplicationContext context;
protected Environment environment;
@Override
@ -84,12 +88,13 @@ public abstract class AbstractDiscoveryLifecycle implements DiscoveryLifecycle, @@ -84,12 +88,13 @@ public abstract class AbstractDiscoveryLifecycle implements DiscoveryLifecycle,
protected abstract boolean isEnabled();
protected String getManagementServiceId() {
return this.context.getId() + ":management"; // TODO: configurable management
// suffix
return this.context.getId() + ":management";
// TODO: configurable management suffix
}
protected String getManagementServiceName() {
return getAppName() + ":management"; // TODO: configurable management suffix
return getAppName() + ":management";
// TODO: configurable management suffix
}
protected Integer getManagementPort() {
@ -130,4 +135,5 @@ public abstract class AbstractDiscoveryLifecycle implements DiscoveryLifecycle, @@ -130,4 +135,5 @@ public abstract class AbstractDiscoveryLifecycle implements DiscoveryLifecycle,
public int getPhase() {
return 0;
}
}

5
src/main/java/org/springframework/cloud/client/discovery/DiscoveryClient.java

@ -23,8 +23,10 @@ import org.springframework.cloud.client.ServiceInstance; @@ -23,8 +23,10 @@ import org.springframework.cloud.client.ServiceInstance;
/**
* @author Spencer Gibb
*/
// TODO: merge with LoadBalancerClient?
public interface DiscoveryClient {
// TODO: merge with LoadBalancerClient?
public String description();
/**
@ -45,4 +47,5 @@ public interface DiscoveryClient { @@ -45,4 +47,5 @@ public interface DiscoveryClient {
* @return all known service id's
*/
public List<String> getServices();
}

2
src/main/java/org/springframework/cloud/client/discovery/DiscoveryClientHealthIndicator.java

@ -31,6 +31,7 @@ import org.springframework.core.Ordered; @@ -31,6 +31,7 @@ import org.springframework.core.Ordered;
public class DiscoveryClientHealthIndicator implements DiscoveryHealthIndicator, Ordered {
private int order = Ordered.HIGHEST_PRECEDENCE;
private DiscoveryClient discoveryClient;
public DiscoveryClientHealthIndicator(DiscoveryClient discoveryClient) {
@ -65,4 +66,5 @@ public class DiscoveryClientHealthIndicator implements DiscoveryHealthIndicator, @@ -65,4 +66,5 @@ public class DiscoveryClientHealthIndicator implements DiscoveryHealthIndicator,
public void setOrder(int order) {
this.order = order;
}
}

1
src/main/java/org/springframework/cloud/client/discovery/DiscoveryCompositeHealthIndicator.java

@ -50,4 +50,5 @@ public class DiscoveryCompositeHealthIndicator extends CompositeHealthIndicator @@ -50,4 +50,5 @@ public class DiscoveryCompositeHealthIndicator extends CompositeHealthIndicator
return this.delegate.health();
}
}
}

4
src/main/java/org/springframework/cloud/client/discovery/DiscoveryHealthIndicator.java

@ -22,10 +22,12 @@ import org.springframework.boot.actuate.health.Health; @@ -22,10 +22,12 @@ import org.springframework.boot.actuate.health.Health;
* @author Spencer Gibb
*/
public interface DiscoveryHealthIndicator {
public String getName();
String getName();
/**
* @return an indication of health
*/
Health health();
}

1
src/main/java/org/springframework/cloud/client/discovery/DiscoveryHeartbeatEvent.java

@ -34,4 +34,5 @@ public class DiscoveryHeartbeatEvent extends ApplicationEvent { @@ -34,4 +34,5 @@ public class DiscoveryHeartbeatEvent extends ApplicationEvent {
public Object getValue() {
return this.value;
}
}

8
src/main/java/org/springframework/cloud/client/discovery/EnableDiscoveryClient.java

@ -16,10 +16,6 @@ @@ -16,10 +16,6 @@
package org.springframework.cloud.client.discovery;
/**
* @author Spencer Gibb
*/
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
@ -29,10 +25,14 @@ import java.lang.annotation.Target; @@ -29,10 +25,14 @@ import java.lang.annotation.Target;
import org.springframework.context.annotation.Import;
/**
* @author Spencer Gibb
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@Import(EnableDiscoveryClientImportSelector.class)
public @interface EnableDiscoveryClient {
}

1
src/main/java/org/springframework/cloud/client/discovery/EnableDiscoveryClientImportSelector.java

@ -33,4 +33,5 @@ public class EnableDiscoveryClientImportSelector extends @@ -33,4 +33,5 @@ public class EnableDiscoveryClientImportSelector extends
return new RelaxedPropertyResolver(getEnvironment()).getProperty(
"spring.cloud.discovery.enabled", Boolean.class, Boolean.TRUE);
}
}

6
src/main/java/org/springframework/cloud/client/discovery/InstanceRegisteredEvent.java

@ -20,14 +20,17 @@ import org.springframework.context.ApplicationEvent; @@ -20,14 +20,17 @@ import org.springframework.context.ApplicationEvent;
/**
* Event to be published after the local service instance registers itself with a
* discovery service
* discovery service.
*
* @author Spencer Gibb
*/
@SuppressWarnings("serial")
public class InstanceRegisteredEvent<T> extends ApplicationEvent {
private T config;
/**
* Create a new {@link InstanceRegisteredEvent} instance.
* @param source the component that published the event (never {@code null})
* @param config the configuration of the instance
*/
@ -39,4 +42,5 @@ public class InstanceRegisteredEvent<T> extends ApplicationEvent { @@ -39,4 +42,5 @@ public class InstanceRegisteredEvent<T> extends ApplicationEvent {
public T getConfig() {
return this.config;
}
}

32
src/main/java/org/springframework/cloud/client/discovery/ManagementServerPortUtils.java

@ -27,13 +27,28 @@ import org.springframework.web.context.WebApplicationContext; @@ -27,13 +27,28 @@ import org.springframework.web.context.WebApplicationContext;
*/
public class ManagementServerPortUtils {
public static ManagementServerPort get(BeanFactory beanFactory) {
return ManagementServerPort.get(beanFactory);
}
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 isSame(BeanFactory beanFactory) {
return get(beanFactory) == ManagementServerPort.SAME;
}
// TODO: copied from EndpointWebMvcAutoConfiguration.ManagementServerPort
public static enum ManagementServerPort {
DISABLE, SAME, DIFFERENT;
public static ManagementServerPort get(BeanFactory beanFactory) {
ServerProperties serverProperties;
try {
serverProperties = beanFactory.getBean(ServerProperties.class);
@ -66,19 +81,4 @@ public class ManagementServerPortUtils { @@ -66,19 +81,4 @@ public class ManagementServerPortUtils {
}
};
public static ManagementServerPort get(BeanFactory beanFactory) {
return ManagementServerPort.get(beanFactory);
}
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 isSame(BeanFactory beanFactory) {
return get(beanFactory) == ManagementServerPort.SAME;
}
}

1
src/main/java/org/springframework/cloud/client/discovery/NoopDiscoveryClient.java

@ -23,7 +23,6 @@ import org.springframework.cloud.client.ServiceInstance; @@ -23,7 +23,6 @@ import org.springframework.cloud.client.ServiceInstance;
/**
* @author Dave Syer
*
*/
public class NoopDiscoveryClient implements DiscoveryClient {

1
src/main/java/org/springframework/cloud/client/discovery/NoopDiscoveryClientConfiguration.java

@ -40,7 +40,6 @@ import org.springframework.core.env.Environment; @@ -40,7 +40,6 @@ import org.springframework.core.env.Environment;
/**
* @author Dave Syer
*
*/
@Configuration
@EnableConfigurationProperties

2
src/main/java/org/springframework/cloud/client/loadbalancer/LoadBalancerRequest.java

@ -22,5 +22,7 @@ import org.springframework.cloud.client.ServiceInstance; @@ -22,5 +22,7 @@ import org.springframework.cloud.client.ServiceInstance;
* @author Spencer Gibb
*/
public interface LoadBalancerRequest<T> {
public T apply(ServiceInstance instance) throws Exception;
}

1
src/test/java/org/springframework/cloud/client/SingleImplementationImportSelectorTests.java

@ -37,6 +37,7 @@ public class SingleImplementationImportSelectorTests { @@ -37,6 +37,7 @@ public class SingleImplementationImportSelectorTests {
public static class MyAnnotationImportSelector extends
SingleImplementationImportSelector<MyAnnotation> {
@Override
protected boolean isEnabled() {
return true;

1
src/test/java/org/springframework/cloud/client/discovery/DiscoveryCompositeHealthIndicatorTests.java

@ -89,4 +89,5 @@ public class DiscoveryCompositeHealthIndicatorTests { @@ -89,4 +89,5 @@ public class DiscoveryCompositeHealthIndicatorTests {
assertEquals("status desciption was wrong", "TestDiscoveryClient",
status.getDescription());
}
}

Loading…
Cancel
Save