1 | /*!
|
2 | * Copyright 2021 Google LLC
|
3 | *
|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | * you may not use this file except in compliance with the License.
|
6 | * You may obtain a copy of the License at
|
7 | *
|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
9 | *
|
10 | * Unless required by applicable law or agreed to in writing, software
|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 | * See the License for the specific language governing permissions and
|
14 | * limitations under the License.
|
15 | */
|
16 | /**
|
17 | * @typedef FlowControlOptions
|
18 | * @property {number} [maxOutstandingMessages] The maximum number of messages to
|
19 | * buffer before publisher flow control kicks in.
|
20 | * @property {number} [maxOutstandingBytes] The maximum number of bytes to buffer
|
21 | * before publisher flow control kicks in.
|
22 | */
|
23 | export interface FlowControlOptions {
|
24 | maxOutstandingMessages?: number;
|
25 | maxOutstandingBytes?: number;
|
26 | }
|
27 | /**
|
28 | * Manages flow control handling for max bytes and messages.
|
29 | *
|
30 | * Do not use this class externally, it may change without warning.
|
31 | * @private
|
32 | *
|
33 | */
|
34 | export declare class FlowControl {
|
35 | options: FlowControlOptions;
|
36 | private bytes;
|
37 | private messages;
|
38 | private requests;
|
39 | constructor(options: FlowControlOptions);
|
40 | /**
|
41 | * Update our options after the fact.
|
42 | *
|
43 | * Do not use externally, it may change without warning.
|
44 | * @private
|
45 | */
|
46 | setOptions(options: FlowControlOptions): void;
|
47 | /**
|
48 | * @returns {number} The number of bytes that are queued up.
|
49 | */
|
50 | get currentByteCount(): number;
|
51 | /**
|
52 | * @returns {number} The number of messages that are queued up.
|
53 | */
|
54 | get currentMessageCount(): number;
|
55 | /**
|
56 | * Adds the specified number of bytes or messages to our count. We'll
|
57 | * assume that this is end running around our queueing mechanisms.
|
58 | *
|
59 | * @param {number} bytes The number of bytes to add to the count.
|
60 | * @param {number} messages The number of messages to add to the count.
|
61 | */
|
62 | addToCount(bytes: number, messages: number): void;
|
63 | /**
|
64 | * Attempts to queue the specified number of bytes and messages. If
|
65 | * there are too many things in the publisher flow control queue
|
66 | * already, we will defer and come back to it.
|
67 | *
|
68 | * Do not use externally, it may change without warning.
|
69 | * @private
|
70 | */
|
71 | willSend(bytes: number, messages: number): Promise<void>;
|
72 | /**
|
73 | * Removes the specified number of bytes and messages from our queued
|
74 | * counts, after a deferred request was released. If there is enough
|
75 | * space.
|
76 | *
|
77 | * Do not use externally, it may change without warning.
|
78 | * @private
|
79 | */
|
80 | sent(bytes: number, messages: number): void;
|
81 | private exceeded;
|
82 | /**
|
83 | * Returns true if adding the specified number of bytes or messages
|
84 | * would exceed limits imposed by configuration.
|
85 | *
|
86 | * Do not use externally, it may change without warning.
|
87 | * @private
|
88 | */
|
89 | wouldExceed(bytes: number, messages: number): boolean;
|
90 | }
|