pull up URI-based common functionality into core abstract base class

This commit is contained in:
Christopher Smith
2014-07-09 19:13:49 -05:00
parent 99302432e9
commit 83245841b3
2 changed files with 30 additions and 17 deletions

View File

@@ -0,0 +1,26 @@
package org.springframework.cloud.service;
import org.springframework.cloud.ServiceInfoCreator;
import org.springframework.cloud.AbstractCloudConnector.KeyValuePair;
public abstract class UriBasedServiceInfoCreator<SI extends ServiceInfo> implements
ServiceInfoCreator<ServiceInfo, KeyValuePair> {
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());
}
}

View File

@@ -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<SI extends ServiceInfo> implements ServiceInfoCreator<SI,KeyValuePair> {
public abstract class HerokuServiceInfoCreator<SI extends ServiceInfo> extends UriBasedServiceInfoCreator<SI> {
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);
}
/**