Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Commit

Permalink
HARP-16533 Worker connection timeout can be configured (#2287)
Browse files Browse the repository at this point in the history
Signed-off-by: Jonathan Stichbury <2533428+nzjony@users.noreply.github.com>
  • Loading branch information
nzjony committed Aug 20, 2021
1 parent 6af2cb3 commit 13b1c4b
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 40 deletions.
9 changes: 8 additions & 1 deletion @here/harp-mapview-decoder/lib/TileDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ export interface TileDataSourceOptions extends DataSourceOptions {
*/
concurrentDecoderWorkerCount?: number;

/**
* Timeout for connecting to the web worker in seconds. Default to 10s, search for:
* DEFAULT_WORKER_INITIALIZATION_TIMEOUT
*/
workerConnectionTimeout?: number;

/**
* Optional, default copyright information of tiles provided by this data source.
* Implementation should provide this information from the source data if possible.
Expand Down Expand Up @@ -140,7 +146,8 @@ export class TileDataSource<TileType extends Tile = Tile> extends DataSource {
this.m_decoder = ConcurrentDecoderFacade.getTileDecoder(
m_options.concurrentDecoderServiceName,
m_options.concurrentDecoderScriptUrl,
m_options.concurrentDecoderWorkerCount
m_options.concurrentDecoderWorkerCount,
m_options.workerConnectionTimeout
);
} else {
throw new Error(
Expand Down
18 changes: 14 additions & 4 deletions @here/harp-mapview/lib/ConcurrentDecoderFacade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ export class ConcurrentDecoderFacade {
* @param decoderServiceType - The name of the decoder service type.
* @param scriptUrl - The optional URL with the workers' script.
* @param workerCount - The number of web workers to use.
* @param workerConnectionTimeout - Timeout in seconds to connect to the web worker.
*/
static getTileDecoder(
decoderServiceType: string,
scriptUrl?: string,
workerCount?: number
workerCount?: number,
workerConnectionTimeout?: number
): ITileDecoder {
const workerSet = this.getWorkerSet(scriptUrl, workerCount);
const workerSet = this.getWorkerSet(scriptUrl, workerCount, workerConnectionTimeout);

return new WorkerBasedDecoder(workerSet, decoderServiceType);
}
Expand All @@ -50,17 +52,25 @@ export class ConcurrentDecoderFacade {
* @param scriptUrl - The optional URL with the workers' script. If not specified,
* the function uses [[defaultScriptUrl]] instead.
* @param workerCount - The number of web workers to use.
* @param workerConnectionTimeout - Timeout in seconds to connect to the web worker.
*/
static getWorkerSet(scriptUrl?: string, workerCount?: number): ConcurrentWorkerSet {
static getWorkerSet(
scriptUrl?: string,
workerCount?: number,
workerConnectionTimeout?: number
): ConcurrentWorkerSet {
if (scriptUrl === undefined) {
scriptUrl = this.defaultScriptUrl;
}

let workerSet = this.workerSets[scriptUrl];
if (workerSet === undefined) {
const workerConnectionTimeoutInMs =
workerConnectionTimeout !== undefined ? workerConnectionTimeout * 1000 : undefined;
workerSet = new ConcurrentWorkerSet({
scriptUrl,
workerCount: workerCount === undefined ? this.defaultWorkerCount : workerCount
workerCount: workerCount ?? this.defaultWorkerCount,
workerConnectionTimeout: workerConnectionTimeoutInMs
});
this.workerSets[scriptUrl] = workerSet;
}
Expand Down
22 changes: 18 additions & 4 deletions @here/harp-mapview/lib/ConcurrentTilerFacade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,15 @@ export class ConcurrentTilerFacade {
* @param tilerServiceType - The name of the tiler service type.
* @param scriptUrl - The optional URL with the workers' script.
* @param workerCount - The number of web workers to use.
* @param workerConnectionTimeout - Timeout in seconds to connect to the web worker.
*/
static getTiler(tilerServiceType: string, scriptUrl?: string, workerCount?: number): ITiler {
const workerSet = this.getWorkerSet(scriptUrl, workerCount);
static getTiler(
tilerServiceType: string,
scriptUrl?: string,
workerCount?: number,
workerConnectionTimeout?: number
): ITiler {
const workerSet = this.getWorkerSet(scriptUrl, workerCount, workerConnectionTimeout);

return new WorkerBasedTiler(workerSet, tilerServiceType);
}
Expand All @@ -46,17 +52,25 @@ export class ConcurrentTilerFacade {
* @param scriptUrl - The optional URL with the workers' script. If not specified,
* the function uses [[defaultScriptUrl]] instead.
* @param workerCount - The number of web workers to use.
* @param workerConnectionTimeout - Timeout in seconds to connect to the web worker.
*/
static getWorkerSet(scriptUrl?: string, workerCount?: number): ConcurrentWorkerSet {
static getWorkerSet(
scriptUrl?: string,
workerCount?: number,
workerConnectionTimeout?: number
): ConcurrentWorkerSet {
if (scriptUrl === undefined) {
scriptUrl = this.defaultScriptUrl;
}

let workerSet = this.workerSets[scriptUrl];
if (workerSet === undefined) {
const workerConnectionTimeoutInMs =
workerConnectionTimeout !== undefined ? workerConnectionTimeout * 1000 : undefined;
workerSet = new ConcurrentWorkerSet({
scriptUrl,
workerCount: workerCount === undefined ? this.defaultWorkerCount : workerCount
workerCount: workerCount ?? this.defaultWorkerCount,
workerConnectionTimeout: workerConnectionTimeoutInMs
});
this.workerSets[scriptUrl] = workerSet;
}
Expand Down
9 changes: 8 additions & 1 deletion @here/harp-vectortile-datasource/lib/GeoJsonDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ export interface GeoJsonDataProviderOptions {
* from `ConcurrentTilerFacade`.
*/
tiler?: ITiler;

/**
* Timeout for connecting to the web worker in seconds. Default to 10s, search for:
* DEFAULT_WORKER_INITIALIZATION_TIMEOUT
*/
workerConnectionTimeout?: number;
}

let missingTilerServiceInfoEmitted: boolean = false;
Expand Down Expand Up @@ -66,7 +72,8 @@ export class GeoJsonDataProvider extends DataProvider {
options?.tiler ??
ConcurrentTilerFacade.getTiler(
GEOJSON_TILER_SERVICE_TYPE,
options && options.workerTilerUrl
options?.workerTilerUrl,
options?.workerConnectionTimeout
);
}

Expand Down
38 changes: 8 additions & 30 deletions @here/harp-vectortile-datasource/lib/VectorTileDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,9 @@
* Licensed under Apache 2.0, see full license in LICENSE
* SPDX-License-Identifier: Apache-2.0
*/
import {
DecoderOptions,
ITileDecoder,
OptionsMap,
WorkerServiceProtocol
} from "@here/harp-datasource-protocol";
import { DecoderOptions, OptionsMap, WorkerServiceProtocol } from "@here/harp-datasource-protocol";
import { EarthConstants, TileKey, webMercatorTilingScheme } from "@here/harp-geoutils";
import { CopyrightInfo, CopyrightProvider, DataSourceOptions, Tile } from "@here/harp-mapview";
import { DataSourceOptions, Tile } from "@here/harp-mapview";
import {
DataProvider,
TileDataSource,
Expand Down Expand Up @@ -39,7 +34,10 @@ export interface VectorTileFactory {
createTile(dataSource: VectorTileDataSource, tileKey: TileKey): Tile;
}

export interface VectorTileDataSourceParameters extends DataSourceOptions {
export interface VectorTileDataSourceParameters
extends DataSourceOptions,
// These parameters have to be handled specially, see: completeDataSourceParameters
Omit<TileDataSourceOptions, "dataProvider" | "tilingScheme"> {
/**
* If set to `true`, features that have no technique in the theme will be printed to the console
* (can be excessive!).
Expand All @@ -53,21 +51,11 @@ export interface VectorTileDataSourceParameters extends DataSourceOptions {
*/
createTileInfo?: boolean;

/**
* Specify the decoder that should be used. If not supplied, the default will be used.
*/
decoder?: ITileDecoder;

/**
* Optionally specify the DataProvider that should be used.
*/
dataProvider?: DataProvider;

/**
* Specify the URL to the decoder bundle. If not supplied, the default will be used.
*/
concurrentDecoderScriptUrl?: string;

/**
* Gather feature IDs from `OmvData`. Defaults to `false`.
* @deprecated FeatureIds are always gathered, use [[gatherFeatureAttributes]] to gather
Expand Down Expand Up @@ -132,17 +120,6 @@ export interface VectorTileDataSourceParameters extends DataSourceOptions {
*/
politicalView?: string;

/**
* Optional, default copyright information of tiles provided by this data source.
* Implementation should provide this information from the source data if possible.
*/
copyrightInfo?: CopyrightInfo[];

/**
* Optional copyright info provider for tiles provided by this data source.
*/
copyrightProvider?: CopyrightProvider;

/**
* Indicates whether overlay on elevation is enabled. Defaults to `false`.
*/
Expand Down Expand Up @@ -284,7 +261,8 @@ export class VectorTileDataSource extends TileDataSource {
constructor(private readonly m_params: OmvWithRestClientParams | OmvWithCustomDataProvider) {
super(m_params.tileFactory ?? new TileFactory(Tile), {
styleSetName: m_params.styleSetName ?? "omv",
concurrentDecoderServiceName: VECTOR_TILE_DECODER_SERVICE_TYPE,
concurrentDecoderServiceName:
m_params.concurrentDecoderServiceName ?? VECTOR_TILE_DECODER_SERVICE_TYPE,
minDataLevel: m_params.minDataLevel ?? 1,
maxDataLevel: m_params.maxDataLevel ?? 17,
storageLevelOffset: m_params.storageLevelOffset ?? -1,
Expand Down

0 comments on commit 13b1c4b

Please sign in to comment.