From f9cffe9f3c8291dfc8ad2eda39afe80f2e8071a1 Mon Sep 17 00:00:00 2001 From: Jakub Narloch Date: Sun, 1 Nov 2015 12:06:09 +0100 Subject: [PATCH] Introduced ServiceInstance metadata map. --- .../cloud/client/DefaultServiceInstance.java | 15 ++++++++++++++ .../cloud/client/ServiceInstance.java | 20 +++++++++++++------ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/DefaultServiceInstance.java b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/DefaultServiceInstance.java index b9038ac8..49e0f0e3 100644 --- a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/DefaultServiceInstance.java +++ b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/DefaultServiceInstance.java @@ -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; * @author Spencer Gibb */ @Data +@RequiredArgsConstructor public class DefaultServiceInstance implements ServiceInstance { private final String serviceId; @@ -36,11 +40,22 @@ public class DefaultServiceInstance implements ServiceInstance { private final boolean secure; + private final Map metadata; + + public DefaultServiceInstance(String serviceId, String host, int port, boolean secure) { + this(serviceId, host, port, secure, Collections.emptyMap()); + } + @Override public URI getUri() { return getUri(this); } + @Override + public Map getMetadata() { + return metadata; + } + /** * Create a uri from the given ServiceInstance's host:port * @param instance diff --git a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/ServiceInstance.java b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/ServiceInstance.java index 7cd52f72..ca99e692 100644 --- a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/ServiceInstance.java +++ b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/ServiceInstance.java @@ -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 { /** * @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 getMetadata(); }