/** @packageDocumentation
 * @module Tiles
 */
import { IModelConnection } from "../IModelConnection";
import { Tile, TileContent, TileRequest } from "./internal";
/** As part of a [[TileRequestChannelStatistics]], summarizes cumulative time spent decoding tile content.
 * For each Tile, the time elapsed between receiving the raw tile content (e.g., over the network) and converting it to a [[TileContent]] via [[Tile.readContent]]
 * is recorded.
 * All times are reported in milliseconds.
 * @beta
 */
export interface TileContentDecodingStatistics {
    /** The total number of milliseconds spent decoding content. */
    total: number;
    /** The mean (average) number of milliseconds spent decoding content. */
    mean: number;
    /** The longest amount of time, in milliseconds, spent decoding any single tile's content. */
    max: number;
    /** The shortest amount of time, in milliseconds, spent decoding any single tile's content. */
    min: number;
}
/** Statistics regarding the current and cumulative state of one or more [[TileRequestChannel]]s. Useful for monitoring performance and diagnosing problems.
 * @see [[TileRequestChannel.statistics]] for a specific channel's statistics.
 * @see [[TileRequestChannels.statistics]] for statistics from all channels.
 * @see [[TileAdmin.statistics]] for additional statistics.
 * @public
 * @extensions
 */
export declare class TileRequestChannelStatistics {
    /** The number of queued requests that have not yet been dispatched. */
    numPendingRequests: number;
    /** The number of requests that have been dispatched but not yet completed. */
    numActiveRequests: number;
    /** The number of requests canceled during the most recent update. */
    numCanceled: number;
    /** The total number of completed requests during this session. */
    totalCompletedRequests: number;
    /** The total number of failed requests during this session. */
    totalFailedRequests: number;
    /** The total number of timed-out requests during this session. */
    totalTimedOutRequests: number;
    /** The total number of completed requests during this session which produced an empty tile.
     * These tiles also contribute to [[totalCompletedRequests]], but not to [[totalUndisplayableTiles]].
     */
    totalEmptyTiles: number;
    /** The total number of completed requests during this session that produced an undisplayable tile.
     * These tiles also contribute to [[totalCompletedRequests]], but not to [[totalEmptyTiles]].
     */
    totalUndisplayableTiles: number;
    /** The total number of tiles whose contents were not found in cloud storage cache and therefore resulted in a backend request to generate the tile content. */
    totalCacheMisses: number;
    /** The total number of tiles for which content requests were dispatched. */
    totalDispatchedRequests: number;
    /** The total number of tiles for which content requests were dispatched and then canceled on the backend before completion. */
    totalAbortedRequests: number;
    /** Statistics summarizing time spent decoding tile content.
     * @beta
     */
    decoding: TileContentDecodingStatistics;
    /** @internal */
    addTo(stats: TileRequestChannelStatistics): void;
    /** @internal */
    recordCompletion(tile: Tile, elapsedMilliseconds: number): void;
}
/** A channel over which requests for tile content can be made. The channel may request content over HTTP, calls to the backend via IPC or RPC, or any other method like generating the content
 * on the frontend. The channel consists of a queue of pending requests and a set of "active" requests (dispatched and awaiting a response). Incoming requests are placed onto the queue. Requests are popped of the queue in order of priority and dispatched, until the maximum number of simultaneously-active requests is reached.
 * The maximum number of active requests depends on the transport mechanism. For HTTP 1.1, browsers impose a limit of 6 simultaneous connections to a given domain, so ideally each unique domain will use its own unique channel with a limit of 6 active requests. Even for requests satisfied entirely by the frontend, imposing a limit is important for throttling the amount of work done at one time, especially because as the user navigates the view, tiles that were previously requested may no longer be of interest and we shouldn't waste resources producing their content.
 * A channel must be registered with [[TileRequestChannels]] and must have a unique name among all registered channels.
 * @see [[TileRequestChannels.getForHttp]] to obtain (and register if not already registered) an HTTP-based channel.
 * @see [[TileAdmin.channels]] for the channels configured for use with the iTwin.js display system.
 * @see [[Tile.channel]] to specify the channel to be used to request a given tile's content.
 * @public
 * @extensions
 */
