adds some javadocs

This commit is contained in:
Spencer Gibb
2015-02-13 13:16:15 -07:00
parent ab6f01a98b
commit 9d29064534
14 changed files with 81 additions and 9 deletions

View File

@@ -41,6 +41,11 @@ public class DefaultServiceInstance implements ServiceInstance {
return getUri(this);
}
/**
* Create a uri from the given ServiceInstance's host:port
* @param instance
* @return URI of the form (secure)?https:http + "host:port"
*/
public static URI getUri(ServiceInstance instance) {
String scheme = (instance.isSecure()) ? "https" : "http";
String uri = String.format("%s://%s:%s", scheme, instance.getHost(),

View File

@@ -19,16 +19,29 @@ package org.springframework.cloud.client;
import java.net.URI;
/**
* Represents an instance of a Service in a Discovery System
* @author Spencer Gibb
*/
public interface ServiceInstance {
/**
* @return the service id as register by the DiscoveryClient
*/
public String getServiceId();
/**
* @return the hostname of the registered ServiceInstance
*/
public String getHost();
/**
* @return the port of the registered ServiceInstance
*/
public int getPort();
/**
* @return ifthe port of the registered ServiceInstance is https or not
*/
public boolean isSecure();
public URI getUri();

View File

@@ -26,6 +26,8 @@ import java.lang.annotation.Target;
import org.springframework.context.annotation.Import;
/**
* Annotation to enable a CircuitBreaker implementation.
* http://martinfowler.com/bliki/CircuitBreaker.html
* @author Spencer Gibb
*/
@Target(ElementType.TYPE)

View File

@@ -22,6 +22,7 @@ import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
/**
* Import a single circuit breaker implementation Configuration
* @author Spencer Gibb
*/
@Order(Ordered.LOWEST_PRECEDENCE - 100)

View File

@@ -27,6 +27,7 @@ import org.springframework.context.ApplicationContextAware;
import org.springframework.core.env.Environment;
/**
* Lifecycle methods that may be useful and common to various DiscoveryClient implementations.
* @author Spencer Gibb
*/
public abstract class AbstractDiscoveryLifecycle implements DiscoveryLifecycle,
@@ -83,36 +84,66 @@ public abstract class AbstractDiscoveryLifecycle implements DiscoveryLifecycle,
this.running = true;
}
/**
* @return if the management service should be registered with the DiscoveryService
*/
protected boolean shouldRegisterManagement() {
return getManagementServerProperties() != null
&& getManagementPort() != null
&& ManagementServerPortUtils.isDifferent(this.context);
}
/**
* @return the object used to configure the DiscoveryClient
*/
protected abstract Object getConfiguration();
/**
* Register the local service with the DiscoveryClient
*/
protected abstract void register();
/**
* Register the local management service with the DiscoveryClient
*/
protected void registerManagement() {
}
/**
* De-register the local service with the DiscoveryClient
*/
protected abstract void deregister();
/**
* De-register the local management service with the DiscoveryClient
*/
protected void deregisterManagement() {
}
/**
* @return if the DiscoveryClient is enabled
*/
protected abstract boolean isEnabled();
/**
* @return the serviceId of the Management Service
*/
protected String getManagementServiceId() {
return this.context.getId() + ":management";
// TODO: configurable management suffix
}
/**
* @return the service name of the Management Service
*/
protected String getManagementServiceName() {
return getAppName() + ":management";
// TODO: configurable management suffix
}
/**
* @return the management server port
*/
protected Integer getManagementPort() {
return getManagementServerProperties().getPort();
}
@@ -125,6 +156,9 @@ public abstract class AbstractDiscoveryLifecycle implements DiscoveryLifecycle,
}
}
/**
* @return the app name, currently the spring.application.name property
*/
protected String getAppName() {
return this.environment.getProperty("spring.application.name");
}

View File

@@ -21,12 +21,16 @@ import java.util.List;
import org.springframework.cloud.client.ServiceInstance;
/**
* DiscoveryClient represents operations commonly available to Discovery service
* such as Netflix Eureka or consul.io
* @author Spencer Gibb
*/
public interface DiscoveryClient {
// TODO: merge with LoadBalancerClient?
/**
* A human readable description of the implementation, used in HealthIndicator
* @return
*/
public String description();
/**
@@ -41,8 +45,6 @@ public interface DiscoveryClient {
*/
public List<ServiceInstance> getInstances(String serviceId);
public List<ServiceInstance> getAllInstances();
/**
* @return all known service id's
*/

View File

@@ -26,6 +26,7 @@ import java.lang.annotation.Target;
import org.springframework.context.annotation.Import;
/**
* Annotation to enable a DiscoveryClient implementation.
* @author Spencer Gibb
*/
@Target(ElementType.TYPE)

View File

@@ -23,6 +23,7 @@ import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.web.context.WebApplicationContext;
/**
*
* @author Spencer Gibb
*/
public class ManagementServerPortUtils {

View File

@@ -19,6 +19,8 @@ package org.springframework.cloud.client.discovery.event;
import org.springframework.context.ApplicationEvent;
/**
* Event DiscoveryClient implementation can broadcast if they support
* heartbeat's from the discovery server
* @author Spencer Gibb
*/
@SuppressWarnings("serial")

View File

@@ -25,6 +25,8 @@ import org.springframework.boot.actuate.health.HealthAggregator;
import org.springframework.boot.actuate.health.HealthIndicator;
/**
* Gathers all DiscoveryHealthIndicator's from a DiscoveryClient implementation
* and aggregates the statuses.
* @author Spencer Gibb
*/
public class DiscoveryCompositeHealthIndicator extends CompositeHealthIndicator {

View File

@@ -19,6 +19,7 @@ package org.springframework.cloud.client.discovery.health;
import org.springframework.boot.actuate.health.Health;
/**
* A health indicator interface specific for a DiscoveryClient implementation
* @author Spencer Gibb
*/
public interface DiscoveryHealthIndicator {

View File

@@ -23,6 +23,7 @@ import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
/**
* DiscoveryClient used when no implementations are found on the classpath
* @author Dave Syer
*/
public class NoopDiscoveryClient implements DiscoveryClient {
@@ -48,11 +49,6 @@ public class NoopDiscoveryClient implements DiscoveryClient {
return Collections.emptyList();
}
@Override
public List<ServiceInstance> getAllInstances() {
return Collections.emptyList();
}
@Override
public List<String> getServices() {
return Collections.emptyList();

View File

@@ -21,6 +21,7 @@ import java.net.URI;
import org.springframework.cloud.client.ServiceInstance;
/**
* Represents a client side load balancer
* @author Spencer Gibb
*/
public interface LoadBalancerClient {
@@ -42,6 +43,15 @@ public interface LoadBalancerClient {
*/
public <T> T execute(String serviceId, LoadBalancerRequest<T> request);
/**
* Create a proper URI with a real host and port for systems to utilize.
* Some systems use a URI with the logical serivce name as the host,
* such as http://myservice/path/to/service. This will replace the
* service name with the host:port from the ServiceInstance.
* @param instance
* @param original a URI with the host as a logical service name
* @return a reconstructed URI
*/
public URI reconstructURI(ServiceInstance instance, URI original);
}

View File

@@ -19,6 +19,8 @@ package org.springframework.cloud.client.loadbalancer;
import org.springframework.cloud.client.ServiceInstance;
/**
* Simple interface used by LoadBalancerClient to apply metrics or pre and post
* actions around load balancer requests.
* @author Spencer Gibb
*/
public interface LoadBalancerRequest<T> {