Skip to content

Commit

Permalink
0002335: Make the ISyncUrlExtension more flexible by always calling a…
Browse files Browse the repository at this point in the history
… registered ISyncUrlExtension
  • Loading branch information
chenson42 committed Jun 26, 2015
1 parent 43055e0 commit d668cdf
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 43 deletions.
Expand Up @@ -65,26 +65,19 @@ public String resolveURL(String syncUrl, String registrationUrl) {
if (StringUtils.isBlank(syncUrl) || syncUrl.startsWith(Constants.PROTOCOL_NONE)) {
log.debug("Using the registration URL to contact the remote node because the syncURL for the node is blank");
return registrationUrl;
} else if (syncUrl.startsWith(Constants.PROTOCOL_EXT)) {
try {
URI uri = new URI(syncUrl);
ISyncUrlExtension handler = null;
if (extensionService != null) {
handler = extensionService.getExtensionPointMap(ISyncUrlExtension.class).get(uri.getHost());
}
if (handler == null) {
log.error("Could not find a registered extension sync url handler with the name of {} using the url {}", uri.getHost(), syncUrl);
return syncUrl;
} else {
return handler.resolveUrl(uri);
}
} catch (URISyntaxException e) {
log.error(e.getMessage(),e);
return syncUrl;
}

try {
URI uri = new URI(syncUrl);

for (ISyncUrlExtension handler : extensionService.getExtensionPointList(ISyncUrlExtension.class)) {
syncUrl = handler.resolveUrl(uri);
uri = new URI(syncUrl);
}
} else {
return syncUrl;
} catch (URISyntaxException e) {
log.error(e.getMessage(),e);
}
return syncUrl;
}

protected String getAcknowledgementData(boolean requires13Format, String nodeId,
Expand Down
Expand Up @@ -29,6 +29,7 @@
import java.util.Map;

import org.jumpmind.extension.IBuiltInExtensionPoint;
import org.jumpmind.symmetric.common.Constants;
import org.jumpmind.symmetric.service.IBandwidthService;
import org.jumpmind.symmetric.service.INodeService;
import org.jumpmind.symmetric.transport.ISyncUrlExtension;
Expand Down Expand Up @@ -70,32 +71,34 @@ public HttpBandwidthUrlSelector(INodeService nodeService,
}

public String resolveUrl(URI uri) {
Map<String, String> params = getParameters(uri);
List<SyncUrl> urls = null;
if (!cachedUrls.containsKey(uri)) {
urls = getUrls(params);
cachedUrls.put(uri, urls);
} else {
urls = cachedUrls.get(uri);
}

boolean initialLoadOnly = isInitialLoadOnly(params);
if ((initialLoadOnly && nodeService != null && !nodeService.isDataLoadCompleted()) || !initialLoadOnly) {
long ts = System.currentTimeMillis();
if (ts - getSampleTTL(params) > lastSampleTs) {
for (SyncUrl syncUrl : urls) {
syncUrl.kbps = bandwidthService.getDownloadKbpsFor(syncUrl.url, getSampleSize(params),
getMaxSampleDuration(params));
if (uri.toString().startsWith(Constants.PROTOCOL_EXT)) {
Map<String, String> params = getParameters(uri);
List<SyncUrl> urls = null;
if (!cachedUrls.containsKey(uri)) {
urls = getUrls(params);
cachedUrls.put(uri, urls);
} else {
urls = cachedUrls.get(uri);
}

boolean initialLoadOnly = isInitialLoadOnly(params);
if ((initialLoadOnly && nodeService != null && !nodeService.isDataLoadCompleted()) || !initialLoadOnly) {
long ts = System.currentTimeMillis();
if (ts - getSampleTTL(params) > lastSampleTs) {
for (SyncUrl syncUrl : urls) {
syncUrl.kbps = bandwidthService.getDownloadKbpsFor(syncUrl.url, getSampleSize(params),
getMaxSampleDuration(params));
}
lastSampleTs = ts;
Collections.sort(urls, new BestBandwidthSorter());
}
lastSampleTs = ts;
Collections.sort(urls, new BestBandwidthSorter());
return urls.get(0).url;
} else {
Collections.sort(urls, new ListOrderSorter());
return urls.get(0).url;
}
return urls.get(0).url;
} else {
Collections.sort(urls, new ListOrderSorter());
return urls.get(0).url;
}

else return uri.toString();
}

protected long getSampleSize(Map<String, String> params) {
Expand Down
Expand Up @@ -67,8 +67,6 @@ public HttpTransportManager() {
public HttpTransportManager(ISymmetricEngine engine) {
super(engine.getExtensionService());
this.engine = engine;
engine.getExtensionService().addExtensionPoint("httpBandwidthUrlSelector", new HttpBandwidthUrlSelector(
engine.getNodeService(), engine.getBandwidthService()));
}

public int sendCopyRequest(Node local) throws IOException {
Expand Down

0 comments on commit d668cdf

Please sign in to comment.