export declare class TileRequestChannel {
    /** The channel's name. It must be unique among all registered [[TileRequestChannels]]. */
    readonly name: string;
    private _concurrency;
    /** Protected strictly for tests. @internal */
    protected readonly _active: Set<TileRequest>;
    private _pending;
    private _previouslyPending;
    protected _statistics: TileRequestChannelStatistics;
    /** Callback invoked by recordCompletion. See IModelTileMetadataCacheChannel.
     * @internal
     */
    contentCallback?: (tile: Tile, content: TileContent) => void;
    /** Create a new channel.
     * @param name The unique name of the channel.
     * @param concurrency The maximum number of requests that can be dispatched and awaiting a response at any given time. Requests beyond this maximum are enqueued for deferred dispatch.
     * @see [[TileRequestChannels.getForHttp]] to create an HTTP-based channel.
     */
    constructor(name: string, concurrency: number);
    /** The maximum number of active requests. This is generally only modified for debugging purposes.
     * @note When reducing `concurrency`, the number of active requests ([[numActive]]) will only decrease to the new value after a sufficient number of dispatched requests are resolved.
     */
    get concurrency(): number;
    set concurrency(max: number);
    /** The number of requests that have been dispatched and are awaiting a response. */
    get numActive(): number;
    /** The number of requests that have been enqueued for later dispatch. */
    get numPending(): number;
    /** The total number of requests in this channel, whether dispatched or enqueued. */
    get size(): number;
    /** Statistics intended primarily for debugging. */
    get statistics(): Readonly<TileRequestChannelStatistics>;
    /** Reset all of this channel's [[statistics]] to zero. */
    resetStatistics(): void;
    /** Invoked by [[TileRequest]] when a request times out.
     * @internal
     */
    recordTimeout(): void;
    /** Invoked by [[TileRequest]] when a request fails to produce a response.
     * @internal
     */
    recordFailure(): void;
    /** Invoked by [[TileRequest]] after a request completes.
     * @internal
     */
    recordCompletion(tile: Tile, content: TileContent, elapsedMilliseconds: number): void;
    /** Invoked by [[TileRequestChannels.swapPending]] when [[TileAdmin]] is about to start enqueuing new requests.
     * @internal
     */
    swapPending(): void;
    /** Invoked by [[TileAdmin.processRequests]] to enqueue a request. Ordering is ignored - the queue will be re-sorted later.
     * @internal
     */
    append(request: TileRequest): void;
    /** Invoked by [[TileRequestChannels.process]] to process the active and pending requests.
     * @internal
     */
    process(): void;
    /** Cancel all active and queued requests and clear the active set and queue.
     * @internal
     */
    cancelAndClearAll(): void;
    /** Invoked when [[Tile.requestContent]] returns `undefined`. Return true if the request can be retried, e.g., via different channel.
     * If so, the tile will remain marked as "not loaded" and, if re-selected for display, a new [[TileRequest]] will be enqueued for it.
     * Otherwise, the tile will be marked as "failed to load" and no further requests will be made for its content.
     * The default implementation always returns `false`.
     */
    onNoContent(_request: TileRequest): boolean;
    /** Invoked when a request that was previously dispatched is canceled before a response is received.
     * Some channels accumulate such requests for later cancellation in [[processCancellations]].
     */
    onActiveRequestCanceled(_request: TileRequest): void;
    /** Invoked to do any additional work to cancel tiles accumulated by [[onActiveRequestCanceled]]. For example, a channel that requests tile content
     * over IPC may signal to the tile generation process that it should cease generating content for those tiles.
     */
    processCancellations(): void;
    /** Invoked when an iModel is closed, to clean up any state associated with that iModel. */
    onIModelClosed(_iModel: IModelConnection): void;
    /** Request content for the specified tile. The default implementation simply forwards to [[Tile.requestContent]]. */
    requestContent(tile: Tile, isCanceled: () => boolean): Promise<TileRequest.Response>;
    /** Protected only for tests - do not override.
     * @internal
     */
    protected dispatch(request: TileRequest): void;
    /** Protected only for tests - do not override.
     * @internal
     */
    protected cancel(request: TileRequest): void;
    /** Protected only for tests - do not override.
     * @internal
     */
    protected dropActiveRequest(request: TileRequest): void;
}
//# sourceMappingURL=TileRequestChannel.d.ts.map