From 83245841b362d670792a6b35e59ef635032535f9 Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Wed, 9 Jul 2014 19:13:49 -0500 Subject: [PATCH] pull up URI-based common functionality into core abstract base class --- .../service/UriBasedServiceInfoCreator.java | 26 +++++++++++++++++++ .../heroku/HerokuServiceInfoCreator.java | 21 +++------------ 2 files changed, 30 insertions(+), 17 deletions(-) create mode 100644 spring-cloud-core/src/main/java/org/springframework/cloud/service/UriBasedServiceInfoCreator.java diff --git a/spring-cloud-core/src/main/java/org/springframework/cloud/service/UriBasedServiceInfoCreator.java b/spring-cloud-core/src/main/java/org/springframework/cloud/service/UriBasedServiceInfoCreator.java new file mode 100644 index 0000000..b856bc0 --- /dev/null +++ b/spring-cloud-core/src/main/java/org/springframework/cloud/service/UriBasedServiceInfoCreator.java @@ -0,0 +1,26 @@ +package org.springframework.cloud.service; + +import org.springframework.cloud.ServiceInfoCreator; +import org.springframework.cloud.AbstractCloudConnector.KeyValuePair; + +public abstract class UriBasedServiceInfoCreator implements + ServiceInfoCreator { + + private final String uriScheme; + + public UriBasedServiceInfoCreator(String uriScheme) { + this.uriScheme = uriScheme; + } + + @Override + public boolean accept(KeyValuePair serviceData) { + return serviceData.getValue().toString().startsWith(uriScheme + "://"); + } + + public abstract SI createServiceInfo(String id, String uri); + + @Override + public SI createServiceInfo(KeyValuePair serviceData) { + return createServiceInfo(serviceData.getKey(), serviceData.getValue()); + } +} diff --git a/spring-cloud-heroku-connector/src/main/java/org/springframework/cloud/heroku/HerokuServiceInfoCreator.java b/spring-cloud-heroku-connector/src/main/java/org/springframework/cloud/heroku/HerokuServiceInfoCreator.java index 00b6c6b..81094eb 100644 --- a/spring-cloud-heroku-connector/src/main/java/org/springframework/cloud/heroku/HerokuServiceInfoCreator.java +++ b/spring-cloud-heroku-connector/src/main/java/org/springframework/cloud/heroku/HerokuServiceInfoCreator.java @@ -1,30 +1,17 @@ package org.springframework.cloud.heroku; -import org.springframework.cloud.AbstractCloudConnector.KeyValuePair; -import org.springframework.cloud.ServiceInfoCreator; import org.springframework.cloud.service.ServiceInfo; +import org.springframework.cloud.service.UriBasedServiceInfoCreator; /** * * @author Ramnivas Laddad * */ -public abstract class HerokuServiceInfoCreator implements ServiceInfoCreator { +public abstract class HerokuServiceInfoCreator extends UriBasedServiceInfoCreator { - private String urlProtocol; - - public HerokuServiceInfoCreator(String urlProtocol) { - this.urlProtocol = urlProtocol; - } - - public boolean accept(KeyValuePair serviceData) { - return serviceData.getValue().toString().startsWith(urlProtocol + "://"); - } - - public abstract SI createServiceInfo(String id, String uri); - - public SI createServiceInfo(KeyValuePair serviceData) { - return createServiceInfo(serviceData.getKey(), serviceData.getValue()); + public HerokuServiceInfoCreator(String uriScheme) { + super(uriScheme); } /**