Browse Source

Introduced ServiceInstance metadata map.

pull/75/merge
Jakub Narloch 9 years ago committed by Spencer Gibb
parent
commit
f9cffe9f3c
  1. 15
      spring-cloud-commons/src/main/java/org/springframework/cloud/client/DefaultServiceInstance.java
  2. 20
      spring-cloud-commons/src/main/java/org/springframework/cloud/client/ServiceInstance.java

15
spring-cloud-commons/src/main/java/org/springframework/cloud/client/DefaultServiceInstance.java

@ -17,8 +17,11 @@ @@ -17,8 +17,11 @@
package org.springframework.cloud.client;
import java.net.URI;
import java.util.Collections;
import java.util.Map;
import lombok.Data;
import lombok.RequiredArgsConstructor;
/**
* Default implementation of {@link ServiceInstance}.
@ -26,6 +29,7 @@ import lombok.Data; @@ -26,6 +29,7 @@ import lombok.Data;
* @author Spencer Gibb
*/
@Data
@RequiredArgsConstructor
public class DefaultServiceInstance implements ServiceInstance {
private final String serviceId;
@ -36,11 +40,22 @@ public class DefaultServiceInstance implements ServiceInstance { @@ -36,11 +40,22 @@ public class DefaultServiceInstance implements ServiceInstance {
private final boolean secure;
private final Map<String, String> metadata;
public DefaultServiceInstance(String serviceId, String host, int port, boolean secure) {
this(serviceId, host, port, secure, Collections.<String, String>emptyMap());
}
@Override
public URI getUri() {
return getUri(this);
}
@Override
public Map<String, String> getMetadata() {
return metadata;
}
/**
* Create a uri from the given ServiceInstance's host:port
* @param instance

20
spring-cloud-commons/src/main/java/org/springframework/cloud/client/ServiceInstance.java

@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
package org.springframework.cloud.client;
import java.net.URI;
import java.util.Map;
/**
* Represents an instance of a Service in a Discovery System
@ -27,23 +28,30 @@ public interface ServiceInstance { @@ -27,23 +28,30 @@ public interface ServiceInstance {
/**
* @return the service id as register by the DiscoveryClient
*/
public String getServiceId();
String getServiceId();
/**
* @return the hostname of the registered ServiceInstance
*/
public String getHost();
String getHost();
/**
* @return the port of the registered ServiceInstance
*/
public int getPort();
int getPort();
/**
* @return ifthe port of the registered ServiceInstance is https or not
* @return if the port of the registered ServiceInstance is https or not
*/
public boolean isSecure();
boolean isSecure();
public URI getUri();
/**
* @return the service uri address
*/
URI getUri();
/**
* @return the key value pair metadata associated with the service instance
*/
Map<String, String> getMetadata();
}

Loading…
Cancel
Save