Skip to content

Commit

Permalink
New request scheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed May 19, 2017
1 parent d3e0aba commit 00d6f25
Show file tree
Hide file tree
Showing 52 changed files with 1,624 additions and 390 deletions.
38 changes: 19 additions & 19 deletions Source/Core/CesiumTerrainProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ define([
'./Math',
'./OrientedBoundingBox',
'./QuantizedMeshTerrainData',
'./Request',
'./RequestType',
'./TerrainProvider',
'./throttleRequestByServer',
'./TileAvailability',
'./TileProviderError'
], function(
Expand All @@ -43,14 +44,15 @@ define([
CesiumMath,
OrientedBoundingBox,
QuantizedMeshTerrainData,
Request,
RequestType,
TerrainProvider,
throttleRequestByServer,
TileAvailability,
TileProviderError) {
'use strict';

/**
* A {@link TerrainProvider} that access terrain data in a Cesium terrain format.
* A {@link TerrainProvider} that accesses terrain data in a Cesium terrain format.
* The format is described on the
* {@link https://github.com/AnalyticalGraphicsInc/cesium/wiki/Cesium-Terrain-Server|Cesium wiki}.
*
Expand Down Expand Up @@ -489,17 +491,16 @@ define([
* @param {Number} x The X coordinate of the tile for which to request geometry.
* @param {Number} y The Y coordinate of the tile for which to request geometry.
* @param {Number} level The level of the tile for which to request geometry.
* @param {Boolean} [throttleRequests=true] True if the number of simultaneous requests should be limited,
* or false if the request should be initiated regardless of the number of requests
* already in progress.
* @param {Request} [request] The request object.
*
* @returns {Promise.<TerrainData>|undefined} A promise for the requested geometry. If this method
* returns undefined instead of a promise, it is an indication that too many requests are already
* pending and the request will be retried later.
*
* @exception {DeveloperError} This function must not be called before {@link CesiumTerrainProvider#ready}
* returns true.
*/
CesiumTerrainProvider.prototype.requestTileGeometry = function(x, y, level, throttleRequests) {
CesiumTerrainProvider.prototype.requestTileGeometry = function(x, y, level, request) {
//>>includeStart('debug', pragmas.debug)
if (!this._ready) {
throw new DeveloperError('requestTileGeometry must not be called before the terrain provider is ready.');
Expand All @@ -522,8 +523,6 @@ define([
url = proxy.getURL(url);
}

var promise;

var extensionList = [];
if (this._requestVertexNormals && this._hasVertexNormals) {
extensionList.push(this._littleEndianExtensionSize ? 'octvertexnormals' : 'vertexnormals');
Expand All @@ -532,17 +531,18 @@ define([
extensionList.push('watermask');
}

function tileLoader(tileUrl) {
return loadArrayBuffer(tileUrl, getRequestHeader(extensionList));
// TODO - remove later, this to handle the deprecated throttleRequests parameter
if (typeof request === 'boolean') {
request = new Request({
throttle : request,
type : RequestType.TERRAIN
});
}
throttleRequests = defaultValue(throttleRequests, true);
if (throttleRequests) {
promise = throttleRequestByServer(url, tileLoader);
if (!defined(promise)) {
return undefined;
}
} else {
promise = tileLoader(url);

var promise = loadArrayBuffer(url, getRequestHeader(extensionList), request);

if (!defined(promise)) {
return undefined;
}

var that = this;
Expand Down
7 changes: 3 additions & 4 deletions Source/Core/EllipsoidTerrainProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,13 @@ define([
* @param {Number} x The X coordinate of the tile for which to request geometry.
* @param {Number} y The Y coordinate of the tile for which to request geometry.
* @param {Number} level The level of the tile for which to request geometry.
* @param {Boolean} [throttleRequests=true] True if the number of simultaneous requests should be limited,
* or false if the request should be initiated regardless of the number of requests
* already in progress.
* @param {Request} [request] The request object.
*
* @returns {Promise.<TerrainData>|undefined} A promise for the requested geometry. If this method
* returns undefined instead of a promise, it is an indication that too many requests are already
* pending and the request will be retried later.
*/
EllipsoidTerrainProvider.prototype.requestTileGeometry = function(x, y, level, throttleRequests) {
EllipsoidTerrainProvider.prototype.requestTileGeometry = function(x, y, level, request) {
var width = 16;
var height = 16;
return new HeightmapTerrainData({
Expand Down
63 changes: 33 additions & 30 deletions Source/Core/GoogleEarthEnterpriseMetadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ define([
'./GoogleEarthEnterpriseTileInformation',
'./isBitSet',
'./loadArrayBuffer',
'./Request',
'./RequestType',
'./RuntimeError',
'./TaskProcessor',
'./throttleRequestByServer'
'./TaskProcessor'
], function(
when,
appendForwardSlash,
Expand All @@ -22,9 +23,10 @@ define([
GoogleEarthEnterpriseTileInformation,
isBitSet,
loadArrayBuffer,
Request,
RequestType,
RuntimeError,
TaskProcessor,
throttleRequestByServer) {
TaskProcessor) {
'use strict';

/**
Expand Down Expand Up @@ -55,7 +57,7 @@ define([
this._subtreePromises = {};

var that = this;
this._readyPromise = this.getQuadTreePacket('', 1, false)
this._readyPromise = this.getQuadTreePacket('', 1)
.then(function() {
return true;
})
Expand Down Expand Up @@ -216,30 +218,23 @@ define([
*
* @param {String} [quadKey=''] The quadkey to retrieve the packet for.
* @param {Number} [version=1] The cnode version to be used in the request.
* @param {Boolean} [throttle=true] True if the number of simultaneous requests should be limited,
* or false if the request should be initiated regardless of the number of requests
* already in progress.
* @param {Request} [request] The request object.
*
* @private
*/
GoogleEarthEnterpriseMetadata.prototype.getQuadTreePacket = function(quadKey, version, throttle) {
GoogleEarthEnterpriseMetadata.prototype.getQuadTreePacket = function(quadKey, version, request) {
version = defaultValue(version, 1);
quadKey = defaultValue(quadKey, '');
throttle = defaultValue(throttle, true);
var url = getMetadataUrl(this, quadKey, version);
var proxy = this._proxy;
if (defined(proxy)) {
url = proxy.getURL(url);
}

var promise;
if (throttle) {
promise = throttleRequestByServer(url, loadArrayBuffer);
if (!defined(promise)) {
return undefined;
}
} else {
promise = loadArrayBuffer(url);
var promise = loadArrayBuffer(url, undefined, request);

if (!defined(promise)) {
return undefined; // Throttled
}

var tileInfo = this._tileInfo;
Expand Down Expand Up @@ -300,21 +295,18 @@ define([
* @param {Number} x The tile X coordinate.
* @param {Number} y The tile Y coordinate.
* @param {Number} level The tile level.
* @param {Boolean} [throttle=true] True if the number of simultaneous requests should be limited,
* or false if the request should be initiated regardless of the number of requests
* already in progress.
* @param {Request} [request] The request object.
*
* @returns {Promise<GoogleEarthEnterpriseTileInformation>} A promise that resolves to the tile info for the requested quad key
*
* @private
*/
GoogleEarthEnterpriseMetadata.prototype.populateSubtree = function(x, y, level, throttle) {
throttle = defaultValue(throttle, true);
GoogleEarthEnterpriseMetadata.prototype.populateSubtree = function(x, y, level, request) {
var quadkey = GoogleEarthEnterpriseMetadata.tileXYToQuadKey(x, y, level);
return populateSubtree(this, quadkey, throttle);
return populateSubtree(this, quadkey, request);
};

function populateSubtree(that, quadKey, throttle) {
function populateSubtree(that, quadKey, request) {
var tileInfo = that._tileInfo;
var q = quadKey;
var t = tileInfo[q];
Expand All @@ -328,13 +320,19 @@ define([
t = tileInfo[q];
}

var subtreeRequest;
var subtreePromises = that._subtreePromises;
var promise = subtreePromises[q];
if (defined(promise)) {
return promise
.then(function() {
// Recursively call this incase we need multiple subtree requests
return populateSubtree(that, quadKey, throttle);
// Recursively call this in case we need multiple subtree requests
subtreeRequest = new Request({
throttle : request.throttle,
type : request.type,
distance : request.distance
});
return populateSubtree(that, quadKey, subtreeRequest);
});
}

Expand All @@ -349,16 +347,21 @@ define([
// We need to split up the promise here because when will execute syncronously if getQuadTreePacket
// is already resolved (like in the tests), so subtreePromises will never get cleared out.
// Only the initial request will also remove the promise from subtreePromises.
promise = that.getQuadTreePacket(q, t.cnodeVersion, throttle);
promise = that.getQuadTreePacket(q, t.cnodeVersion, request);
if (!defined(promise)) {
return undefined;
}
subtreePromises[q] = promise;

return promise
.then(function() {
// Recursively call this incase we need multiple subtree requests
return populateSubtree(that, quadKey, throttle);
// Recursively call this in case we need multiple subtree requests
subtreeRequest = new Request({
throttle : request.throttle,
type : request.type,
distance : request.distance
});
return populateSubtree(that, quadKey, subtreeRequest);
})
.always(function() {
delete subtreePromises[q];
Expand Down
39 changes: 23 additions & 16 deletions Source/Core/GoogleEarthEnterpriseTerrainProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ define([
'./loadArrayBuffer',
'./Math',
'./Rectangle',
'./Request',
'./RequestType',
'./RuntimeError',
'./TaskProcessor',
'./throttleRequestByServer',
'./TileProviderError'
], function(
when,
Expand All @@ -35,9 +36,10 @@ define([
loadArrayBuffer,
CesiumMath,
Rectangle,
Request,
RequestType,
RuntimeError,
TaskProcessor,
throttleRequestByServer,
TileProviderError) {
'use strict';

Expand Down Expand Up @@ -332,17 +334,15 @@ define([
* @param {Number} x The X coordinate of the tile for which to request geometry.
* @param {Number} y The Y coordinate of the tile for which to request geometry.
* @param {Number} level The level of the tile for which to request geometry.
* @param {Boolean} [throttleRequests=true] True if the number of simultaneous requests should be limited,
* or false if the request should be initiated regardless of the number of requests
* already in progress.
* @param {Request} [request] The request object.
* @returns {Promise.<TerrainData>|undefined} A promise for the requested geometry. If this method
* returns undefined instead of a promise, it is an indication that too many requests are already
* pending and the request will be retried later.
*
* @exception {DeveloperError} This function must not be called before {@link GoogleEarthEnterpriseProvider#ready}
* returns true.
*/
GoogleEarthEnterpriseTerrainProvider.prototype.requestTileGeometry = function(x, y, level, throttleRequests) {
GoogleEarthEnterpriseTerrainProvider.prototype.requestTileGeometry = function(x, y, level, request) {
//>>includeStart('debug', pragmas.debug)
if (!this._ready) {
throw new DeveloperError('requestTileGeometry must not be called before the terrain provider is ready.');
Expand Down Expand Up @@ -428,15 +428,18 @@ define([
if (defined(terrainPromises[q])) { // Already being loaded possibly from another child, so return existing promise
promise = terrainPromises[q];
} else { // Create new request for terrain
var requestPromise;
throttleRequests = defaultValue(throttleRequests, true);
if (throttleRequests) {
requestPromise = throttleRequestByServer(url, loadArrayBuffer);
if (!defined(requestPromise)) {
return undefined; // Throttled
}
} else {
requestPromise = loadArrayBuffer(url);
// TODO - remove later, this to handle the deprecated throttleRequests parameter
if (typeof request === 'boolean') {
request = new Request({
throttle : request,
type : RequestType.TERRAIN
});
}

var requestPromise = loadArrayBuffer(url, undefined, request);

if (!defined(requestPromise)) {
return undefined; // Throttled
}

promise = requestPromise
Expand Down Expand Up @@ -549,7 +552,11 @@ define([

if (metadata.isValid(quadKey)) {
// We will need this tile, so request metadata and return false for now
metadata.populateSubtree(x, y, level);
var request = new Request({
throttle : true,
type : RequestType.TERRAIN
});
metadata.populateSubtree(x, y, level, request);
}
return false;
};
Expand Down
Loading

0 comments on commit 00d6f25

Please sign in to comment.