JsSymbolMap symbolMap = get(symbolMapUrl);
// We only want to request and parse for symbolMaps we havn't already
// parsed.
if (symbolMap == null) {
// Create the XhrCallback to service this request.
XhrCallback xhrCallback = new XhrCallback() {
public void onFail(XMLHttpRequest xhr) {
callback.onSymbolsFetchFailed(ERROR_SYMBOL_FETCH_FAIL);
dequeuePendingXhrs(symbolMapUrl, xhr, false);
if (ClientConfig.isDebugMode()) {
Logging.getLogger().logText(
"Fetching symbol map: " + symbolMapUrl + " failed.");
}
}
public void onSuccess(XMLHttpRequest xhr) {
// Double check that another XHR didnt pull it down and parse it.
JsSymbolMap fetchedSymbolMap = get(symbolMapUrl);
if (fetchedSymbolMap == null) {
fetchedSymbolMap = JsSymbolMap.parse(
resourceSymbolInfo.getSourceServer(),
resourceSymbolInfo.getSourceViewerServer(),
resourceSymbolInfo.getType(), xhr.getResponseText());
put(symbolMapUrl, fetchedSymbolMap);
}
callback.onSymbolsReady(fetchedSymbolMap);
dequeuePendingXhrs(symbolMapUrl, xhr, true);
if (ClientConfig.isDebugMode()) {
Logging.getLogger().logText("Fetched symbol map: " + symbolMapUrl);
}
}
private void dequeuePendingXhrs(String symbolMapUrl,
XMLHttpRequest xhr, boolean success) {
List<XhrCallback> callbacks = queuedSymbolMapRequests.get(symbolMapUrl);
if (callbacks != null) {
while (!callbacks.isEmpty()) {
XhrCallback callback = callbacks.remove(0);
if (success) {
callback.onSuccess(xhr);
} else {
callback.onFail(xhr);
}
}
}
}
};
// Check to see if we have a request in flight.
List<XhrCallback> requestCallbacks = queuedSymbolMapRequests.get(symbolMapUrl);
if (requestCallbacks == null) {
// Make an entry indicating a request is in flight.
queuedSymbolMapRequests.put(symbolMapUrl, new ArrayList<XhrCallback>());
if (ClientConfig.isDebugMode()) {
Logging.getLogger().logText(
"Fetching symbol map URL: " + symbolManifestUrl.getResourceBase()
+ symbolMapUrl);
}
Xhr.get(symbolManifestUrl.getResourceBase() + symbolMapUrl, xhrCallback);
} else {
// There are pending XHRs out. Which means that we should just queue
// this request.
requestCallbacks.add(xhrCallback);
}
} else {
// We have already fetched this and parsed it before. Send it to the
// callback.
callback.onSymbolsReady(symbolMap);
}
}