rename KeyValuePair to UriBasedServiceData and rename "value" field
This commit is contained in:
@@ -1,19 +0,0 @@
|
||||
package org.springframework.cloud;
|
||||
|
||||
public class KeyValuePair {
|
||||
private final String key;
|
||||
private final String value;
|
||||
|
||||
public KeyValuePair(String key, String value) {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,10 @@
|
||||
package org.springframework.cloud.service;
|
||||
|
||||
import org.springframework.cloud.FallbackServiceInfoCreator;
|
||||
import org.springframework.cloud.KeyValuePair;
|
||||
|
||||
public class FallbackBaseServiceInfoCreator extends FallbackServiceInfoCreator<BaseServiceInfo, KeyValuePair> {
|
||||
public class FallbackBaseServiceInfoCreator extends FallbackServiceInfoCreator<BaseServiceInfo, UriBasedServiceData> {
|
||||
@Override
|
||||
public BaseServiceInfo createServiceInfo(KeyValuePair serviceData) {
|
||||
public BaseServiceInfo createServiceInfo(UriBasedServiceData serviceData) {
|
||||
return new BaseServiceInfo(serviceData.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package org.springframework.cloud.service;
|
||||
|
||||
public class UriBasedServiceData {
|
||||
private final String key;
|
||||
private final String uri;
|
||||
|
||||
public UriBasedServiceData(String key, String uri) {
|
||||
this.key = key;
|
||||
this.uri = uri;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public String getUri() {
|
||||
return uri;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
package org.springframework.cloud.service;
|
||||
|
||||
import org.springframework.cloud.KeyValuePair;
|
||||
import org.springframework.cloud.ServiceInfoCreator;
|
||||
|
||||
public abstract class UriBasedServiceInfoCreator<SI extends ServiceInfo> implements
|
||||
ServiceInfoCreator<ServiceInfo, KeyValuePair> {
|
||||
ServiceInfoCreator<ServiceInfo, UriBasedServiceData> {
|
||||
|
||||
private final String uriScheme;
|
||||
|
||||
@@ -13,14 +12,14 @@ public abstract class UriBasedServiceInfoCreator<SI extends ServiceInfo> impleme
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accept(KeyValuePair serviceData) {
|
||||
return serviceData.getValue().toString().startsWith(uriScheme + "://");
|
||||
public boolean accept(UriBasedServiceData serviceData) {
|
||||
return serviceData.getUri().toString().startsWith(uriScheme + "://");
|
||||
}
|
||||
|
||||
public abstract SI createServiceInfo(String id, String uri);
|
||||
|
||||
@Override
|
||||
public SI createServiceInfo(KeyValuePair serviceData) {
|
||||
return createServiceInfo(serviceData.getKey(), serviceData.getValue());
|
||||
public SI createServiceInfo(UriBasedServiceData serviceData) {
|
||||
return createServiceInfo(serviceData.getKey(), serviceData.getUri());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,12 +8,12 @@ import java.util.Map;
|
||||
import org.springframework.cloud.AbstractCloudConnector;
|
||||
import org.springframework.cloud.CloudException;
|
||||
import org.springframework.cloud.FallbackServiceInfoCreator;
|
||||
import org.springframework.cloud.KeyValuePair;
|
||||
import org.springframework.cloud.ServiceInfoCreator;
|
||||
import org.springframework.cloud.app.ApplicationInstanceInfo;
|
||||
import org.springframework.cloud.service.BaseServiceInfo;
|
||||
import org.springframework.cloud.service.FallbackBaseServiceInfoCreator;
|
||||
import org.springframework.cloud.service.ServiceInfo;
|
||||
import org.springframework.cloud.service.UriBasedServiceData;
|
||||
import org.springframework.cloud.util.EnvironmentAccessor;
|
||||
|
||||
/**
|
||||
@@ -25,7 +25,7 @@ import org.springframework.cloud.util.EnvironmentAccessor;
|
||||
* @author Ramnivas Laddad
|
||||
*
|
||||
*/
|
||||
public class HerokuConnector extends AbstractCloudConnector<KeyValuePair> {
|
||||
public class HerokuConnector extends AbstractCloudConnector<UriBasedServiceData> {
|
||||
|
||||
private EnvironmentAccessor environment = new EnvironmentAccessor();
|
||||
private ApplicationInstanceInfoCreator applicationInstanceInfoCreator
|
||||
@@ -59,7 +59,7 @@ public class HerokuConnector extends AbstractCloudConnector<KeyValuePair> {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerServiceInfoCreator(ServiceInfoCreator<? extends ServiceInfo, KeyValuePair> serviceInfoCreator) {
|
||||
protected void registerServiceInfoCreator(ServiceInfoCreator<? extends ServiceInfo, UriBasedServiceData> serviceInfoCreator) {
|
||||
super.registerServiceInfoCreator(serviceInfoCreator);
|
||||
HerokuServiceInfoCreator<?> herokuServiceInfoCreator = (HerokuServiceInfoCreator<?>)serviceInfoCreator;
|
||||
String[] envPrefixes = herokuServiceInfoCreator.getEnvPrefixes();
|
||||
@@ -78,15 +78,15 @@ public class HerokuConnector extends AbstractCloudConnector<KeyValuePair> {
|
||||
* </p>
|
||||
* @return information about services bound to the app
|
||||
*/
|
||||
protected List<KeyValuePair> getServicesData() {
|
||||
List<KeyValuePair> serviceData = new ArrayList<KeyValuePair>();
|
||||
protected List<UriBasedServiceData> getServicesData() {
|
||||
List<UriBasedServiceData> serviceData = new ArrayList<UriBasedServiceData>();
|
||||
|
||||
Map<String,String> env = environment.getEnv();
|
||||
|
||||
for (Map.Entry<String, String> envEntry : env.entrySet()) {
|
||||
for (String envPrefix : serviceEnvPrefixes) {
|
||||
if (envEntry.getKey().startsWith(envPrefix)) {
|
||||
serviceData.add(new KeyValuePair(envEntry.getKey(), envEntry.getValue()));
|
||||
serviceData.add(new UriBasedServiceData(envEntry.getKey(), envEntry.getValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -95,7 +95,7 @@ public class HerokuConnector extends AbstractCloudConnector<KeyValuePair> {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FallbackServiceInfoCreator<BaseServiceInfo,KeyValuePair> getFallbackServiceInfoCreator() {
|
||||
protected FallbackServiceInfoCreator<BaseServiceInfo,UriBasedServiceData> getFallbackServiceInfoCreator() {
|
||||
return new FallbackBaseServiceInfoCreator();
|
||||
}
|
||||
}
|
||||
@@ -15,18 +15,18 @@ import java.util.regex.Pattern;
|
||||
|
||||
import org.springframework.cloud.AbstractCloudConnector;
|
||||
import org.springframework.cloud.FallbackServiceInfoCreator;
|
||||
import org.springframework.cloud.KeyValuePair;
|
||||
import org.springframework.cloud.app.ApplicationInstanceInfo;
|
||||
import org.springframework.cloud.app.BasicApplicationInstanceInfo;
|
||||
import org.springframework.cloud.service.BaseServiceInfo;
|
||||
import org.springframework.cloud.service.FallbackBaseServiceInfoCreator;
|
||||
import org.springframework.cloud.service.UriBasedServiceData;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Christopher Smith
|
||||
*
|
||||
*/
|
||||
public class LocalConfigConnector extends AbstractCloudConnector<KeyValuePair> {
|
||||
public class LocalConfigConnector extends AbstractCloudConnector<UriBasedServiceData> {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(LocalConfigConnector.class.getName());
|
||||
|
||||
@@ -78,7 +78,7 @@ public class LocalConfigConnector extends AbstractCloudConnector<KeyValuePair> {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<KeyValuePair> getServicesData() {
|
||||
protected List<UriBasedServiceData> getServicesData() {
|
||||
if(fileProperties == null)
|
||||
throw new IllegalStateException("isInMatchingCloud() must be called first to initialize connector");
|
||||
|
||||
@@ -97,7 +97,7 @@ public class LocalConfigConnector extends AbstractCloudConnector<KeyValuePair> {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FallbackServiceInfoCreator<BaseServiceInfo, KeyValuePair> getFallbackServiceInfoCreator() {
|
||||
protected FallbackServiceInfoCreator<BaseServiceInfo, UriBasedServiceData> getFallbackServiceInfoCreator() {
|
||||
return new FallbackBaseServiceInfoCreator();
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.util.Properties;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
import org.springframework.cloud.KeyValuePair;
|
||||
import org.springframework.cloud.service.UriBasedServiceData;
|
||||
|
||||
public final class LocalConfigUtil {
|
||||
private static final Logger logger = Logger.getLogger(LocalConfigConnector.class.getName());
|
||||
@@ -17,7 +17,7 @@ public final class LocalConfigUtil {
|
||||
private LocalConfigUtil() {
|
||||
}
|
||||
|
||||
static List<KeyValuePair> readServicesData(LinkedHashMap<String, Properties> propertySources) {
|
||||
static List<UriBasedServiceData> readServicesData(LinkedHashMap<String, Properties> propertySources) {
|
||||
// we'll turn this into KVPs to return but need to eliminate duplicates first
|
||||
Map<String, String> collectedServices = new HashMap<String, String>();
|
||||
|
||||
@@ -41,9 +41,9 @@ public final class LocalConfigUtil {
|
||||
}
|
||||
|
||||
// now we have a collated set of service IDs and URIs
|
||||
List<KeyValuePair> serviceData = new ArrayList<KeyValuePair>(collectedServices.size());
|
||||
List<UriBasedServiceData> serviceData = new ArrayList<UriBasedServiceData>(collectedServices.size());
|
||||
for (Map.Entry<String, String> serviceInfo : collectedServices.entrySet()) {
|
||||
serviceData.add(new KeyValuePair(serviceInfo.getKey(), serviceInfo.getValue()));
|
||||
serviceData.add(new UriBasedServiceData(serviceInfo.getKey(), serviceInfo.getValue()));
|
||||
}
|
||||
|
||||
return serviceData;
|
||||
|
||||
@@ -17,7 +17,7 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.contrib.java.lang.system.ClearSystemProperties;
|
||||
import org.junit.contrib.java.lang.system.ProvideSystemProperty;
|
||||
import org.springframework.cloud.KeyValuePair;
|
||||
import org.springframework.cloud.service.UriBasedServiceData;
|
||||
|
||||
public class LocalConfigConnectorTest {
|
||||
|
||||
@@ -119,11 +119,11 @@ public class LocalConfigConnectorTest {
|
||||
assertTrue(connector.isInMatchingCloud());
|
||||
assertEquals("testApp", connector.getApplicationInstanceInfo().getAppId());
|
||||
|
||||
List<KeyValuePair> services = connector.getServicesData();
|
||||
List<UriBasedServiceData> services = connector.getServicesData();
|
||||
assertEquals(2, services.size());
|
||||
for (KeyValuePair service : services)
|
||||
for (UriBasedServiceData service : services)
|
||||
if ("foo".equals(service.getKey()))
|
||||
assertEquals("bar", service.getValue());
|
||||
assertEquals("bar", service.getUri());
|
||||
}
|
||||
|
||||
@Rule
|
||||
@@ -136,10 +136,10 @@ public class LocalConfigConnectorTest {
|
||||
assertTrue(connector.isInMatchingCloud());
|
||||
assertEquals("testApp", connector.getApplicationInstanceInfo().getAppId());
|
||||
|
||||
List<KeyValuePair> services = connector.getServicesData();
|
||||
List<UriBasedServiceData> services = connector.getServicesData();
|
||||
assertEquals(2, services.size());
|
||||
for(KeyValuePair service: services)
|
||||
for(UriBasedServiceData service: services)
|
||||
if("baz".equals(service.getKey()))
|
||||
assertEquals("inline!", service.getValue());
|
||||
assertEquals("inline!", service.getUri());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.util.Properties;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.cloud.KeyValuePair;
|
||||
import org.springframework.cloud.service.UriBasedServiceData;
|
||||
|
||||
public class LocalConfigUtilTest {
|
||||
|
||||
@@ -46,13 +46,13 @@ public class LocalConfigUtilTest {
|
||||
first.setProperty("spring.cloud.first", "firstUri");
|
||||
second.setProperty("spring.cloud.second", "secondUri");
|
||||
|
||||
List<KeyValuePair> serviceData = LocalConfigUtil.readServicesData(propertySources);
|
||||
List<UriBasedServiceData> serviceData = LocalConfigUtil.readServicesData(propertySources);
|
||||
assertEquals(2, serviceData.size());
|
||||
boolean foundFirst = false;
|
||||
|
||||
for(KeyValuePair kvp : serviceData) {
|
||||
for(UriBasedServiceData kvp : serviceData) {
|
||||
if(kvp.getKey().equals("first")) {
|
||||
assertEquals("firstUri", kvp.getValue());
|
||||
assertEquals("firstUri", kvp.getUri());
|
||||
foundFirst = true;
|
||||
}
|
||||
}
|
||||
@@ -65,10 +65,10 @@ public class LocalConfigUtilTest {
|
||||
first.setProperty("spring.cloud.duplicate", "firstUri");
|
||||
second.setProperty("spring.cloud.duplicate", "secondUri");
|
||||
|
||||
List<KeyValuePair> serviceData = LocalConfigUtil.readServicesData(propertySources);
|
||||
List<UriBasedServiceData> serviceData = LocalConfigUtil.readServicesData(propertySources);
|
||||
assertEquals(1, serviceData.size());
|
||||
KeyValuePair kvp = serviceData.get(0);
|
||||
UriBasedServiceData kvp = serviceData.get(0);
|
||||
assertEquals("duplicate", kvp.getKey());
|
||||
assertEquals("secondUri", kvp.getValue());
|
||||
assertEquals("secondUri", kvp.getUri());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user